Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Jun 22, 2023
1 parent abfdf40 commit bc615a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/vitest/src/integrations/env/jsdom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default <Environment>({
resources: resources ?? (userAgent ? new ResourceLoader({ userAgent }) : undefined),
runScripts,
url,
virtualConsole: (console && global.console) ? new VirtualConsole().sendTo(global.console) : undefined,
virtualConsole: (console && globalThis.console) ? new VirtualConsole().sendTo(globalThis.console) : undefined,
cookieJar: cookieJar ? new CookieJar() : undefined,
includeNodeLocations,
contentType,
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/child.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export async function run(ctx: ChildContext) {

try {
const state = init(ctx)
const { run, executor } = await startViteNode(ctx, {
const { run, executor } = await startViteNode({
state,
})
await run(ctx.files, ctx.config, ctx.environment, executor)
Expand Down
29 changes: 13 additions & 16 deletions packages/vitest/src/runtime/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ViteNodeRunnerOptions } from 'vite-node'
import { normalize, relative, resolve } from 'pathe'
import { processError } from '@vitest/utils/error'
import type { MockMap } from '../types/mocker'
import type { ContextRPC, ContextTestEnvironment, ResolvedConfig, WorkerGlobalState } from '../types'
import type { ContextTestEnvironment, ResolvedConfig, WorkerGlobalState } from '../types'
import { distDir } from '../paths'
import { getWorkerState } from '../utils/global'
import { VitestMocker } from './mocker'
Expand Down Expand Up @@ -38,11 +38,11 @@ let _viteNode: {
export const moduleCache = new ModuleCacheMap()
export const mockMap: MockMap = new Map()

export async function startViteNode(ctx: ContextRPC, options: ContextExecutorOptions) {
export async function startViteNode(options: ContextExecutorOptions) {
if (_viteNode)
return _viteNode

const executor = await startVitestExecutor(ctx, options)
const executor = await startVitestExecutor(options)

const { run } = await import(entryPath)

Expand All @@ -58,10 +58,9 @@ export interface ContextExecutorOptions {
state: WorkerGlobalState
}

export async function startVitestExecutor(ctx: ContextRPC, options: ContextExecutorOptions) {
const { config } = ctx

const rpc = () => getWorkerState()?.rpc || options.state.rpc
export async function startVitestExecutor(options: ContextExecutorOptions) {
const state = () => getWorkerState() || options.state
const rpc = () => state().rpc

const processExit = process.exit

Expand All @@ -77,7 +76,7 @@ export async function startVitestExecutor(ctx: ContextRPC, options: ContextExecu
if (!isPrimitive(error)) {
error.VITEST_TEST_NAME = worker.current?.name
if (worker.filepath)
error.VITEST_TEST_PATH = relative(config.root, worker.filepath)
error.VITEST_TEST_PATH = relative(state().config.root, worker.filepath)
error.VITEST_AFTER_ENV_TEARDOWN = worker.environmentTeardownRun
}
rpc().onUnhandledError(error, type)
Expand All @@ -88,19 +87,17 @@ export async function startVitestExecutor(ctx: ContextRPC, options: ContextExecu

return await createVitestExecutor({
fetchModule(id) {
const state = getWorkerState()
return rpc().fetch(id, state.environment)
return rpc().fetch(id, state().environment)
},
resolveId(id, importer) {
const state = getWorkerState()
return rpc().resolveId(id, importer, state.environment)
return rpc().resolveId(id, importer, state().environment)
},
moduleCache,
mockMap,
get interopDefault() { return config.deps.interopDefault },
get moduleDirectories() { return config.deps.moduleDirectories },
get root() { return config.root },
get base() { return config.base },
get interopDefault() { return state().config.deps.interopDefault },
get moduleDirectories() { return state().config.deps.moduleDirectories },
get root() { return state().config.root },
get base() { return state().config.base },
...options,
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function run(ctx: WorkerContext) {

try {
const state = init(ctx)
const { run, executor } = await startViteNode(ctx, { state })
const { run, executor } = await startViteNode({ state })
await run(ctx.files, ctx.config, ctx.environment, executor)
await rpcDone()
}
Expand Down

0 comments on commit bc615a9

Please sign in to comment.