Skip to content

Commit

Permalink
fix(typecheck): fix ignoreSourceErrors in run mode (#5044)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Jan 26, 2024
1 parent cf5641a commit 6dae3fe
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pools/typecheck.ts
Expand Up @@ -20,7 +20,7 @@ export function createTypecheckPool(ctx: Vitest): ProcessPool {
if (!project.config.typecheck.ignoreSourceErrors)
sourceErrors.forEach(error => ctx.state.catchError(error, 'Unhandled Source Error'))

const processError = !hasFailed(files) && checker.getExitCode()
const processError = !hasFailed(files) && !sourceErrors.length && checker.getExitCode()
if (processError) {
const error = new Error(checker.getOutput())
error.stack = ''
Expand Down
1 change: 1 addition & 0 deletions test/typescript/fixtures/source-error/src/not-ok.ts
@@ -0,0 +1 @@
thisIsSourceError
5 changes: 5 additions & 0 deletions test/typescript/fixtures/source-error/test/ok.test-d.ts
@@ -0,0 +1,5 @@
import { expectTypeOf, test } from 'vitest'

test('ok', () => {
expectTypeOf(1).toEqualTypeOf(2)
})
12 changes: 12 additions & 0 deletions test/typescript/fixtures/source-error/tsconfig.json
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"noEmit": true,
"target": "es2020",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"verbatimModuleSyntax": true
},
"include": ["src", "test"],
"exclude": ["node_modules"]
}
9 changes: 9 additions & 0 deletions test/typescript/fixtures/source-error/vite.config.ts
@@ -0,0 +1,9 @@
import { defineConfig } from 'vitest/config'

export default defineConfig({
test: {
typecheck: {
enabled: true,
},
},
})
27 changes: 27 additions & 0 deletions test/typescript/test/runner.test.ts
Expand Up @@ -97,3 +97,30 @@ describe('should fail', async () => {
expect(stderr.replace(resolve(__dirname, '..'), '<root>')).toMatchSnapshot()
})
})

describe('ignoreSourceErrors', () => {
it('disabled', async () => {
const vitest = await runVitestCli(
{
cwd: resolve(__dirname, '../fixtures/source-error'),
},
'--run',
)
expect(vitest.stdout).toContain('Unhandled Errors')
expect(vitest.stderr).toContain('Unhandled Source Error')
expect(vitest.stderr).toContain('TypeCheckError: Cannot find name \'thisIsSourceError\'')
})

it('enabled', async () => {
const vitest = await runVitestCli(
{
cwd: resolve(__dirname, '../fixtures/source-error'),
},
'--run',
'--typecheck.ignoreSourceErrors',
)
expect(vitest.stdout).not.toContain('Unhandled Errors')
expect(vitest.stderr).not.toContain('Unhandled Source Error')
expect(vitest.stderr).not.toContain('TypeCheckError: Cannot find name \'thisIsSourceError\'')
})
})
3 changes: 2 additions & 1 deletion test/typescript/tsconfig.json
@@ -1,6 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"exclude": [
"**/dist/**"
"**/dist/**",
"**/fixtures/**"
]
}

0 comments on commit 6dae3fe

Please sign in to comment.