diff --git a/packages/vitest/src/node/plugins/index.ts b/packages/vitest/src/node/plugins/index.ts index b24a0e06fce8..ae0c26ea824a 100644 --- a/packages/vitest/src/node/plugins/index.ts +++ b/packages/vitest/src/node/plugins/index.ts @@ -191,6 +191,8 @@ export async function VitestPlugin( ) { const watch = config.server!.watch if (watch) { + // eslint-disable-next-line ts/ban-ts-comment + // @ts-ignore Vite 6 compat watch.useFsEvents = false watch.usePolling = false } diff --git a/packages/vitest/src/typecheck/collect.ts b/packages/vitest/src/typecheck/collect.ts index de4e39ab4782..a3d4ed864dd8 100644 --- a/packages/vitest/src/typecheck/collect.ts +++ b/packages/vitest/src/typecheck/collect.ts @@ -51,6 +51,8 @@ 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.getName() diff --git a/test/cli/fixtures/vm-threads/vitest.config.ts b/test/cli/fixtures/vm-threads/vitest.config.ts index 82d2963ca99d..ce5a109523ae 100644 --- a/test/cli/fixtures/vm-threads/vitest.config.ts +++ b/test/cli/fixtures/vm-threads/vitest.config.ts @@ -12,4 +12,7 @@ export default defineConfig({ }, }, }, + build: { + assetsInlineLimit: 0, + }, }) diff --git a/test/cli/test/inspect.test.ts b/test/cli/test/inspect.test.ts index 9a0ae290eb55..ac5437dc80b3 100644 --- a/test/cli/test/inspect.test.ts +++ b/test/cli/test/inspect.test.ts @@ -1,4 +1,5 @@ import type { InspectorNotification } from 'node:inspector' +import { version as viteVersion } from 'vite' import { expect, test } from 'vitest' import WebSocket from 'ws' @@ -35,8 +36,16 @@ test('--inspect-brk stops at test file', async () => { send({ method: 'Debugger.getScriptSource', params: { scriptId } }) const { result } = await response as any - expect(result.scriptSource).toContain('test("sum", () => {') - expect(result.scriptSource).toContain('expect(1 + 1).toBe(2)') + if (viteVersion[0] >= '6') { + // vite ssr transform wraps import by + // __vite_ssr_identity__(__vite_ssr_import_0__.test)(...) + expect(result.scriptSource).toContain('test)("sum", () => {') + expect(result.scriptSource).toContain('expect)(1 + 1).toBe(2)') + } + else { + expect(result.scriptSource).toContain('test("sum", () => {') + expect(result.scriptSource).toContain('expect(1 + 1).toBe(2)') + } send({ method: 'Debugger.resume' }) diff --git a/test/cli/test/stacktraces.test.ts b/test/cli/test/stacktraces.test.ts index 6e38e8fff323..63690be215ef 100644 --- a/test/cli/test/stacktraces.test.ts +++ b/test/cli/test/stacktraces.test.ts @@ -1,11 +1,13 @@ import { resolve } from 'pathe' import { glob } from 'tinyglobby' -import { describe, expect, it } from 'vitest' - +import { version as viteVersion } from 'vite' +import { describe, expect, it as vitestIt } from 'vitest' import { runVitest } from '../../test-utils' const [major] = process.version.slice(1).split('.').map(num => Number(num)) +const it = viteVersion[0] >= '6' ? (vitestIt.skip as typeof vitestIt) : vitestIt + // To prevent the warnining coming up in snapshots process.setMaxListeners(20) diff --git a/test/coverage-test/test/vue.test.ts b/test/coverage-test/test/vue.test.ts index 19ee0fa11e92..4a76d1f071fa 100644 --- a/test/coverage-test/test/vue.test.ts +++ b/test/coverage-test/test/vue.test.ts @@ -1,5 +1,6 @@ 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' @@ -20,7 +21,11 @@ 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 () => { +test('coverage results matches snapshot', async (ctx) => { + if (viteVersion[0] >= '6') { + ctx.skip() + } + const coverageMap = await readCoverageMap() const summary = coverageMap.getCoverageSummary()