test: accept any route function in the test app without a cast

This commit is contained in:
Aarnav Tale
2026-10-17 18:04:00 -07:00
parent d4213f3b39
commit 061609c057
5 changed files with 13 additions and 10 deletions
+2 -2
View File
@@ -26,7 +26,7 @@ describe("machines on a real tailnet", () => {
});
function machine(form: Record<string, string>) {
return app.call(machineAction as never, "/machines", { as: owner, form });
return app.call(machineAction, "/machines", { as: owner, form });
}
test("a waiting machine registered from its URL comes online for that user", async () => {
@@ -110,7 +110,7 @@ describe("DNS on a real tailnet", () => {
const node = await tailnet.node({ name: "dns-client", user: "alice@" });
const { cookie } = await app.signIn("owner");
const result = await app.call(dnsAction as never, "/dns", {
const result = await app.call(dnsAction, "/dns", {
as: cookie,
form: {
intent: "add_record",
+5 -2
View File
@@ -21,7 +21,8 @@ export interface TestAppOptions {
export type TestApp = Awaited<ReturnType<typeof createTestApp>>;
type RouteFunction = (args: LoaderFunctionArgs & ActionFunctionArgs) => unknown;
// Any loader or action, whatever its generated argument types.
type RouteFunction = (args: never) => unknown;
export interface CallOptions {
as?: string;
@@ -120,7 +121,9 @@ export async function createTestApp(options: TestAppOptions = {}) {
};
try {
return await fn(args as unknown as LoaderFunctionArgs & ActionFunctionArgs);
return await (fn as (args: LoaderFunctionArgs & ActionFunctionArgs) => unknown)(
args as unknown as LoaderFunctionArgs & ActionFunctionArgs,
);
} catch (error) {
return error;
}
+3 -3
View File
@@ -20,7 +20,7 @@ afterEach(async () => {
});
function create(as: string, form: Record<string, string | string[]>) {
return app.call(action as never, "/settings/auth-keys", {
return app.call(action, "/settings/auth-keys", {
as,
form: { intent: "create", expiry: "90", ...form },
});
@@ -90,7 +90,7 @@ describe("self-service auth keys", () => {
await create(admin, { user_id: bob.id });
await create(admin, { tags: "tag:prod" });
const data = (await app.call(loader as never, "/settings/auth-keys", {
const data = (await app.call(loader, "/settings/auth-keys", {
as: await signInAsAlice(),
})) as Awaited<ReturnType<typeof loader>>;
@@ -104,7 +104,7 @@ describe("self-service auth keys", () => {
await create(cookie, { user_id: bob.id });
await create(cookie, { tags: "tag:prod" });
const data = (await app.call(loader as never, "/settings/auth-keys", {
const data = (await app.call(loader, "/settings/auth-keys", {
as: cookie,
})) as Awaited<ReturnType<typeof loader>>;
+1 -1
View File
@@ -6,7 +6,7 @@ import { HEADSCALE_VERSIONS } from "../../harness/versions";
import { createTestApp, type TestApp } from "../../support/app";
async function signIn(app: TestApp, form: Record<string, string>) {
return app.call(action as never, "/login", { form });
return app.call(action, "/login", { form });
}
describe.for(HEADSCALE_VERSIONS)("API key sign-in on Headscale %s", (version) => {
+2 -2
View File
@@ -112,7 +112,7 @@ describe("route permissions", () => {
});
function callAction(entry: Entry, as?: string) {
return app.call(entry.module.action! as never, entry.path, {
return app.call(entry.module.action!, entry.path, {
as,
form: { ...form, ...(entry.intent ? { intent: entry.intent } : {}) },
params: { id: form.node_id },
@@ -129,7 +129,7 @@ describe("route permissions", () => {
async ([, entry]) => {
const callers = MEMBER_VISIBLE.has(entry.file) ? [undefined] : [undefined, "member" as const];
for (const role of callers) {
const result = await app.call(entry.module.loader! as never, entry.path, {
const result = await app.call(entry.module.loader!, entry.path, {
as: role && cookies.get(role),
params: { id: form.node_id },
});