-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(runner): fix fixture cleanup for concurrent tests (#4827)
- Loading branch information
Showing
3 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { afterAll, beforeEach, expect, test } from 'vitest' | ||
|
||
// this test case might look exotic, but a few conditions were required to reproduce the reported bug. | ||
// such particular conditions are marked with "[repro]" in the comments. | ||
|
||
let globalA = 0 | ||
let globalB = 0 | ||
|
||
interface MyFixtures { | ||
a: number | ||
b: number | ||
} | ||
|
||
export const myTest = test.extend<MyFixtures>({ | ||
// [repro] fixture order must be { a, b } and not { b, a } | ||
a: async ({}, use) => { | ||
globalA++ | ||
await new Promise<void>(resolve => setTimeout(resolve, 200)) // [repro] async fixture | ||
await use(globalA) | ||
}, | ||
b: async ({}, use) => { | ||
globalB++ | ||
await use(globalB) | ||
}, | ||
}) | ||
|
||
// [repro] beforeEach uses only "b" | ||
beforeEach<MyFixtures>(({ b }) => { | ||
expect(b).toBeTypeOf('number') | ||
}) | ||
|
||
afterAll(() => { | ||
expect([globalA, globalB]).toEqual([2, 2]) | ||
}) | ||
|
||
// [repro] concurrent test uses both "a" and "b" | ||
myTest.concurrent('test1', async ({ a, b }) => { | ||
expect(a).toBeTypeOf('number') | ||
expect(b).toBeTypeOf('number') | ||
}) | ||
|
||
myTest.concurrent('test2', async ({ a, b }) => { | ||
expect(a).toBeTypeOf('number') | ||
expect(b).toBeTypeOf('number') | ||
}) |