MCPcopy
hub / github.com/vitest-dev/vitest / _setServer

Method _setServer

packages/vitest/src/node/core.ts:207–367  ·  view source on GitHub ↗

@internal

(options: UserConfig, server: ViteDevServer)

Source from the content-addressed store, hash-verified

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(

Callers 1

handlerFunction · 0.80

Calls 15

closeMethod · 0.95
reportMethod · 0.95
resolveProjectsMethod · 0.95
resolveConfigFunction · 0.90
loadVCSProviderFunction · 0.90
toArrayFunction · 0.90
populateProjectsTagsFunction · 0.90
createBenchmarkReportersFunction · 0.90
createReportersFunction · 0.90
normalizeFunction · 0.85
registerWatcherMethod · 0.80

Tested by

no test coverage detected