Skip to content

Commit e49c13f

Browse files
authored
perf: don't import vite in worker (#2759)
1 parent 3679cf2 commit e49c13f

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

packages/vitest/src/runtime/execute.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { ViteNodeRunner } from 'vite-node/client'
22
import { isInternalRequest } from 'vite-node/utils'
33
import type { ViteNodeRunnerOptions } from 'vite-node'
4-
import { normalizePath } from 'vite'
4+
import { normalize } from 'pathe'
55
import { isNodeBuiltin } from 'mlly'
66
import type { MockMap } from '../types/mocker'
7-
import { getCurrentEnvironment, getWorkerState } from '../utils'
7+
import { getCurrentEnvironment, getWorkerState } from '../utils/global'
88
import { VitestMocker } from './mocker'
99

1010
export interface ExecuteOptions extends ViteNodeRunnerOptions {
@@ -68,7 +68,7 @@ export class VitestRunner extends ViteNodeRunner {
6868
const workerState = getWorkerState()
6969

7070
// support `import.meta.vitest` for test entry
71-
if (workerState.filepath && normalizePath(workerState.filepath) === normalizePath(context.__filename)) {
71+
if (workerState.filepath && normalize(workerState.filepath) === normalize(context.__filename)) {
7272
// @ts-expect-error injected untyped global
7373
Object.defineProperty(context.__vite_ssr_import_meta__, 'vitest', { get: () => globalThis.__vitest_index__ })
7474
}

packages/vitest/src/runtime/mocker.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { existsSync, readdirSync } from 'node:fs'
22
import { isNodeBuiltin } from 'mlly'
33
import { basename, dirname, extname, isAbsolute, join, resolve } from 'pathe'
4-
import { getColors } from '@vitest/utils'
5-
import { getAllMockableProperties, getType, getWorkerState } from '../utils'
4+
import { getColors, getType } from '@vitest/utils'
5+
import { getWorkerState } from '../utils/global'
6+
import { getAllMockableProperties } from '../utils/base'
67
import { distDir } from '../constants'
78
import type { MockFactory, PendingSuiteMock } from '../types/mocker'
89
import type { VitestRunner } from './execute'

packages/vitest/src/runtime/worker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ModuleCacheMap } from 'vite-node/client'
66
import { isPrimitive } from 'vite-node/utils'
77
import type { ResolvedConfig, WorkerContext, WorkerRPC } from '../types'
88
import { distDir } from '../constants'
9-
import { getWorkerState } from '../utils'
9+
import { getWorkerState } from '../utils/global'
1010
import type { MockMap } from '../types/mocker'
1111
import { executeInViteNode } from './execute'
1212
import { rpc } from './rpc'

0 commit comments

Comments
 (0)