-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(typecheck): improve error message when tsc outputs help text #9214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sheremet-va
merged 20 commits into
vitest-dev:main
from
Ujjwaljain16:fix/typecheck-tsconfig-missing-error
Dec 23, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c6f2eab
fix(typecheck): improve error message when tsc outputs help text
Ujjwaljain16 5ce857b
test(typecheck): add unit tests for help text detection
Ujjwaljain16 441a6e9
Merge branch 'main' into fix/typecheck-tsconfig-missing-error
Ujjwaljain16 f8f1165
Merge branch 'main' into fix/typecheck-tsconfig-missing-error
Ujjwaljain16 26f4b71
fix(typecheck): fix Windows CI failure for non-existing typechecker c…
Ujjwaljain16 ecc15fd
fix(typecheck): move winTimeout declaration before use to fix linting…
Ujjwaljain16 0691f0d
test(typecheck): replace mocked tests with integration test
Ujjwaljain16 46bf95c
fix(typecheck): improve error message when tsconfig is missing\n\nDet…
Ujjwaljain16 a2d9ba2
Merge branch 'main' into fix/typecheck-tsconfig-missing-error
Ujjwaljain16 07b408c
style: fix linting errors
Ujjwaljain16 609930f
fix: use proper typecheck test file pattern
Ujjwaljain16 cc0a388
Merge branch 'fix/typecheck-tsconfig-missing-error' of https://github…
Ujjwaljain16 f09c5d6
fix: use test-d.ts pattern to trigger typecheck execution
Ujjwaljain16 c12e7f4
chore: remove debug log and document test approach
Ujjwaljain16 dfe2b54
fix lint
Ujjwaljain16 130d597
refactor(test): use createFile utility and static imports per review …
Ujjwaljain16 3468560
Merge branch 'main' into fix/typecheck-tsconfig-missing-error
Ujjwaljain16 7874e85
Merge branch 'main' into fix/typecheck-tsconfig-missing-error
Ujjwaljain16 a0e8efb
refactor: remove console.error and redundant mkdirSync per review
Ujjwaljain16 d5ec671
refactor: remove console.error and redundant mkdirSync per review
Ujjwaljain16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import fs from 'node:fs' | ||
| import os from 'node:os' | ||
| import path from 'node:path' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { createFile, runInlineTests } from '../../test-utils' | ||
|
|
||
| describe('Typechecker Error Handling', () => { | ||
| it('throws helpful error when tsc outputs help text (missing config)', async () => { | ||
| // TESTING APPROACH: | ||
| // We cannot reliably trigger tsc's help text output in normal usage because: | ||
| // 1. tsc only shows help when called with NO arguments or INVALID arguments | ||
| // 2. Vitest always calls tsc with proper arguments (--noEmit, --pretty, etc.) | ||
| // 3. Invalid tsconfig causes ERROR output, not help text | ||
| // | ||
| // SOLUTION: Use a test executable that mimics tsc help output | ||
| // This is NOT a mock (no jest.mock or similar), but a real executable script | ||
| // that Vitest spawns and executes, validating the error handling logic works. | ||
|
|
||
| // Create a temporary directory for our fake tsc | ||
| const tmpDir = path.join(os.tmpdir(), `vitest-test-${Date.now()}`) | ||
|
|
||
| // Create fake tsc script - cross-platform executable | ||
| // Using createFile ensures cleanup even if test fails | ||
| const fakeTscPath = path.join(tmpDir, 'fake-tsc') | ||
| const scriptContent = '#!/usr/bin/env node\nconsole.log(\'Version 5.3.3\');\nconsole.log(\'tsc: The TypeScript Compiler - Version 5.3.3\');\nconsole.log(\'\');\nconsole.log(\'COMMON COMMANDS\');\n' | ||
|
|
||
| createFile(fakeTscPath, scriptContent) | ||
| fs.chmodSync(fakeTscPath, '755') | ||
|
|
||
| const configContent = `import { defineConfig } from 'vitest/config' | ||
| export default defineConfig({ | ||
| test: { | ||
| typecheck: { | ||
| enabled: true, | ||
| checker: '${fakeTscPath.replace(/\\/g, '/')}', | ||
| }, | ||
| }, | ||
| })` | ||
|
|
||
| const { stderr, stdout } = await runInlineTests({ | ||
| 'vitest.config.ts': configContent, | ||
| 'example.test-d.ts': 'import { expectTypeOf, test } from \'vitest\'\ntest(\'dummy type test\', () => { expectTypeOf(1).toEqualTypeOf<number>() })', | ||
| }) | ||
|
|
||
| // Assert that Vitest caught the help text and threw the descriptive error | ||
| const output = stderr + stdout | ||
| expect(output).toContain('TypeScript compiler returned help text instead of type checking results') | ||
| expect(output).toContain('This usually means the tsconfig file was not found') | ||
| expect(output).toContain('Ensure \'tsconfig.json\' exists in your project root') | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { resolve } from 'pathe' | ||
| import { describe, expect, it } from 'vitest' | ||
| import { runVitest } from '../../test-utils' | ||
|
|
||
| describe('Typechecker', () => { | ||
| it('handles non-existing typechecker command gracefully', async () => { | ||
| const { stderr } = await runVitest({ | ||
| root: resolve(import.meta.dirname, '../fixtures/source-error'), | ||
| typecheck: { | ||
| enabled: true, | ||
| checker: 'non-existing-tsc-command', | ||
| }, | ||
| }) | ||
|
|
||
| // Should show proper error when typechecker doesn't exist | ||
| expect(stderr).toContain('Spawning typechecker failed') | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.