@internal
(options: UserConfig, server: ViteDevServer)
| 205 | |
| 206 | /** @internal */ |
| 207 | async _setServer(options: UserConfig, server: ViteDevServer) { |
| 208 | this.watcher.unregisterWatcher() |
| 209 | clearTimeout(this._rerunTimer) |
| 210 | this.restartsCount += 1 |
| 211 | this.pool?.close?.() |
| 212 | this.pool = undefined |
| 213 | this.closingPromise = undefined |
| 214 | this.projects = [] |
| 215 | this.runningPromise = undefined |
| 216 | this.coreWorkspaceProject = undefined |
| 217 | this.specifications.clearCache() |
| 218 | this._coverageProvider = undefined |
| 219 | this._onUserTestsRerun = [] |
| 220 | |
| 221 | this._vite = server |
| 222 | |
| 223 | const resolved = resolveConfig(this, options, server.config) |
| 224 | |
| 225 | this._config = resolved |
| 226 | this._state = new StateManager({ |
| 227 | onUnhandledError: resolved.onUnhandledError, |
| 228 | }) |
| 229 | this._cache = new VitestCache(this.logger) |
| 230 | this._snapshot = new SnapshotManager({ ...resolved.snapshotOptions }) |
| 231 | this._testRun = new TestRun(this) |
| 232 | const otelSdkPath = resolved.experimental.openTelemetry?.sdkPath |
| 233 | this._traces = new Traces({ |
| 234 | enabled: !!resolved.experimental.openTelemetry?.enabled, |
| 235 | sdkPath: otelSdkPath, |
| 236 | watchMode: resolved.watch, |
| 237 | }) |
| 238 | |
| 239 | if (this.config.watch) { |
| 240 | this.watcher.registerWatcher() |
| 241 | } |
| 242 | |
| 243 | this._resolver = new VitestResolver(server.config.cacheDir, resolved) |
| 244 | this._fsCache = new FileSystemModuleCache(this) |
| 245 | this._fetcher = createFetchModuleFunction( |
| 246 | this._resolver, |
| 247 | this._config, |
| 248 | this._fsCache, |
| 249 | this._traces, |
| 250 | this._tmpDir, |
| 251 | ) |
| 252 | const environment = server.environments.__vitest__ |
| 253 | this.runner = resolved.experimental.viteModuleRunner === false |
| 254 | ? new NativeModuleRunner(resolved.root) |
| 255 | : new ServerModuleRunner( |
| 256 | environment, |
| 257 | this._fetcher, |
| 258 | resolved, |
| 259 | ) |
| 260 | // patch default ssr runnable environment so third-party usage of `runner.import` |
| 261 | // still works with Vite's external/noExternal configuration. |
| 262 | const ssrEnvironment = server.environments.ssr |
| 263 | if (isRunnableDevEnvironment(ssrEnvironment)) { |
| 264 | const ssrRunner = new ServerModuleRunner( |
no test coverage detected