Skip to content

Commit

Permalink
fix: fix type test collect
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 11, 2024
1 parent 147165a commit 6e7953d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
4 changes: 4 additions & 0 deletions packages/vitest/src/typecheck/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,14 @@ export async function collectTests(
ctx: WorkspaceProject,
filepath: string,
): Promise<null | FileInformation> {
// 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()
Expand Down
26 changes: 13 additions & 13 deletions test/typescript/test/__snapshots__/runner.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ TypeCheckError: This expression is not callable. Type 'ExpectArray<number>' has
TypeCheckError: This expression is not callable. Type 'ExpectUndefined<number>' has no call signatures.
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' 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<number>' has no call signatures."
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' 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<number>()"
`;
exports[`should fail > typecheck files 3`] = `
" FAIL fail.test-d.ts > nested suite
TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' has no call signatures.
❯ fail.test-d.ts:15:19
Expand All @@ -21,17 +32,6 @@ TypeCheckError: This expression is not callable. Type 'ExpectVoid<number>' 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<number>()"
`;
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"'.
Expand Down

0 comments on commit 6e7953d

Please sign in to comment.