Skip to content

Commit 26f915a

Browse files
authoredJan 19, 2023
fix(typecheck): store tmp tsconfig close to original one (#2660)
* fix: store tmp tsconfig close to original one * chore: use separate tsconfig * chore: cleanup
1 parent 6a30cdd commit 26f915a

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed
 

‎packages/vitest/src/node/reporters/base.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export abstract class BaseReporter implements Reporter {
241241
logger.log(padTitle('Tests'), getStateString(tests))
242242
if (this.mode === 'typecheck') {
243243
const failed = tests.filter(t => t.meta?.typecheck && t.result?.errors?.length)
244-
logger.log(padTitle('Type Errors'), failed.length ? c.bold(c.red(`${failed} failed`)) : c.dim('no errors'))
244+
logger.log(padTitle('Type Errors'), failed.length ? c.bold(c.red(`${failed.length} failed`)) : c.dim('no errors'))
245245
}
246246
logger.log(padTitle('Start at'), formatTimeString(this._timeStart))
247247
if (this.watchFilters)

‎packages/vitest/src/typecheck/parse.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import url from 'node:url'
22
import { writeFile } from 'node:fs/promises'
3-
import { join } from 'pathe'
3+
import { dirname, join } from 'pathe'
44
import { getTsconfig as getTsconfigContent } from 'get-tsconfig'
55
import type { TypecheckConfig } from '../types'
66
import type { RawErrsMap, TscErrorInfo } from './types'
@@ -58,8 +58,6 @@ export async function makeTscErrorInfo(
5858
}
5959

6060
export async function getTsconfig(root: string, config: TypecheckConfig) {
61-
const tempConfigPath = join(root, 'tsconfig.temp.json')
62-
6361
const configName = config.tsconfig?.includes('jsconfig.json')
6462
? 'jsconfig.json'
6563
: undefined
@@ -69,6 +67,8 @@ export async function getTsconfig(root: string, config: TypecheckConfig) {
6967
if (!tsconfig)
7068
throw new Error('no tsconfig.json found')
7169

70+
const tempConfigPath = join(dirname(tsconfig.path), 'tsconfig.vitest-temp.json')
71+
7272
try {
7373
const tmpTsConfig: Record<string, any> = { ...tsconfig.config }
7474

‎test/typescript/test/__snapshots__/runner.test.ts.snap

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1
22

3-
exports[`should fails > typecheck files 1`] = `
3+
exports[`should fail > typecheck files 1`] = `
44
"TypeCheckError: Expected 1 arguments, but got 0.
55
TypeCheckError: Expected 1 arguments, but got 0.
66
TypeCheckError: Expected 1 arguments, but got 0.
@@ -10,7 +10,7 @@ TypeCheckError: Unused '@ts-expect-error' directive.
1010
TypeCheckError: Expected 1 arguments, but got 0."
1111
`;
1212

13-
exports[`should fails > typecheck files 2`] = `
13+
exports[`should fail > typecheck files 2`] = `
1414
" FAIL fail.test-d.ts > nested suite
1515
TypeCheckError: Expected 1 arguments, but got 0.
1616
❯ fail.test-d.ts:15:19
@@ -21,7 +21,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
2121
16| })"
2222
`;
2323

24-
exports[`should fails > typecheck files 3`] = `
24+
exports[`should fail > typecheck files 3`] = `
2525
" FAIL expect-error.test-d.ts > failing test with expect-error
2626
TypeCheckError: Unused '@ts-expect-error' directive.
2727
❯ expect-error.test-d.ts:4:3
@@ -32,7 +32,7 @@ TypeCheckError: Unused '@ts-expect-error' directive.
3232
5| expectTypeOf(1).toEqualTypeOf<number>()"
3333
`;
3434
35-
exports[`should fails > typecheck files 4`] = `
35+
exports[`should fail > typecheck files 4`] = `
3636
" FAIL fail.test-d.ts > failing test
3737
TypeCheckError: Expected 1 arguments, but got 0.
3838
❯ fail.test-d.ts:4:19
@@ -43,7 +43,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
4343
5| })"
4444
`;
4545
46-
exports[`should fails > typecheck files 5`] = `
46+
exports[`should fail > typecheck files 5`] = `
4747
" FAIL fail.test-d.ts > nested suite > nested 2 > failing test 2
4848
TypeCheckError: Expected 1 arguments, but got 0.
4949
❯ fail.test-d.ts:10:23
@@ -54,7 +54,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
5454
11| expectTypeOf(1).toBeUndefined()"
5555
`;
5656
57-
exports[`should fails > typecheck files 6`] = `
57+
exports[`should fail > typecheck files 6`] = `
5858
" FAIL fail.test-d.ts > nested suite > nested 2 > failing test 2
5959
TypeCheckError: Expected 1 arguments, but got 0.
6060
❯ fail.test-d.ts:11:23
@@ -65,7 +65,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
6565
12| })"
6666
`;
6767
68-
exports[`should fails > typecheck files 7`] = `
68+
exports[`should fail > typecheck files 7`] = `
6969
" FAIL js-fail.test-d.js > js test fails
7070
TypeCheckError: Expected 1 arguments, but got 0.
7171
❯ js-fail.test-d.js:6:19
@@ -76,7 +76,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
7676
7| })"
7777
`;
7878
79-
exports[`should fails > typecheck files 8`] = `
79+
exports[`should fail > typecheck files 8`] = `
8080
" FAIL only.test-d.ts > failing test
8181
TypeCheckError: Expected 1 arguments, but got 0.
8282
❯ only.test-d.ts:4:19

‎test/typescript/test/runner.test.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,15 @@ import fg from 'fast-glob'
33
import { execa } from 'execa'
44
import { describe, expect, it } from 'vitest'
55

6-
describe('should fails', async () => {
6+
describe('should fail', async () => {
77
const root = resolve(__dirname, '../failing')
88
const files = await fg('*.test-d.*', { cwd: root })
99

1010
it('typecheck files', async () => {
11-
// in Windows child_process is very unstable, we skip testing it
12-
if (process.platform === 'win32' && process.env.CI)
13-
return
14-
1511
const { stderr } = await execa('npx', [
1612
'vitest',
1713
'typecheck',
14+
'--run',
1815
'--dir',
1916
resolve(__dirname, '..', './failing'),
2017
'--config',

‎test/typescript/tsconfig.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"exclude": [
4+
"**/dist/**"
5+
]
6+
}

0 commit comments

Comments
 (0)
Please sign in to comment.