Skip to content

Commit f427f00

Browse files
fenghan34sheremet-va
andauthoredJun 19, 2023
feat: add concurrent option to sequence config (#3604)
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
1 parent 2db1a73 commit f427f00

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed
 

‎docs/config/index.md

+9
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,15 @@ If you want tests to run randomly, you can enable it with this option, or CLI ar
13081308

13091309
Vitest usually uses cache to sort tests, so long running tests start earlier - this makes tests run faster. If your tests will run in random order you will lose this performance improvement, but it may be useful to track tests that accidentally depend on another run previously.
13101310

1311+
#### sequence.concurrent
1312+
1313+
- **Type**: `boolean`
1314+
- **Default**: `false`
1315+
- **CLI**: `--sequence.concurrent`, `--sequence.concurrent=false`
1316+
- **Version**: Since Vitest 0.32.2
1317+
1318+
If you want tests to run in parallel, you can enable it with this option, or CLI argument [`--sequence.concurrent`](/guide/cli).
1319+
13111320
#### sequence.seed<NonProjectOption />
13121321

13131322
- **Type**: `number`

‎packages/runner/src/suite.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function getRunner() {
3131

3232
export function clearCollectorContext(currentRunner: VitestRunner) {
3333
if (!defaultSuite)
34-
defaultSuite = currentRunner.config.sequence.shuffle ? suite.shuffle('') : suite('')
34+
defaultSuite = currentRunner.config.sequence.shuffle ? suite.shuffle('') : currentRunner.config.sequence.concurrent ? suite.concurrent('') : suite('')
3535
runner = currentRunner
3636
collectorContext.tasks.length = 0
3737
defaultSuite.clear()
@@ -83,7 +83,7 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m
8383
meta: Object.create(null),
8484
} as Omit<Test, 'context'> as Test
8585

86-
if (this.concurrent || concurrent)
86+
if (this.concurrent || concurrent || runner.config.sequence.concurrent)
8787
test.concurrent = true
8888
if (shuffle)
8989
test.shuffle = true

‎packages/runner/src/types/runner.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface VitestRunnerConfig {
99
allowOnly?: boolean
1010
sequence: {
1111
shuffle?: boolean
12+
concurrent?: boolean
1213
seed: number
1314
hooks: SequenceHooks
1415
setupFiles: SequenceSetupFiles

‎packages/vitest/src/node/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ cli
4141
.option('--dangerouslyIgnoreUnhandledErrors', 'Ignore any unhandled errors that occur')
4242
.option('--shard <shard>', 'Test suite shard to execute in a format of <index>/<count>')
4343
.option('--changed [since]', 'Run tests that are affected by the changed files (default: false)')
44-
.option('--sequence <options>', 'Define in what order to run tests (use --sequence.shuffle to run tests in random order)')
44+
.option('--sequence <options>', 'Define in what order to run tests (use --sequence.shuffle to run tests in random order, use --sequence.concurrent to run tests in parallel)')
4545
.option('--segfaultRetry <times>', 'Return tests on segment fault (default: 0)', { default: 0 })
4646
.option('--no-color', 'Removes colors from the console output')
4747
.option('--inspect', 'Enable Node.js inspector')

‎packages/vitest/src/types/config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ interface SequenceOptions {
4848
* @default false
4949
*/
5050
shuffle?: boolean
51+
/**
52+
* Should tests run in parallel.
53+
* @default false
54+
*/
55+
concurrent?: boolean
5156
/**
5257
* Defines how setup files should be ordered
5358
* - 'parallel' will run all setup files in parallel
@@ -703,6 +708,7 @@ export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'f
703708
hooks: SequenceHooks
704709
setupFiles: SequenceSetupFiles
705710
shuffle?: boolean
711+
concurrent?: boolean
706712
seed: number
707713
}
708714

0 commit comments

Comments
 (0)
Please sign in to comment.