From 26f915adc4c9d13302f73b24d13ffcc42417e8a9 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Thu, 19 Jan 2023 09:52:39 +0100 Subject: [PATCH] fix(typecheck): store tmp tsconfig close to original one (#2660) * fix: store tmp tsconfig close to original one * chore: use separate tsconfig * chore: cleanup --- packages/vitest/src/node/reporters/base.ts | 2 +- packages/vitest/src/typecheck/parse.ts | 6 +++--- .../test/__snapshots__/runner.test.ts.snap | 16 ++++++++-------- test/typescript/test/runner.test.ts | 7 ++----- test/typescript/tsconfig.json | 6 ++++++ 5 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 test/typescript/tsconfig.json diff --git a/packages/vitest/src/node/reporters/base.ts b/packages/vitest/src/node/reporters/base.ts index 0127f594cadd..320b634e37b7 100644 --- a/packages/vitest/src/node/reporters/base.ts +++ b/packages/vitest/src/node/reporters/base.ts @@ -241,7 +241,7 @@ export abstract class BaseReporter implements Reporter { logger.log(padTitle('Tests'), getStateString(tests)) if (this.mode === 'typecheck') { const failed = tests.filter(t => t.meta?.typecheck && t.result?.errors?.length) - logger.log(padTitle('Type Errors'), failed.length ? c.bold(c.red(`${failed} failed`)) : c.dim('no errors')) + logger.log(padTitle('Type Errors'), failed.length ? c.bold(c.red(`${failed.length} failed`)) : c.dim('no errors')) } logger.log(padTitle('Start at'), formatTimeString(this._timeStart)) if (this.watchFilters) diff --git a/packages/vitest/src/typecheck/parse.ts b/packages/vitest/src/typecheck/parse.ts index 39a1ad7f1b4a..214000c7a092 100644 --- a/packages/vitest/src/typecheck/parse.ts +++ b/packages/vitest/src/typecheck/parse.ts @@ -1,6 +1,6 @@ import url from 'node:url' import { writeFile } from 'node:fs/promises' -import { join } from 'pathe' +import { dirname, join } from 'pathe' import { getTsconfig as getTsconfigContent } from 'get-tsconfig' import type { TypecheckConfig } from '../types' import type { RawErrsMap, TscErrorInfo } from './types' @@ -58,8 +58,6 @@ export async function makeTscErrorInfo( } export async function getTsconfig(root: string, config: TypecheckConfig) { - const tempConfigPath = join(root, 'tsconfig.temp.json') - const configName = config.tsconfig?.includes('jsconfig.json') ? 'jsconfig.json' : undefined @@ -69,6 +67,8 @@ export async function getTsconfig(root: string, config: TypecheckConfig) { if (!tsconfig) throw new Error('no tsconfig.json found') + const tempConfigPath = join(dirname(tsconfig.path), 'tsconfig.vitest-temp.json') + try { const tmpTsConfig: Record = { ...tsconfig.config } diff --git a/test/typescript/test/__snapshots__/runner.test.ts.snap b/test/typescript/test/__snapshots__/runner.test.ts.snap index 45f2f244e2c5..479f16d6ec8b 100644 --- a/test/typescript/test/__snapshots__/runner.test.ts.snap +++ b/test/typescript/test/__snapshots__/runner.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1 -exports[`should fails > typecheck files 1`] = ` +exports[`should fail > typecheck files 1`] = ` "TypeCheckError: Expected 1 arguments, but got 0. TypeCheckError: Expected 1 arguments, but got 0. TypeCheckError: Expected 1 arguments, but got 0. @@ -10,7 +10,7 @@ TypeCheckError: Unused '@ts-expect-error' directive. TypeCheckError: Expected 1 arguments, but got 0." `; -exports[`should fails > typecheck files 2`] = ` +exports[`should fail > typecheck files 2`] = ` " FAIL fail.test-d.ts > nested suite TypeCheckError: Expected 1 arguments, but got 0. ❯ fail.test-d.ts:15:19 @@ -21,7 +21,7 @@ TypeCheckError: Expected 1 arguments, but got 0. 16| })" `; -exports[`should fails > typecheck files 3`] = ` +exports[`should fail > typecheck files 3`] = ` " FAIL expect-error.test-d.ts > failing test with expect-error TypeCheckError: Unused '@ts-expect-error' directive. ❯ expect-error.test-d.ts:4:3 @@ -32,7 +32,7 @@ TypeCheckError: Unused '@ts-expect-error' directive. 5| expectTypeOf(1).toEqualTypeOf()" `; -exports[`should fails > typecheck files 4`] = ` +exports[`should fail > typecheck files 4`] = ` " FAIL fail.test-d.ts > failing test TypeCheckError: Expected 1 arguments, but got 0. ❯ fail.test-d.ts:4:19 @@ -43,7 +43,7 @@ TypeCheckError: Expected 1 arguments, but got 0. 5| })" `; -exports[`should fails > typecheck files 5`] = ` +exports[`should fail > typecheck files 5`] = ` " FAIL fail.test-d.ts > nested suite > nested 2 > failing test 2 TypeCheckError: Expected 1 arguments, but got 0. ❯ fail.test-d.ts:10:23 @@ -54,7 +54,7 @@ TypeCheckError: Expected 1 arguments, but got 0. 11| expectTypeOf(1).toBeUndefined()" `; -exports[`should fails > typecheck files 6`] = ` +exports[`should fail > typecheck files 6`] = ` " FAIL fail.test-d.ts > nested suite > nested 2 > failing test 2 TypeCheckError: Expected 1 arguments, but got 0. ❯ fail.test-d.ts:11:23 @@ -65,7 +65,7 @@ TypeCheckError: Expected 1 arguments, but got 0. 12| })" `; -exports[`should fails > typecheck files 7`] = ` +exports[`should fail > typecheck files 7`] = ` " FAIL js-fail.test-d.js > js test fails TypeCheckError: Expected 1 arguments, but got 0. ❯ js-fail.test-d.js:6:19 @@ -76,7 +76,7 @@ TypeCheckError: Expected 1 arguments, but got 0. 7| })" `; -exports[`should fails > typecheck files 8`] = ` +exports[`should fail > typecheck files 8`] = ` " FAIL only.test-d.ts > failing test TypeCheckError: Expected 1 arguments, but got 0. ❯ only.test-d.ts:4:19 diff --git a/test/typescript/test/runner.test.ts b/test/typescript/test/runner.test.ts index fe6798ef223d..fa7b369c54a1 100644 --- a/test/typescript/test/runner.test.ts +++ b/test/typescript/test/runner.test.ts @@ -3,18 +3,15 @@ import fg from 'fast-glob' import { execa } from 'execa' import { describe, expect, it } from 'vitest' -describe('should fails', async () => { +describe('should fail', async () => { const root = resolve(__dirname, '../failing') const files = await fg('*.test-d.*', { cwd: root }) it('typecheck files', async () => { - // in Windows child_process is very unstable, we skip testing it - if (process.platform === 'win32' && process.env.CI) - return - const { stderr } = await execa('npx', [ 'vitest', 'typecheck', + '--run', '--dir', resolve(__dirname, '..', './failing'), '--config', diff --git a/test/typescript/tsconfig.json b/test/typescript/tsconfig.json new file mode 100644 index 000000000000..46c90b1893df --- /dev/null +++ b/test/typescript/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../tsconfig.json", + "exclude": [ + "**/dist/**" + ] +}