diff --git a/packages/vitest/src/node/pools/browser.ts b/packages/vitest/src/node/pools/browser.ts index e26fe75b3f7b..fdbaa08f8af4 100644 --- a/packages/vitest/src/node/pools/browser.ts +++ b/packages/vitest/src/node/pools/browser.ts @@ -44,7 +44,7 @@ export function createBrowserPool(ctx: Vitest): ProcessPool { if (project.config.browser.isolate) { for (const path of paths) { if (isCancelled) { - ctx.state.cancelFiles(files.slice(paths.indexOf(path)), ctx.config.root, project.getName()) + ctx.state.cancelFiles(files.slice(paths.indexOf(path)), ctx.config.root, project.config.name) break } diff --git a/packages/vitest/src/node/pools/child.ts b/packages/vitest/src/node/pools/child.ts index 513d3ad7a309..6392744c6aed 100644 --- a/packages/vitest/src/node/pools/child.ts +++ b/packages/vitest/src/node/pools/child.ts @@ -118,7 +118,7 @@ export function createChildProcessPool(ctx: Vitest, { execArgv, env, forksPath } // Intentionally cancelled else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message)) - ctx.state.cancelFiles(files, ctx.config.root, project.getName()) + ctx.state.cancelFiles(files, ctx.config.root, project.config.name) else throw error diff --git a/packages/vitest/src/node/pools/threads.ts b/packages/vitest/src/node/pools/threads.ts index c426cc6074c1..3dfa6402baa0 100644 --- a/packages/vitest/src/node/pools/threads.ts +++ b/packages/vitest/src/node/pools/threads.ts @@ -106,7 +106,7 @@ export function createThreadsPool(ctx: Vitest, { execArgv, env, workerPath }: Po // Intentionally cancelled else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message)) - ctx.state.cancelFiles(files, ctx.config.root, project.getName()) + ctx.state.cancelFiles(files, ctx.config.root, project.config.name) else throw error diff --git a/packages/vitest/src/node/pools/vm-threads.ts b/packages/vitest/src/node/pools/vm-threads.ts index 9b1c4f2f22c9..b48fc60ad957 100644 --- a/packages/vitest/src/node/pools/vm-threads.ts +++ b/packages/vitest/src/node/pools/vm-threads.ts @@ -111,7 +111,7 @@ export function createVmThreadsPool(ctx: Vitest, { execArgv, env, vmPath }: Pool // Intentionally cancelled else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message)) - ctx.state.cancelFiles(files, ctx.config.root, project.getName()) + ctx.state.cancelFiles(files, ctx.config.root, project.config.name) else throw error @@ -123,6 +123,9 @@ export function createVmThreadsPool(ctx: Vitest, { execArgv, env, vmPath }: Pool } return async (specs, invalidates) => { + // Cancel pending tasks from pool when possible + ctx.onCancel(() => pool.cancelPendingTasks()) + const configs = new Map() const getConfig = (project: WorkspaceProject): ResolvedConfig => { if (configs.has(project))