···11+import fs from 'node:fs'
22+import os from 'node:os'
33+import path from 'node:path'
44+import { describe, expect, it } from 'vitest'
55+import { createFile, runInlineTests } from '../../test-utils'
66+77+describe('Typechecker Error Handling', () => {
88+ it('throws helpful error when tsc outputs help text (missing config)', async () => {
99+ // TESTING APPROACH:
1010+ // We cannot reliably trigger tsc's help text output in normal usage because:
1111+ // 1. tsc only shows help when called with NO arguments or INVALID arguments
1212+ // 2. Vitest always calls tsc with proper arguments (--noEmit, --pretty, etc.)
1313+ // 3. Invalid tsconfig causes ERROR output, not help text
1414+ //
1515+ // SOLUTION: Use a test executable that mimics tsc help output
1616+ // This is NOT a mock (no jest.mock or similar), but a real executable script
1717+ // that Vitest spawns and executes, validating the error handling logic works.
1818+1919+ // Create a temporary directory for our fake tsc
2020+ const tmpDir = path.join(os.tmpdir(), `vitest-test-${Date.now()}`)
2121+2222+ // Create fake tsc script - cross-platform executable
2323+ // Using createFile ensures cleanup even if test fails
2424+ const fakeTscPath = path.join(tmpDir, 'fake-tsc')
2525+ 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'
2626+2727+ createFile(fakeTscPath, scriptContent)
2828+ fs.chmodSync(fakeTscPath, '755')
2929+3030+ const configContent = `import { defineConfig } from 'vitest/config'
3131+export default defineConfig({
3232+ test: {
3333+ typecheck: {
3434+ enabled: true,
3535+ checker: '${fakeTscPath.replace(/\\/g, '/')}',
3636+ },
3737+ },
3838+})`
3939+4040+ const { stderr, stdout } = await runInlineTests({
4141+ 'vitest.config.ts': configContent,
4242+ 'example.test-d.ts': 'import { expectTypeOf, test } from \'vitest\'\ntest(\'dummy type test\', () => { expectTypeOf(1).toEqualTypeOf<number>() })',
4343+ })
4444+4545+ // Assert that Vitest caught the help text and threw the descriptive error
4646+ const output = stderr + stdout
4747+ expect(output).toContain('TypeScript compiler returned help text instead of type checking results')
4848+ expect(output).toContain('This usually means the tsconfig file was not found')
4949+ expect(output).toContain('Ensure \'tsconfig.json\' exists in your project root')
5050+ })
5151+})