Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Type-level test files use intentional long, single-line cases so that each
# `@ts-expect-error` attaches to the error on the line immediately below it.
# Prettier's line wrapping would move the error off that line and break them.
*.test-d.ts
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"release": "pnpm publish --no-git-checks",
"test": "vitest",
"test:e2e": "vitest --mode e2e --reporter=verbose --test-timeout 10000",
"test:types": "vitest --run --mode types",
"format": "prettier --write \"**/*.{ts,tsx,md,json,css,scss,html}\""
},
"sideEffects": false,
Expand Down
4 changes: 4 additions & 0 deletions src/test/schema/Country.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
{
"type": "Decimal",
"name": "population"
},
{
"type": "Int",
"name": "rank"
}
]
}
477 changes: 477 additions & 0 deletions src/test/types-client-input.test-d.ts

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/test/types-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { generateCode } from "./client.utils";

// The type tests import the generated test client (`./db/models`), which is
// not committed — generate it up front, like the e2e setup does, but without
// the database container: only tsc consumes the result.
export function setup() {
generateCode();
}
10 changes: 10 additions & 0 deletions tsconfig.typecheck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": true,
"incremental": false,
"composite": false
},
"include": ["src/test/**/*.test-d.ts"],
"exclude": ["node_modules", "dist"]
}
21 changes: 20 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,27 @@ const e2eTests: ViteUserConfig["test"] = {
maxWorkers: 1,
};

// Type-level tests (`*.test-d.ts`), checked by tsc via Vitest's typecheck mode.
// No runtime / DB — the client is `declare`d in the test files; the global
// setup only generates the test client code the suite typechecks against.
const typeTests: ViteUserConfig["test"] = {
include: [],
globalSetup: ["src/test/types-setup.ts"],
typecheck: {
enabled: true,
only: true,
include: ["src/test/**/*.test-d.ts"],
tsconfig: "tsconfig.typecheck.json",
},
};

export default defineConfig((env) => {
const testConfig = env.mode === "e2e" ? e2eTests : unitTests;
const testConfig =
env.mode === "e2e"
? e2eTests
: env.mode === "types"
? typeTests
: unitTests;
return {
plugins: [
{
Expand Down