Skip to content

Commit 636795f

Browse files
committed
test: add test:compiler for full tests
1 parent 012d8b9 commit 636795f

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"lint:fix": "automd && eslint --fix . && prettier -w src test",
2525
"release": "pnpm test && pnpm build && changelogen --release && git push --follow-tags && npm publish",
2626
"test": "pnpm lint && pnpm test:types && vitest run --coverage",
27+
"test:compiler": "TEST_COMPILER=1 vitest",
2728
"test:types": "tsc --noEmit"
2829
},
2930
"devDependencies": {
File renamed without changes.

test/router.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, it, expect } from "vitest";
22
import type { RouterContext } from "../src/types.ts";
33
import { createRouter, formatTree } from "./_utils.ts";
44
import { addRoute, findRoute, removeRoute } from "../src/index.ts";
5+
import { compileRouter } from "../src/compiler.ts";
56

67
type TestRoute = {
78
data: { path: string };
@@ -22,6 +23,10 @@ function testRouter(
2223
) {
2324
const router = createRouter<{ path?: string }>(routes);
2425

26+
const compiledMatch = process.env.TEST_COMPILER
27+
? compileRouter(router)
28+
: undefined;
29+
2530
if (!tests) {
2631
tests = Array.isArray(routes)
2732
? Object.fromEntries(
@@ -51,7 +56,13 @@ function testRouter(
5156
it.skipIf(tests[path]?.skip)(
5257
`lookup ${path} should be ${JSON.stringify(tests[path])}`,
5358
() => {
54-
expect(findRoute(router, "GET", path)).to.toMatchObject(tests[path]!);
59+
if (process.env.TEST_COMPILER) {
60+
expect(compiledMatch!("GET", path)).to.toMatchObject(
61+
tests[path] || { data: { path } },
62+
);
63+
} else {
64+
expect(findRoute(router, "GET", path)).to.toMatchObject(tests[path]!);
65+
}
5566
},
5667
);
5768
}

0 commit comments

Comments
 (0)