Skip to content

Commit 2597cd6

Browse files
committed
feat: support running suites in parallel
1 parent d400388 commit 2597cd6

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

examples/basic/test/repro.test.ts

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { describe, test } from 'vitest'
2+
3+
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
4+
5+
// finishes in 3 sec
6+
// (1st and 2nd suites in parallel)
7+
describe('example-1', () => {
8+
// finishes in 3 sec
9+
// (1st and 2nd cases in serial)
10+
describe('1st suite', { concurrentSuite: true }, () => {
11+
test('1st case', async () => {
12+
await sleep(1000)
13+
})
14+
test('2nd case', async () => {
15+
await sleep(2000)
16+
})
17+
})
18+
19+
describe('2nd suite', { concurrentSuite: true }, () => {
20+
test('1st case', async () => {
21+
await sleep(1000)
22+
})
23+
test('2nd case', async () => {
24+
await sleep(2000)
25+
})
26+
})
27+
})
28+
29+
// finishes in 3 sec
30+
// (same as example-1 but implemented as describe.each)
31+
describe('example-2', () => {
32+
describe.each(['1st suite', '2nd suite'])('%s', { concurrentSuite: true }, () => {
33+
test('1st case', async () => {
34+
await sleep(1000)
35+
})
36+
test('2nd case', async () => {
37+
await sleep(2000)
38+
})
39+
})
40+
})

packages/runner/src/suite.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m
172172
if (typeof suiteOptions === 'object')
173173
options = Object.assign({}, suiteOptions, options)
174174

175-
// inherit concurrent / sequential from suite
175+
// TODO: `this.concurrent/sequential` always undefined?
176+
// inherit concurrent / sequential from current suite
176177
options.concurrent = this.concurrent || (!this.sequential && options?.concurrent)
177178
options.sequential = this.sequential || (!this.concurrent && options?.sequential)
178179

@@ -215,6 +216,7 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m
215216
tasks: [],
216217
meta: Object.create(null),
217218
projectName: '',
219+
concurrent: suiteOptions?.concurrentSuite,
218220
}
219221

220222
if (runner && includeLocation && runner.config.includeTaskLocation) {
@@ -282,7 +284,8 @@ function createSuite() {
282284
if (currentSuite?.options)
283285
options = { ...currentSuite.options, ...options }
284286

285-
// inherit concurrent / sequential from current suite
287+
// TODO: `this.concurrent/sequential` always undefined?
288+
// inherit test concurrent / sequential from current suite
286289
options.concurrent = this.concurrent || (!this.sequential && options?.concurrent)
287290
options.sequential = this.sequential || (!this.concurrent && options?.sequential)
288291

packages/runner/src/types/tasks.ts

+4
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ export interface TestOptions {
185185
* Tests inherit `concurrent` from `describe()` and nested `describe()` will inherit from parent's `concurrent`.
186186
*/
187187
concurrent?: boolean
188+
/**
189+
* wip
190+
*/
191+
concurrentSuite?: boolean
188192
/**
189193
* Whether tests run sequentially.
190194
* Tests inherit `sequential` from `describe()` and nested `describe()` will inherit from parent's `sequential`.

0 commit comments

Comments
 (0)