diff --git a/packages/runner/src/fixture.ts b/packages/runner/src/fixture.ts index 6722b5792000..faa31b4b9bf6 100644 --- a/packages/runner/src/fixture.ts +++ b/packages/runner/src/fixture.ts @@ -44,7 +44,7 @@ export function mergeContextFixtures(fixtures: Record, context: { f return context } -const fixtureValueMap = new Map() +const fixtureValueMaps = new Map>() let cleanupFnArray = new Array<() => void | Promise>() export async function callFixtureCleanup() { @@ -68,6 +68,10 @@ export function withFixtures(fn: Function, testContext?: TestContext) { if (!usedProps.length) return fn(context) + if (!fixtureValueMaps.get(context)) + fixtureValueMaps.set(context, new Map()) + const fixtureValueMap: Map = fixtureValueMaps.get(context)! + const usedFixtures = fixtures.filter(({ prop }) => usedProps.includes(prop)) const pendingFixtures = resolveDeps(usedFixtures) let cursor = 0 diff --git a/test/core/test/fixture-concurrent.test.ts b/test/core/test/fixture-concurrent.test.ts new file mode 100644 index 000000000000..b1bfd251dc58 --- /dev/null +++ b/test/core/test/fixture-concurrent.test.ts @@ -0,0 +1,24 @@ +import { expect, test } from 'vitest' + +export const myTest = test.extend<{ + a: string + b: string +}>({ + a: async ({ task }: any, use) => { + await new Promise(resolve => setTimeout(resolve, 200)) + await use(task.id) + }, + b: async ({ a }, use) => { + await use(a) + }, +}) + +myTest.concurrent('fixture - concurrent test 1', ({ a, b, task }) => { + expect(a).toBe(task.id) + expect(b).toBe(task.id) +}) + +myTest.concurrent('fixture - concurrent test 2', ({ a, b, task }) => { + expect(a).toBe(task.id) + expect(b).toBe(task.id) +})