From f714833511bf1d895361b4b118303fc8420d1228 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sat, 9 Jul 2022 01:14:58 +0800 Subject: [PATCH] fix(reporter): clear previous state on rerun --- packages/vitest/src/node/core.ts | 2 ++ packages/vitest/src/node/pool.ts | 1 + packages/vitest/src/node/state.ts | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 21583b7506d2..fdf209b35fbf 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -227,8 +227,10 @@ export class Vitest { } async runFiles(paths: string[]) { + // previous run await this.runningPromise + // schedule the new run this.runningPromise = (async () => { if (!this.pool) this.pool = createPool(this) diff --git a/packages/vitest/src/node/pool.ts b/packages/vitest/src/node/pool.ts index cd26ebb8cd96..b23c67bb9bd9 100644 --- a/packages/vitest/src/node/pool.ts +++ b/packages/vitest/src/node/pool.ts @@ -67,6 +67,7 @@ export function createPool(ctx: Vitest): WorkerPool { let id = 0 async function runFiles(config: ResolvedConfig, files: string[], invalidates: string[] = []) { + ctx.state.clearFiles(files) const { workerPort, port } = createChannel(ctx) const workerId = ++id const data: WorkerContext = { diff --git a/packages/vitest/src/node/state.ts b/packages/vitest/src/node/state.ts index 029f5eb20e6c..72392ecd9c99 100644 --- a/packages/vitest/src/node/state.ts +++ b/packages/vitest/src/node/state.ts @@ -54,6 +54,12 @@ export class StateManager { }) } + clearFiles(paths: string[] = []) { + paths.forEach((path) => { + this.filesMap.delete(path) + }) + } + updateId(task: Task) { if (this.idMap.get(task.id) === task) return