Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add concurrent option to sequence config #3604

Merged
merged 3 commits into from Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/config/index.md
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

sheremet-va marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Up @@ -30,7 +30,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 @@ -82,7 +82,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
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
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
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