[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix: fix `getState().testPath` during collection with no isolation (#7640)

authored by

Hiroshi Ogawa and committed by
GitHub
(Mar 11, 2025, 2:48 PM +0100) 3fb3fbf8 e4b34b81

+49 -1
+19
test/config/test/get-state.test.ts
··· 1 + import type { UserConfig } from 'vitest/node' 2 + import { expect, test } from 'vitest' 3 + import { runVitest } from '../../test-utils' 4 + 5 + test.for([ 6 + { isolate: true }, 7 + { isolate: false, minWorkers: 1, maxWorkers: 1 }, 8 + { isolate: false, fileParallelism: false }, 9 + { isolate: false, poolOptions: { forks: { singleFork: true } } }, 10 + ] satisfies UserConfig[])(`getState().testPath during collection %s`, async (config) => { 11 + const result = await runVitest({ 12 + root: './fixtures/get-state', 13 + ...config, 14 + }) 15 + expect(result.stderr).toBe('') 16 + expect(result.stdout).toContain('✓ a.test.ts') 17 + expect(result.stdout).toContain('✓ b.test.ts') 18 + expect(result.stdout).toContain('✓ c.test.ts') 19 + })
+7
test/config/fixtures/get-state/a.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + 3 + const testPath = expect.getState().testPath; 4 + 5 + test("a", () => { 6 + expect(testPath).toContain('a.test.ts') 7 + })
+7
test/config/fixtures/get-state/b.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + 3 + const testPath = expect.getState().testPath; 4 + 5 + test("b", () => { 6 + expect(testPath).toContain('b.test.ts') 7 + })
+7
test/config/fixtures/get-state/c.test.ts
··· 1 + import { expect, test } from 'vitest' 2 + 3 + const testPath = expect.getState().testPath; 4 + 5 + test("c", () => { 6 + expect(testPath).toContain('c.test.ts') 7 + })
+9
test/config/fixtures/get-state/vitest.config.ts
··· 1 + import { defineConfig } from "vitest/config"; 2 + 3 + export default defineConfig({ 4 + test: { 5 + isolate: false, 6 + minWorkers: 1, 7 + maxWorkers: 1, 8 + } 9 + })
-1
packages/vitest/src/runtime/runners/test.ts
··· 125 125 isExpectingAssertionsError: null, 126 126 expectedAssertionsNumber: null, 127 127 expectedAssertionsNumberErrorGen: null, 128 - testPath: test.file.filepath, 129 128 currentTestName: getTestName(test), 130 129 snapshotState: this.snapshotClient.getSnapshotState(test.file.filepath), 131 130 },