Skip to content

Commit

Permalink
feat: add concurrent option to sequence config (#3604)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladimir <sleuths.slews0s@icloud.com>
  • Loading branch information
fenghan34 and sheremet-va authored Jun 19, 2023
1 parent 2db1a73 commit f427f00
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,15 @@ If you want tests to run randomly, you can enable it with this option, or CLI ar
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.
#### sequence.concurrent
- **Type**: `boolean`
- **Default**: `false`
- **CLI**: `--sequence.concurrent`, `--sequence.concurrent=false`
- **Version**: Since Vitest 0.32.2
If you want tests to run in parallel, you can enable it with this option, or CLI argument [`--sequence.concurrent`](/guide/cli).
#### sequence.seed<NonProjectOption />
- **Type**: `number`
Expand Down
4 changes: 2 additions & 2 deletions packages/runner/src/suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getRunner() {

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

if (this.concurrent || concurrent)
if (this.concurrent || concurrent || runner.config.sequence.concurrent)
test.concurrent = true
if (shuffle)
test.shuffle = true
Expand Down
1 change: 1 addition & 0 deletions packages/runner/src/types/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface VitestRunnerConfig {
allowOnly?: boolean
sequence: {
shuffle?: boolean
concurrent?: boolean
seed: number
hooks: SequenceHooks
setupFiles: SequenceSetupFiles
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cli
.option('--dangerouslyIgnoreUnhandledErrors', 'Ignore any unhandled errors that occur')
.option('--shard <shard>', 'Test suite shard to execute in a format of <index>/<count>')
.option('--changed [since]', 'Run tests that are affected by the changed files (default: false)')
.option('--sequence <options>', 'Define in what order to run tests (use --sequence.shuffle to run tests in random order)')
.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)')
.option('--segfaultRetry <times>', 'Return tests on segment fault (default: 0)', { default: 0 })
.option('--no-color', 'Removes colors from the console output')
.option('--inspect', 'Enable Node.js inspector')
Expand Down
6 changes: 6 additions & 0 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ interface SequenceOptions {
* @default false
*/
shuffle?: boolean
/**
* Should tests run in parallel.
* @default false
*/
concurrent?: boolean
/**
* Defines how setup files should be ordered
* - 'parallel' will run all setup files in parallel
Expand Down Expand Up @@ -703,6 +708,7 @@ export interface ResolvedConfig extends Omit<Required<UserConfig>, 'config' | 'f
hooks: SequenceHooks
setupFiles: SequenceSetupFiles
shuffle?: boolean
concurrent?: boolean
seed: number
}

Expand Down

0 comments on commit f427f00

Please sign in to comment.