Skip to content

Commit

Permalink
feat: typecheck
Browse files Browse the repository at this point in the history
  • Loading branch information
nikovirtala committed Dec 29, 2024
1 parent 7790fff commit 7970f35
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
48 changes: 48 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 35 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ export interface VitestConfigOptions {
* @default "coverage"
*/
readonly coverageDirectory?: string;

/**
* Enable typechecking alongside your regular tests. https://vitest.dev/config/#typecheck-enabled
*
* @default true
*/
readonly typecheckEnabled?: boolean;

/**
* Tool to use for type checking. Checker should implement the same output format as `tsc`.
*
* https://vitest.dev/config/#typecheck-checker
*
* @default "tsc --noEmit"
*/
readonly typecheckChecker?: string;

/**
* Path to custom tsconfig, relative to the project root. https://vitest.dev/config/#typecheck-tsconfig
*
* @default "tsconfig.dev.json"
*/
readonly typecheckTsconfig?: string;
}

export interface VitestOptions {
Expand Down Expand Up @@ -219,6 +242,9 @@ export class Vitest extends Component {
private readonly isolate: boolean;
private readonly pool: Pool;
private readonly coverageEnabled: boolean;
private readonly typecheckEnabled: boolean;
private readonly typecheckChecker: string;
private readonly typecheckTsconfig: string;
private environment: string;
private globals: boolean;
private coverageProvider: CoverageProvider;
Expand All @@ -239,6 +265,9 @@ export class Vitest extends Component {
this.isolate = options.config?.isolate ?? true;
this.pool = options.config?.pool ?? Pool.FORKS;
this.coverageEnabled = options.config?.coverageEnabled ?? true;
this.typecheckEnabled = options.config?.typecheckEnabled ?? true;
this.typecheckChecker = options.config?.typecheckChecker ?? "tsc --noEmit";
this.typecheckTsconfig = options.config?.typecheckTsconfig ?? "tsconfig.dev.json";
this.environment = options.config?.environment ?? Environment.NODE;
this.globals = options.config?.globals ?? false;
this.coverageProvider = options.config?.coverageProvider ?? CoverageProvider.V8;
Expand Down Expand Up @@ -343,7 +372,12 @@ export class Vitest extends Component {
lines.push(` globals: ${this.globals},`);
lines.push(` include: ${JSON.stringify(Array.from(this.include))},`);
lines.push(` isolate: ${this.isolate},`);
lines.push(` pool: "${this.pool}", `);
lines.push(` pool: "${this.pool}",`);
lines.push(" typecheck: {");
lines.push(` checker: "${this.typecheckChecker}",`);
lines.push(` enabled: ${this.typecheckEnabled},`);
lines.push(` tsconfig: "${this.typecheckTsconfig}",`);
lines.push(" },");

return lines;
}
Expand Down
5 changes: 5 additions & 0 deletions test/vitest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ describe("vitest", () => {
coverageDirectory: "custom-coverage",
include: ["**/*.test.ts"],
exclude: ["**/*.spec.js"],
typecheckEnabled: false,
typecheckChecker: "tsc",
typecheckTsconfig: "tsconfig.custom.json",
},
});

Expand All @@ -114,6 +117,8 @@ describe("vitest", () => {
expect(snapshot["custom.vitest.config.ts"]).toContain('pool: "threads"');
expect(snapshot["custom.vitest.config.ts"]).toContain("globals: false");
expect(snapshot["custom.vitest.config.ts"]).toContain("enabled: false");
expect(snapshot["custom.vitest.config.ts"]).toContain('checker: "tsc"');
expect(snapshot["custom.vitest.config.ts"]).toContain('tsconfig: "tsconfig.custom.json"');
expect(snapshot["custom.vitest.config.ts"]).toContain('provider: "istanbul"');
expect(snapshot["custom.vitest.config.ts"]).toContain('reporter: ["html"]');
expect(snapshot["custom.vitest.config.ts"]).toContain('reportsDirectory: "custom-coverage"');
Expand Down

0 comments on commit 7970f35

Please sign in to comment.