Skip to content

Commit

Permalink
feat: support running suites in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Apr 5, 2024
1 parent d400388 commit 50eb8bf
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
40 changes: 40 additions & 0 deletions examples/basic/test/repro.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { describe, test } from 'vitest'

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

// finishes in 3 sec
// (1st and 2nd suites in parallel)
describe('example-1', () => {
// finishes in 3 sec
// (1st and 2nd cases in serial)
describe('1st suite', { concurrentSuite: true }, () => {
test('1st case', async () => {
await sleep(1000)
})
test('2nd case', async () => {
await sleep(2000)
})
})

describe('2nd suite', { concurrentSuite: true }, () => {
test('1st case', async () => {
await sleep(1000)
})
test('2nd case', async () => {
await sleep(2000)
})
})
})

// finishes in 3 sec
// (same as example-1 but implemented as describe.each)
describe('example-2', () => {
describe.each(['1st suite', '2nd suite'])('%s', { concurrentSuite: true }, () => {
test('1st case', async () => {
await sleep(1000)
})
test('2nd case', async () => {
await sleep(2000)
})
})
})
5 changes: 4 additions & 1 deletion packages/runner/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m
if (typeof suiteOptions === 'object')
options = Object.assign({}, suiteOptions, options)

// TODO: `this.concurrent/sequential` always undefined?
// inherit concurrent / sequential from suite
options.concurrent = this.concurrent || (!this.sequential && options?.concurrent)
options.sequential = this.sequential || (!this.concurrent && options?.sequential)
Expand Down Expand Up @@ -215,6 +216,7 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m
tasks: [],
meta: Object.create(null),
projectName: '',
concurrent: suiteOptions?.concurrentSuite,
}

if (runner && includeLocation && runner.config.includeTaskLocation) {
Expand Down Expand Up @@ -282,7 +284,8 @@ function createSuite() {
if (currentSuite?.options)
options = { ...currentSuite.options, ...options }

// inherit concurrent / sequential from current suite
// TODO: `this.concurrent/sequential` always undefined?
// inherit test concurrent / sequential from current suite
options.concurrent = this.concurrent || (!this.sequential && options?.concurrent)
options.sequential = this.sequential || (!this.concurrent && options?.sequential)

Expand Down
4 changes: 4 additions & 0 deletions packages/runner/src/types/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ export interface TestOptions {
* Tests inherit `concurrent` from `describe()` and nested `describe()` will inherit from parent's `concurrent`.
*/
concurrent?: boolean
/**
* wip
*/
concurrentSuite?: boolean
/**
* Whether tests run sequentially.
* Tests inherit `sequential` from `describe()` and nested `describe()` will inherit from parent's `sequential`.
Expand Down

0 comments on commit 50eb8bf

Please sign in to comment.