Skip to content

Commit 6dae3fe

Browse files
authoredJan 26, 2024
fix(typecheck): fix ignoreSourceErrors in run mode (#5044)
1 parent cf5641a commit 6dae3fe

File tree

7 files changed

+57
-2
lines changed

7 files changed

+57
-2
lines changed
 

‎packages/vitest/src/node/pools/typecheck.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export function createTypecheckPool(ctx: Vitest): ProcessPool {
2020
if (!project.config.typecheck.ignoreSourceErrors)
2121
sourceErrors.forEach(error => ctx.state.catchError(error, 'Unhandled Source Error'))
2222

23-
const processError = !hasFailed(files) && checker.getExitCode()
23+
const processError = !hasFailed(files) && !sourceErrors.length && checker.getExitCode()
2424
if (processError) {
2525
const error = new Error(checker.getOutput())
2626
error.stack = ''
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
thisIsSourceError
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expectTypeOf, test } from 'vitest'
2+
3+
test('ok', () => {
4+
expectTypeOf(1).toEqualTypeOf(2)
5+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"noEmit": true,
4+
"target": "es2020",
5+
"module": "ESNext",
6+
"moduleResolution": "Bundler",
7+
"strict": true,
8+
"verbatimModuleSyntax": true
9+
},
10+
"include": ["src", "test"],
11+
"exclude": ["node_modules"]
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
typecheck: {
6+
enabled: true,
7+
},
8+
},
9+
})

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

+27
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,30 @@ describe('should fail', async () => {
9797
expect(stderr.replace(resolve(__dirname, '..'), '<root>')).toMatchSnapshot()
9898
})
9999
})
100+
101+
describe('ignoreSourceErrors', () => {
102+
it('disabled', async () => {
103+
const vitest = await runVitestCli(
104+
{
105+
cwd: resolve(__dirname, '../fixtures/source-error'),
106+
},
107+
'--run',
108+
)
109+
expect(vitest.stdout).toContain('Unhandled Errors')
110+
expect(vitest.stderr).toContain('Unhandled Source Error')
111+
expect(vitest.stderr).toContain('TypeCheckError: Cannot find name \'thisIsSourceError\'')
112+
})
113+
114+
it('enabled', async () => {
115+
const vitest = await runVitestCli(
116+
{
117+
cwd: resolve(__dirname, '../fixtures/source-error'),
118+
},
119+
'--run',
120+
'--typecheck.ignoreSourceErrors',
121+
)
122+
expect(vitest.stdout).not.toContain('Unhandled Errors')
123+
expect(vitest.stderr).not.toContain('Unhandled Source Error')
124+
expect(vitest.stderr).not.toContain('TypeCheckError: Cannot find name \'thisIsSourceError\'')
125+
})
126+
})

‎test/typescript/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"exclude": [
4-
"**/dist/**"
4+
"**/dist/**",
5+
"**/fixtures/**"
56
]
67
}

0 commit comments

Comments
 (0)
Please sign in to comment.