mirror of
https://github.com/vitest-dev/vitest.git
synced 2026-02-01 17:36:51 +00:00
fix(typecheck): fix typecheck collect on Vite 6 (#6972)
This commit is contained in:
parent
38e50f1bbd
commit
7b35d13a6f
@ -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
|
||||
}
|
||||
|
||||
@ -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)')
|
||||
}
|
||||
|
||||
@ -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()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user