diff --git a/packages/vitest/src/typecheck/collect.ts b/packages/vitest/src/typecheck/collect.ts index de4e39ab4782..1057e1ae0069 100644 --- a/packages/vitest/src/typecheck/collect.ts +++ b/packages/vitest/src/typecheck/collect.ts @@ -47,10 +47,14 @@ export async function collectTests( ctx: WorkspaceProject, filepath: string, ): Promise { + // TODO: can we avoid ssr transform entirely? + // const request = await ctx.server.transformRequest(filepath) const request = await ctx.vitenode.transformRequest(filepath, filepath) if (!request) { return null } + // unwrap __vite_ssr_identity__ for now + request.code = request.code.replace(/__vite_ssr_identity__\((\w+\.\w+)\)/g, ' ($1)') const ast = await parseAstAsync(request.code) const testFilepath = relative(ctx.config.root, filepath) const projectName = ctx.getName() diff --git a/test/typescript/test/__snapshots__/runner.test.ts.snap b/test/typescript/test/__snapshots__/runner.test.ts.snap index 83f4f56cfcd5..89c4d333f155 100644 --- a/test/typescript/test/__snapshots__/runner.test.ts.snap +++ b/test/typescript/test/__snapshots__/runner.test.ts.snap @@ -6,11 +6,22 @@ TypeCheckError: This expression is not callable. Type 'ExpectArray' has TypeCheckError: This expression is not callable. Type 'ExpectUndefined' has no call signatures. TypeCheckError: This expression is not callable. Type 'ExpectVoid' has no call signatures. TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'. -TypeCheckError: Unused '@ts-expect-error' directive. -TypeCheckError: This expression is not callable. Type 'ExpectVoid' has no call signatures." +TypeCheckError: This expression is not callable. Type 'ExpectVoid' has no call signatures. +TypeCheckError: Unused '@ts-expect-error' directive." `; exports[`should fail > typecheck files 2`] = ` +" FAIL expect-error.test-d.ts [ expect-error.test-d.ts ] +TypeCheckError: Unused '@ts-expect-error' directive. + ❯ expect-error.test-d.ts:4:3 + 2| + 3| test('failing test with expect-error', () => { + 4| // @ts-expect-error expect nothing + | ^ + 5| expectTypeOf(1).toEqualTypeOf()" +`; + +exports[`should fail > typecheck files 3`] = ` " FAIL fail.test-d.ts > nested suite TypeCheckError: This expression is not callable. Type 'ExpectVoid' has no call signatures. ❯ fail.test-d.ts:15:19 @@ -21,17 +32,6 @@ TypeCheckError: This expression is not callable. Type 'ExpectVoid' has n 16| })" `; -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 - 2| - 3| test('failing test with expect-error', () => { - 4| // @ts-expect-error expect nothing - | ^ - 5| expectTypeOf(1).toEqualTypeOf()" -`; - exports[`should fail > typecheck files 4`] = ` " FAIL fail.test-d.ts > failing test TypeCheckError: Type 'string' does not satisfy the constraint '"Expected string, Actual number"'.