Skip to content

Commit

Permalink
fix(typecheck): store tmp tsconfig close to original one (#2660)
Browse files Browse the repository at this point in the history
* fix: store tmp tsconfig close to original one

* chore: use separate tsconfig

* chore: cleanup
  • Loading branch information
sheremet-va committed Jan 19, 2023
1 parent 6a30cdd commit 26f915a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/base.ts
Expand Up @@ -241,7 +241,7 @@ export abstract class BaseReporter implements Reporter {
logger.log(padTitle('Tests'), getStateString(tests))
if (this.mode === 'typecheck') {
const failed = tests.filter(t => t.meta?.typecheck && t.result?.errors?.length)
logger.log(padTitle('Type Errors'), failed.length ? c.bold(c.red(`${failed} failed`)) : c.dim('no errors'))
logger.log(padTitle('Type Errors'), failed.length ? c.bold(c.red(`${failed.length} failed`)) : c.dim('no errors'))
}
logger.log(padTitle('Start at'), formatTimeString(this._timeStart))
if (this.watchFilters)
Expand Down
6 changes: 3 additions & 3 deletions packages/vitest/src/typecheck/parse.ts
@@ -1,6 +1,6 @@
import url from 'node:url'
import { writeFile } from 'node:fs/promises'
import { join } from 'pathe'
import { dirname, join } from 'pathe'
import { getTsconfig as getTsconfigContent } from 'get-tsconfig'
import type { TypecheckConfig } from '../types'
import type { RawErrsMap, TscErrorInfo } from './types'
Expand Down Expand Up @@ -58,8 +58,6 @@ export async function makeTscErrorInfo(
}

export async function getTsconfig(root: string, config: TypecheckConfig) {
const tempConfigPath = join(root, 'tsconfig.temp.json')

const configName = config.tsconfig?.includes('jsconfig.json')
? 'jsconfig.json'
: undefined
Expand All @@ -69,6 +67,8 @@ export async function getTsconfig(root: string, config: TypecheckConfig) {
if (!tsconfig)
throw new Error('no tsconfig.json found')

const tempConfigPath = join(dirname(tsconfig.path), 'tsconfig.vitest-temp.json')

try {
const tmpTsConfig: Record<string, any> = { ...tsconfig.config }

Expand Down
16 changes: 8 additions & 8 deletions test/typescript/test/__snapshots__/runner.test.ts.snap
@@ -1,6 +1,6 @@
// Vitest Snapshot v1

exports[`should fails > typecheck files 1`] = `
exports[`should fail > typecheck files 1`] = `
"TypeCheckError: Expected 1 arguments, but got 0.
TypeCheckError: Expected 1 arguments, but got 0.
TypeCheckError: Expected 1 arguments, but got 0.
Expand All @@ -10,7 +10,7 @@ TypeCheckError: Unused '@ts-expect-error' directive.
TypeCheckError: Expected 1 arguments, but got 0."
`;

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

exports[`should fails > typecheck files 3`] = `
exports[`should fail > typecheck files 3`] = `
" FAIL expect-error.test-d.ts > failing test with expect-error
TypeCheckError: Unused '@ts-expect-error' directive.
❯ expect-error.test-d.ts:4:3
Expand All @@ -32,7 +32,7 @@ TypeCheckError: Unused '@ts-expect-error' directive.
5| expectTypeOf(1).toEqualTypeOf<number>()"
`;
exports[`should fails > typecheck files 4`] = `
exports[`should fail > typecheck files 4`] = `
" FAIL fail.test-d.ts > failing test
TypeCheckError: Expected 1 arguments, but got 0.
❯ fail.test-d.ts:4:19
Expand All @@ -43,7 +43,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
5| })"
`;
exports[`should fails > typecheck files 5`] = `
exports[`should fail > typecheck files 5`] = `
" FAIL fail.test-d.ts > nested suite > nested 2 > failing test 2
TypeCheckError: Expected 1 arguments, but got 0.
❯ fail.test-d.ts:10:23
Expand All @@ -54,7 +54,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
11| expectTypeOf(1).toBeUndefined()"
`;
exports[`should fails > typecheck files 6`] = `
exports[`should fail > typecheck files 6`] = `
" FAIL fail.test-d.ts > nested suite > nested 2 > failing test 2
TypeCheckError: Expected 1 arguments, but got 0.
❯ fail.test-d.ts:11:23
Expand All @@ -65,7 +65,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
12| })"
`;
exports[`should fails > typecheck files 7`] = `
exports[`should fail > typecheck files 7`] = `
" FAIL js-fail.test-d.js > js test fails
TypeCheckError: Expected 1 arguments, but got 0.
❯ js-fail.test-d.js:6:19
Expand All @@ -76,7 +76,7 @@ TypeCheckError: Expected 1 arguments, but got 0.
7| })"
`;
exports[`should fails > typecheck files 8`] = `
exports[`should fail > typecheck files 8`] = `
" FAIL only.test-d.ts > failing test
TypeCheckError: Expected 1 arguments, but got 0.
❯ only.test-d.ts:4:19
Expand Down
7 changes: 2 additions & 5 deletions test/typescript/test/runner.test.ts
Expand Up @@ -3,18 +3,15 @@ import fg from 'fast-glob'
import { execa } from 'execa'
import { describe, expect, it } from 'vitest'

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

it('typecheck files', async () => {
// in Windows child_process is very unstable, we skip testing it
if (process.platform === 'win32' && process.env.CI)
return

const { stderr } = await execa('npx', [
'vitest',
'typecheck',
'--run',
'--dir',
resolve(__dirname, '..', './failing'),
'--config',
Expand Down
6 changes: 6 additions & 0 deletions test/typescript/tsconfig.json
@@ -0,0 +1,6 @@
{
"extends": "../../tsconfig.json",
"exclude": [
"**/dist/**"
]
}

0 comments on commit 26f915a

Please sign in to comment.