Skip to content

Commit 5d26b87

Browse files
authored
fix(experimental): export setupEnvironment for custom pools (#9187)
1 parent 167d3a9 commit 5d26b87

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

docs/guide/advanced/pool.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Your `CustomPoolRunner` will be controlling how your custom test runner worker l
120120
In your worker file, you can import helper utilities from `vitest/worker`:
121121

122122
```ts [my-worker.ts]
123-
import { init, runBaseTests } from 'vitest/worker'
123+
import { init, runBaseTests, setupEnvironment } from 'vitest/worker'
124124

125125
init({
126126
post: (response) => {
@@ -141,7 +141,8 @@ init({
141141
deserialize: (value) => {
142142
// Optional, provide custom deserializer for `on` callbacks
143143
},
144-
runTests: state => runBaseTests('run', state),
145-
collectTests: state => runBaseTests('collect', state),
144+
runTests: (state, traces) => runBaseTests('run', state, traces),
145+
collectTests: (state, traces) => runBaseTests('collect', state, traces),
146+
setup: setupEnvironment,
146147
})
147148
```
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { runBaseTests } from '../runtime/workers/base'
1+
export { runBaseTests, setupEnvironment } from '../runtime/workers/base'
22
export { init } from '../runtime/workers/init'

packages/vitest/src/runtime/workers/base.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function startModuleRunner(options: ContextModuleRunnerOptions) {
3030
let _currentEnvironment!: Environment
3131
let _environmentTime: number
3232

33+
/** @experimental */
3334
export async function setupEnvironment(context: WorkerSetupContext): Promise<() => Promise<void>> {
3435
const startTime = performance.now()
3536
const {

test/core/test/exports.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ it('exports snapshot', async ({ skip, task }) => {
340340
"./worker": {
341341
"init": "function",
342342
"runBaseTests": "function",
343+
"setupEnvironment": "function",
343344
},
344345
}
345346
`)

0 commit comments

Comments
 (0)