Skip to content

Commit ea1c44f

Browse files
authored
docs: sequence.setupFiles default is 'list' (#11351)
1 parent 0fd6b97 commit ea1c44f

6 files changed

Lines changed: 72 additions & 5 deletions

File tree

‎docs/config/sequence.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ This option doesn't affect [`onTestFinished`](/api/hooks#ontestfinished). It is
156156
## sequence.setupFiles {#sequence-setupfiles}
157157

158158
- **Type:** `'list' | 'parallel'`
159-
- **Default:** `'parallel'`
159+
- **Default:** `'list'`
160160
- **CLI:** `--sequence.setupFiles=<value>`
161161

162162
Changes the order in which setup files are executed.

‎docs/config/setupfiles.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ outline: deep
77

88
- **Type:** `string | string[]`
99

10-
Paths to setup files resolved relative to the [`root`](/config/root). They will run before each _test file_ in the same process. By default, all test files run in parallel, but you can configure it with [`sequence.setupFiles`](/config/sequence#sequence-setupfiles) option.
10+
Paths to setup files resolved relative to the [`root`](/config/root). They will run before each _test file_ in the same process. By default, setup files run one after another in the order they are defined, but you can configure it with [`sequence.setupFiles`](/config/sequence#sequence-setupfiles) option.
1111

1212
Vitest will ignore any exports from these files.
1313

‎docs/guide/cli-generated.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ Changes the order in which hooks are executed. Accepted values are: "stack", "li
554554
- **CLI:** `--sequence.setupFiles <order>`
555555
- **Config:** [sequence.setupFiles](/config/sequence#sequence-setupfiles)
556556

557-
Changes the order in which setup files are executed. Accepted values are: "list" and "parallel". If set to "list", will run setup files in the order they are defined. If set to "parallel", will run setup files in parallel (default: `"parallel"`)
557+
Changes the order in which setup files are executed. Accepted values are: "list" and "parallel". If set to "list", will run setup files in the order they are defined. If set to "parallel", will run setup files in parallel (default: `"list"`)
558558

559559
### inspect
560560

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
543543
},
544544
setupFiles: {
545545
description:
546-
'Changes the order in which setup files are executed. Accepted values are: "list" and "parallel". If set to "list", will run setup files in the order they are defined. If set to "parallel", will run setup files in parallel (default: `"parallel"`)',
546+
'Changes the order in which setup files are executed. Accepted values are: "list" and "parallel". If set to "list", will run setup files in the order they are defined. If set to "parallel", will run setup files in parallel (default: `"list"`)',
547547
argument: '<order>',
548548
},
549549
groupOrder: null,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ interface SequenceOptions {
128128
* Defines how setup files should be ordered
129129
* - 'parallel' will run all setup files in parallel
130130
* - 'list' will run all setup files in the order they are defined in the config file
131-
* @default 'parallel'
131+
* @default 'list'
132132
*/
133133
setupFiles?: SequenceSetupFiles
134134
/**

‎test/e2e/test/setup-files.test.ts‎

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,70 @@ it('re-evaluates an extensionless setup file when isolation is disabled', async
132132
}
133133
`)
134134
})
135+
136+
describe('sequence.setupFiles', () => {
137+
function run(expectedOrder: string[], sequence?: { setupFiles: 'list' | 'parallel' }) {
138+
return runInlineTests({
139+
'vitest.config.js': `
140+
export default {
141+
test: {
142+
setupFiles: ['./first-setup.js', './second-setup.js'],
143+
${sequence ? `sequence: ${JSON.stringify(sequence)},` : ''}
144+
},
145+
}
146+
`,
147+
'first-setup.js': `
148+
globalThis.setupOrder ??= []
149+
await new Promise(resolve => setTimeout(resolve, 100))
150+
globalThis.setupOrder.push('first')
151+
`,
152+
'second-setup.js': `
153+
globalThis.setupOrder ??= []
154+
globalThis.setupOrder.push('second')
155+
`,
156+
'order.test.js': `
157+
import { expect, test } from 'vitest'
158+
159+
test('setup order', () => {
160+
expect(globalThis.setupOrder).toEqual(${JSON.stringify(expectedOrder)})
161+
})
162+
`,
163+
})
164+
}
165+
166+
it('runs setup files in the defined order by default', async () => {
167+
const { stderr, testTree } = await run(['first', 'second'])
168+
expect(stderr).toBe('')
169+
expect(testTree()).toMatchInlineSnapshot(`
170+
{
171+
"order.test.js": {
172+
"setup order": "passed",
173+
},
174+
}
175+
`)
176+
})
177+
178+
it('runs setup files in the defined order with "list"', async () => {
179+
const { stderr, testTree } = await run(['first', 'second'], { setupFiles: 'list' })
180+
expect(stderr).toBe('')
181+
expect(testTree()).toMatchInlineSnapshot(`
182+
{
183+
"order.test.js": {
184+
"setup order": "passed",
185+
},
186+
}
187+
`)
188+
})
189+
190+
it('runs setup files in parallel with "parallel"', async () => {
191+
const { stderr, testTree } = await run(['second', 'first'], { setupFiles: 'parallel' })
192+
expect(stderr).toBe('')
193+
expect(testTree()).toMatchInlineSnapshot(`
194+
{
195+
"order.test.js": {
196+
"setup order": "passed",
197+
},
198+
}
199+
`)
200+
})
201+
})

0 commit comments

Comments
 (0)