diff --git a/packages/vitest/src/index.ts b/packages/vitest/src/index.ts index c468a3a2f..e0c255428 100644 --- a/packages/vitest/src/index.ts +++ b/packages/vitest/src/index.ts @@ -9,7 +9,7 @@ export * from './types' export * from './runtime/hooks' export * from './integrations/chai' export * from './integrations/jest-mock' -export * from './integrations/utils' +export * from './integrations/vi' declare module 'vite' { interface UserConfig { diff --git a/packages/vitest/src/integrations/utils.ts b/packages/vitest/src/integrations/vi.ts similarity index 100% rename from packages/vitest/src/integrations/utils.ts rename to packages/vitest/src/integrations/vi.ts diff --git a/packages/vitest/src/runtime/entry.ts b/packages/vitest/src/runtime/entry.ts index 770c2fc67..ad7ec9eec 100644 --- a/packages/vitest/src/runtime/entry.ts +++ b/packages/vitest/src/runtime/entry.ts @@ -1,6 +1,6 @@ import { promises as fs } from 'fs' import type { BuiltinEnvironment, ResolvedConfig } from '../types' -import { vi } from '../integrations/utils' +import { vi } from '../integrations/vi' import { setupGlobalEnv, withEnv } from './setup' import { startTests } from './run' diff --git a/packages/vitest/src/runtime/run.ts b/packages/vitest/src/runtime/run.ts index ccf46a066..541836d9f 100644 --- a/packages/vitest/src/runtime/run.ts +++ b/packages/vitest/src/runtime/run.ts @@ -1,8 +1,9 @@ import { performance } from 'perf_hooks' import type { HookListener } from 'vitest' +import { vi } from '../integrations/vi' import type { ResolvedConfig, Suite, SuiteHooks, Task, Test } from '../types' import { getSnapshotClient } from '../integrations/snapshot/chai' -import { clearModuleMocks, hasFailed, hasTests, partitionSuiteChildren } from '../utils' +import { hasFailed, hasTests, partitionSuiteChildren } from '../utils' import { getFn, getHooks } from './map' import { rpc, send } from './rpc' import { collectTests } from './collect' @@ -154,3 +155,15 @@ export async function startTests(paths: string[], config: ResolvedConfig) { await getSnapshotClient().saveSnap() } + +export function clearModuleMocks() { + const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config + + // since each function calls another, we can just call one + if (restoreMocks) + vi.restoreAllMocks() + else if (mockReset) + vi.resetAllMocks() + else if (clearMocks) + vi.clearAllMocks() +} diff --git a/packages/vitest/src/utils.ts b/packages/vitest/src/utils.ts index fadae908b..9d98e48d4 100644 --- a/packages/vitest/src/utils.ts +++ b/packages/vitest/src/utils.ts @@ -1,7 +1,6 @@ import c from 'picocolors' import { isPackageExists } from 'local-pkg' import { resolve } from 'pathe' -import { vi } from './integrations/utils' import type { Arrayable, Nullable, Suite, Task, Test } from './types' /** @@ -134,16 +133,4 @@ export async function ensurePackageInstalled( return false } -export function clearModuleMocks() { - const { clearMocks, mockReset, restoreMocks } = process.__vitest_worker__.config - - // since each function calls another, we can just call one - if (restoreMocks) - vi.restoreAllMocks() - else if (mockReset) - vi.resetAllMocks() - else if (clearMocks) - vi.clearAllMocks() -} - export { resolve as resolvePath }