@@ -3,11 +3,11 @@ import { createClient } from '@vitest/ws-client'
3
3
import type { ResolvedConfig } from 'vitest'
4
4
import type { VitestRunner } from '@vitest/runner'
5
5
import { createBrowserRunner } from './runner'
6
- import { BrowserSnapshotEnvironment } from './snapshot'
7
6
import { importId } from './utils'
8
7
import { setupConsoleLogSpy } from './logger'
9
8
import { createSafeRpc , rpc , rpcDone } from './rpc'
10
9
import { setupDialogsSpy } from './dialog'
10
+ import { BrowserSnapshotEnvironment } from './snapshot'
11
11
12
12
// @ts -expect-error mocking some node apis
13
13
globalThis . process = { env : { } , argv : [ ] , cwd : ( ) => '/' , stdout : { write : ( ) => { } } , nextTick : cb => cb ( ) }
@@ -75,19 +75,17 @@ ws.addEventListener('open', async () => {
75
75
76
76
await setupConsoleLogSpy ( )
77
77
setupDialogsSpy ( )
78
- await runTests ( paths , config )
78
+ await runTests ( paths , config ! )
79
79
} )
80
80
81
- let hasSnapshot = false
82
- async function runTests ( paths : string [ ] , config : any ) {
81
+ async function runTests ( paths : string [ ] , config : ResolvedConfig ) {
83
82
// need to import it before any other import, otherwise Vite optimizer will hang
84
83
const viteClientPath = '/@vite/client'
85
84
await import ( viteClientPath )
86
85
87
86
const {
88
87
startTests,
89
88
setupCommonEnv,
90
- setupSnapshotEnvironment,
91
89
takeCoverageInsideWorker,
92
90
} = await importId ( 'vitest/browser' ) as typeof import ( 'vitest/browser' )
93
91
@@ -101,10 +99,8 @@ async function runTests(paths: string[], config: any) {
101
99
runner = new BrowserRunner ( { config, browserHashMap } )
102
100
}
103
101
104
- if ( ! hasSnapshot ) {
105
- setupSnapshotEnvironment ( new BrowserSnapshotEnvironment ( ) )
106
- hasSnapshot = true
107
- }
102
+ if ( ! config . snapshotOptions . snapshotEnvironment )
103
+ config . snapshotOptions . snapshotEnvironment = new BrowserSnapshotEnvironment ( )
108
104
109
105
try {
110
106
await setupCommonEnv ( config )
0 commit comments