Skip to content

Commit

Permalink
fix(mock): reset mock state before each run
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Mar 17, 2022
1 parent 8a96eaf commit 0e9b92d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/vitest/src/runtime/entry.ts
Expand Up @@ -7,6 +7,11 @@ import { startTests } from './run'
export async function run(files: string[], config: ResolvedConfig): Promise<void> {
await setupGlobalEnv(config)

const workerState = getWorkerState()

// reset mock state
workerState.mockMap.clear()

for (const file of files) {
const code = await fs.readFile(file, 'utf-8')

Expand All @@ -15,7 +20,6 @@ export async function run(files: string[], config: ResolvedConfig): Promise<void
if (!['node', 'jsdom', 'happy-dom'].includes(env))
throw new Error(`Unsupported environment: ${env}`)

const workerState = getWorkerState()
workerState.filepath = file

await withEnv(env as BuiltinEnvironment, config.environmentOptions || {}, async() => {
Expand Down

0 comments on commit 0e9b92d

Please sign in to comment.