Skip to content

Commit

Permalink
perf: don't import vite in worker (#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jan 27, 2023
1 parent 3679cf2 commit e49c13f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/vitest/src/runtime/execute.ts
@@ -1,10 +1,10 @@
import { ViteNodeRunner } from 'vite-node/client'
import { isInternalRequest } from 'vite-node/utils'
import type { ViteNodeRunnerOptions } from 'vite-node'
import { normalizePath } from 'vite'
import { normalize } from 'pathe'
import { isNodeBuiltin } from 'mlly'
import type { MockMap } from '../types/mocker'
import { getCurrentEnvironment, getWorkerState } from '../utils'
import { getCurrentEnvironment, getWorkerState } from '../utils/global'
import { VitestMocker } from './mocker'

export interface ExecuteOptions extends ViteNodeRunnerOptions {
Expand Down Expand Up @@ -68,7 +68,7 @@ export class VitestRunner extends ViteNodeRunner {
const workerState = getWorkerState()

// support `import.meta.vitest` for test entry
if (workerState.filepath && normalizePath(workerState.filepath) === normalizePath(context.__filename)) {
if (workerState.filepath && normalize(workerState.filepath) === normalize(context.__filename)) {
// @ts-expect-error injected untyped global
Object.defineProperty(context.__vite_ssr_import_meta__, 'vitest', { get: () => globalThis.__vitest_index__ })
}
Expand Down
5 changes: 3 additions & 2 deletions packages/vitest/src/runtime/mocker.ts
@@ -1,8 +1,9 @@
import { existsSync, readdirSync } from 'node:fs'
import { isNodeBuiltin } from 'mlly'
import { basename, dirname, extname, isAbsolute, join, resolve } from 'pathe'
import { getColors } from '@vitest/utils'
import { getAllMockableProperties, getType, getWorkerState } from '../utils'
import { getColors, getType } from '@vitest/utils'
import { getWorkerState } from '../utils/global'
import { getAllMockableProperties } from '../utils/base'
import { distDir } from '../constants'
import type { MockFactory, PendingSuiteMock } from '../types/mocker'
import type { VitestRunner } from './execute'
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/worker.ts
Expand Up @@ -6,7 +6,7 @@ import { ModuleCacheMap } from 'vite-node/client'
import { isPrimitive } from 'vite-node/utils'
import type { ResolvedConfig, WorkerContext, WorkerRPC } from '../types'
import { distDir } from '../constants'
import { getWorkerState } from '../utils'
import { getWorkerState } from '../utils/global'
import type { MockMap } from '../types/mocker'
import { executeInViteNode } from './execute'
import { rpc } from './rpc'
Expand Down

0 comments on commit e49c13f

Please sign in to comment.