diff --git a/packages/vitest/src/typecheck/collect.ts b/packages/vitest/src/typecheck/collect.ts index f5babbb5591d..c9139493a576 100644 --- a/packages/vitest/src/typecheck/collect.ts +++ b/packages/vitest/src/typecheck/collect.ts @@ -1,4 +1,5 @@ import type { File, Suite, Test } from '@vitest/runner' +import type { Node } from 'estree' import type { RawSourceMap } from 'vite-node' import type { TestProject } from '../node/project' import { @@ -51,8 +52,6 @@ export async function collectTests( if (!request) { return null } - // unwrap __vite_ssr_identity__ for Vite 6 - 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.name @@ -72,7 +71,7 @@ export async function collectTests( } file.file = file const definitions: LocalCallDefinition[] = [] - const getName = (callee: any): string | null => { + const getName = (callee: Node): string | null => { if (!callee) { return null } @@ -86,12 +85,20 @@ export async function collectTests( return getName(callee.tag) } if (callee.type === 'MemberExpression') { + const object = callee.object as any // direct call as `__vite_ssr_exports_0__.test()` - if (callee.object?.name?.startsWith('__vite_ssr_')) { + if (object?.name?.startsWith('__vite_ssr_')) { return getName(callee.property) } // call as `__vite_ssr__.test.skip()` - return getName(callee.object?.property) + return getName(object?.property) + } + // unwrap (0, ...) + if (callee.type === 'SequenceExpression' && callee.expressions.length === 2) { + const [e0, e1] = callee.expressions + if (e0.type === 'Literal' && e0.value === 0) { + return getName(e1) + } } return null } diff --git a/test/cli/test/inspect.test.ts b/test/cli/test/inspect.test.ts index ac5437dc80b3..dca2e248f499 100644 --- a/test/cli/test/inspect.test.ts +++ b/test/cli/test/inspect.test.ts @@ -38,7 +38,7 @@ test('--inspect-brk stops at test file', async () => { if (viteVersion[0] >= '6') { // vite ssr transform wraps import by - // __vite_ssr_identity__(__vite_ssr_import_0__.test)(...) + // (0, __vite_ssr_import_0__.test)(...) expect(result.scriptSource).toContain('test)("sum", () => {') expect(result.scriptSource).toContain('expect)(1 + 1).toBe(2)') } diff --git a/test/coverage-test/test/vue.test.ts b/test/coverage-test/test/vue.test.ts index 4a76d1f071fa..19ee0fa11e92 100644 --- a/test/coverage-test/test/vue.test.ts +++ b/test/coverage-test/test/vue.test.ts @@ -1,6 +1,5 @@ import { readdirSync } from 'node:fs' import { resolve } from 'node:path' -import { version as viteVersion } from 'vite' import { beforeAll, expect } from 'vitest' import { isBrowser, isV8Provider, readCoverageMap, runVitest, test } from '../utils' @@ -21,11 +20,7 @@ test('files should not contain query parameters', () => { expect(files).not.toContain('Counter.component.ts?vue&type=script&src=true&lang.ts.html') }) -test('coverage results matches snapshot', async (ctx) => { - if (viteVersion[0] >= '6') { - ctx.skip() - } - +test('coverage results matches snapshot', async () => { const coverageMap = await readCoverageMap() const summary = coverageMap.getCoverageSummary()