[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

feat(config): add an option to run setupFiles in sequence (#3008)

authored by

Vladimir and committed by
GitHub
(Mar 15, 2023, 8:43 PM +0100) c2e25bb9 22ca0b6b

+38 -8
+14 -2
docs/config/index.md
··· 94 94 #### deps.experimentalOptimizer 95 95 96 96 - **Type:** `DepOptimizationConfig & { enabled: boolean }` 97 - - **Version:** Vitets 0.29.0 97 + - **Version:** Since Vitest 0.29.0 98 98 - **See also:** [Dep Optimization Options](https://vitejs.dev/config/dep-optimization-options.html) 99 99 100 100 Enable dependency optimization. If you have a lot of tests, this might improve their performance. ··· 1162 1162 1163 1163 ### sequence 1164 1164 1165 - - **Type**: `{ sequencer?, shuffle?, seed?, hooks? }` 1165 + - **Type**: `{ sequencer?, shuffle?, seed?, hooks?, setupFiles? }` 1166 1166 1167 1167 Options for how tests should be sorted. 1168 1168 ··· 1210 1210 - `stack` will order "after" hooks in reverse order, "before" hooks will run in the order they were defined 1211 1211 - `list` will order all hooks in the order they are defined 1212 1212 - `parallel` will run hooks in a single group in parallel (hooks in parent suites will still run before the current suite's hooks) 1213 + 1214 + #### sequence.setupFiles 1215 + 1216 + - **Type**: `'list' | 'parallel'` 1217 + - **Default**: `'parallel'` 1218 + - **CLI**: `--sequence.setupFiles=<value>` 1219 + - **Version**: Since Vitest 0.29.3 1220 + 1221 + Changes the order in which setup files are executed. 1222 + 1223 + - `list` will run setup files in the order they are defined 1224 + - `parallel` will run setup files in parallel 1213 1225 1214 1226 ### typecheck 1215 1227
+10 -4
packages/runner/src/setup.ts
··· 3 3 4 4 export async function runSetupFiles(config: VitestRunnerConfig, runner: VitestRunner) { 5 5 const files = toArray(config.setupFiles) 6 - await Promise.all( 7 - files.map(async (fsPath) => { 6 + if (config.sequence.setupFiles === 'parallel') { 7 + await Promise.all( 8 + files.map(async (fsPath) => { 9 + await runner.importFile(fsPath, 'setup') 10 + }), 11 + ) 12 + } 13 + else { 14 + for (const fsPath of files) 8 15 await runner.importFile(fsPath, 'setup') 9 - }), 10 - ) 16 + } 11 17 }
+2 -1
packages/runner/src/types/runner.ts
··· 1 - import type { File, SequenceHooks, Suite, TaskResult, Test, TestContext } from './tasks' 1 + import type { File, SequenceHooks, SequenceSetupFiles, Suite, TaskResult, Test, TestContext } from './tasks' 2 2 3 3 export interface VitestRunnerConfig { 4 4 root: string ··· 11 11 shuffle?: boolean 12 12 seed: number 13 13 hooks: SequenceHooks 14 + setupFiles: SequenceSetupFiles 14 15 } 15 16 maxConcurrency: number 16 17 testTimeout: number
+1
packages/runner/src/types/tasks.ts
··· 230 230 export type OnTestFailedHandler = (result: TaskResult) => Awaitable<void> 231 231 232 232 export type SequenceHooks = 'stack' | 'list' | 'parallel' 233 + export type SequenceSetupFiles = 'list' | 'parallel'
+11 -1
packages/vitest/src/types/config.ts
··· 1 1 import type { AliasOptions, CommonServerOptions, DepOptimizationConfig } from 'vite' 2 2 import type { PrettyFormatOptions } from 'pretty-format' 3 3 import type { FakeTimerInstallOpts } from '@sinonjs/fake-timers' 4 + import type { SequenceHooks, SequenceSetupFiles } from '@vitest/runner' 4 5 import type { BuiltinReporters } from '../node/reporters' 5 6 import type { TestSequencerConstructor } from '../node/sequencers/types' 6 7 import type { CoverageOptions, ResolvedCoverageOptions } from './coverage' ··· 10 11 import type { Arrayable } from './general' 11 12 import type { BenchmarkUserOptions } from './benchmark' 12 13 14 + export type { SequenceHooks, SequenceSetupFiles } from '@vitest/runner' 15 + 13 16 export type BuiltinEnvironment = 'node' | 'jsdom' | 'happy-dom' | 'edge-runtime' 14 17 // Record is used, so user can get intellisense for builtin environments, but still allow custom environments 15 18 export type VitestEnvironment = BuiltinEnvironment | (string & Record<never, never>) 16 19 export type CSSModuleScopeStrategy = 'stable' | 'scoped' | 'non-scoped' 17 - export type SequenceHooks = 'stack' | 'list' | 'parallel' 18 20 19 21 export type ApiConfig = Pick<CommonServerOptions, 'port' | 'strictPort' | 'host'> 20 22 ··· 499 501 */ 500 502 shuffle?: boolean 501 503 /** 504 + * Defines how setup files should be ordered 505 + * - 'parallel' will run all setup files in parallel 506 + * - 'list' will run all setup files in the order they are defined in the config file 507 + * @default 'parallel' 508 + */ 509 + setupFiles?: SequenceSetupFiles 510 + /** 502 511 * Seed for the random number generator. 503 512 * @default Date.now() 504 513 */ ··· 648 657 sequence: { 649 658 sequencer: TestSequencerConstructor 650 659 hooks: SequenceHooks 660 + setupFiles: SequenceSetupFiles 651 661 shuffle?: boolean 652 662 seed: number 653 663 }