Skip to content

Commit 80f8bbf

Browse files
authoredNov 14, 2024··
fix: misc fix for vite 6 ecosystem ci (#6867)
1 parent b915aa6 commit 80f8bbf

File tree

6 files changed

+28
-5
lines changed

6 files changed

+28
-5
lines changed
 

‎packages/vitest/src/node/plugins/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ export async function VitestPlugin(
191191
) {
192192
const watch = config.server!.watch
193193
if (watch) {
194+
// eslint-disable-next-line ts/ban-ts-comment
195+
// @ts-ignore Vite 6 compat
194196
watch.useFsEvents = false
195197
watch.usePolling = false
196198
}

‎packages/vitest/src/typecheck/collect.ts

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export async function collectTests(
5151
if (!request) {
5252
return null
5353
}
54+
// unwrap __vite_ssr_identity__ for Vite 6
55+
request.code = request.code.replace(/__vite_ssr_identity__\((\w+\.\w+)\)/g, '( $1)')
5456
const ast = await parseAstAsync(request.code)
5557
const testFilepath = relative(ctx.config.root, filepath)
5658
const projectName = ctx.getName()

‎test/cli/fixtures/vm-threads/vitest.config.ts

+3
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ export default defineConfig({
1212
},
1313
},
1414
},
15+
build: {
16+
assetsInlineLimit: 0,
17+
},
1518
})

‎test/cli/test/inspect.test.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { InspectorNotification } from 'node:inspector'
2+
import { version as viteVersion } from 'vite'
23
import { expect, test } from 'vitest'
34
import WebSocket from 'ws'
45

@@ -35,8 +36,16 @@ test('--inspect-brk stops at test file', async () => {
3536
send({ method: 'Debugger.getScriptSource', params: { scriptId } })
3637
const { result } = await response as any
3738

38-
expect(result.scriptSource).toContain('test("sum", () => {')
39-
expect(result.scriptSource).toContain('expect(1 + 1).toBe(2)')
39+
if (viteVersion[0] >= '6') {
40+
// vite ssr transform wraps import by
41+
// __vite_ssr_identity__(__vite_ssr_import_0__.test)(...)
42+
expect(result.scriptSource).toContain('test)("sum", () => {')
43+
expect(result.scriptSource).toContain('expect)(1 + 1).toBe(2)')
44+
}
45+
else {
46+
expect(result.scriptSource).toContain('test("sum", () => {')
47+
expect(result.scriptSource).toContain('expect(1 + 1).toBe(2)')
48+
}
4049

4150
send({ method: 'Debugger.resume' })
4251

‎test/cli/test/stacktraces.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { resolve } from 'pathe'
22
import { glob } from 'tinyglobby'
3-
import { describe, expect, it } from 'vitest'
4-
3+
import { version as viteVersion } from 'vite'
4+
import { describe, expect, it as vitestIt } from 'vitest'
55
import { runVitest } from '../../test-utils'
66

77
const [major] = process.version.slice(1).split('.').map(num => Number(num))
88

9+
const it = viteVersion[0] >= '6' ? (vitestIt.skip as typeof vitestIt) : vitestIt
10+
911
// To prevent the warnining coming up in snapshots
1012
process.setMaxListeners(20)
1113

‎test/coverage-test/test/vue.test.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { readdirSync } from 'node:fs'
22
import { resolve } from 'node:path'
3+
import { version as viteVersion } from 'vite'
34
import { beforeAll, expect } from 'vitest'
45
import { isBrowser, isV8Provider, readCoverageMap, runVitest, test } from '../utils'
56

@@ -20,7 +21,11 @@ test('files should not contain query parameters', () => {
2021
expect(files).not.toContain('Counter.component.ts?vue&type=script&src=true&lang.ts.html')
2122
})
2223

23-
test('coverage results matches snapshot', async () => {
24+
test('coverage results matches snapshot', async (ctx) => {
25+
if (viteVersion[0] >= '6') {
26+
ctx.skip()
27+
}
28+
2429
const coverageMap = await readCoverageMap()
2530
const summary = coverageMap.getCoverageSummary()
2631

0 commit comments

Comments
 (0)
Please sign in to comment.