( method: 'run' | 'collect', files: FileSpecification[], config: SerializedConfig, moduleRunner: TestModuleRunner, traces: Traces, )
| 23 | import { getWorkerState } from './utils' |
| 24 | |
| 25 | export async function run( |
| 26 | method: 'run' | 'collect', |
| 27 | files: FileSpecification[], |
| 28 | config: SerializedConfig, |
| 29 | moduleRunner: TestModuleRunner, |
| 30 | traces: Traces, |
| 31 | ): Promise<void> { |
| 32 | const workerState = getWorkerState() |
| 33 | |
| 34 | await traces.$('vitest.runtime.global_env', () => setupCommonEnv(config)) |
| 35 | |
| 36 | Object.defineProperty(globalThis, '__vitest_index__', { |
| 37 | value: VitestIndex, |
| 38 | enumerable: false, |
| 39 | }) |
| 40 | |
| 41 | const viteEnvironment = workerState.environment.viteEnvironment || workerState.environment.name |
| 42 | VitestIndex.expect.setState({ |
| 43 | environment: workerState.environment.name, |
| 44 | }) |
| 45 | if (viteEnvironment === 'client') { |
| 46 | const _require = createRequire(import.meta.url) |
| 47 | // always mock "required" `css` files, because we cannot process them |
| 48 | _require.extensions['.css'] = resolveCss |
| 49 | _require.extensions['.scss'] = resolveCss |
| 50 | _require.extensions['.sass'] = resolveCss |
| 51 | _require.extensions['.less'] = resolveCss |
| 52 | // since we are using Vite, we can assume how these will be resolved |
| 53 | KNOWN_ASSET_TYPES.forEach((type) => { |
| 54 | _require.extensions[`.${type}`] = resolveAsset |
| 55 | }) |
| 56 | process.env.SSR = '' |
| 57 | } |
| 58 | else { |
| 59 | process.env.SSR = '1' |
| 60 | } |
| 61 | |
| 62 | // @ts-expect-error not typed global for patched timers |
| 63 | globalThis.__vitest_required__ = { |
| 64 | util, |
| 65 | timers, |
| 66 | timersPromises, |
| 67 | } |
| 68 | |
| 69 | await traces.$('vitest.runtime.coverage.start', () => startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: false })) |
| 70 | |
| 71 | if (config.chaiConfig) { |
| 72 | setupChaiConfig(config.chaiConfig) |
| 73 | } |
| 74 | |
| 75 | const [testRunner, snapshotEnvironment] = await Promise.all([ |
| 76 | traces.$('vitest.runtime.runner', () => resolveTestRunner(config, moduleRunner, traces)), |
| 77 | traces.$('vitest.runtime.snapshot.environment', () => resolveSnapshotEnvironment(config, moduleRunner)), |
| 78 | ]) |
| 79 | |
| 80 | config.snapshotOptions.snapshotEnvironment = snapshotEnvironment |
| 81 | |
| 82 | workerState.onCancel((reason) => { |
nothing calls this directly
no test coverage detected