Skip to content

Commit cf53d4b

Browse files
authoredDec 28, 2023
fix(vm-threads): tests not cancelled on key press, cancelled tests shown twice (#4781)
1 parent 20570d1 commit cf53d4b

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed
 

‎packages/vitest/src/node/pools/browser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function createBrowserPool(ctx: Vitest): ProcessPool {
4444
if (project.config.browser.isolate) {
4545
for (const path of paths) {
4646
if (isCancelled) {
47-
ctx.state.cancelFiles(files.slice(paths.indexOf(path)), ctx.config.root, project.getName())
47+
ctx.state.cancelFiles(files.slice(paths.indexOf(path)), ctx.config.root, project.config.name)
4848
break
4949
}
5050

‎packages/vitest/src/node/pools/child.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export function createChildProcessPool(ctx: Vitest, { execArgv, env, forksPath }
118118

119119
// Intentionally cancelled
120120
else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message))
121-
ctx.state.cancelFiles(files, ctx.config.root, project.getName())
121+
ctx.state.cancelFiles(files, ctx.config.root, project.config.name)
122122

123123
else
124124
throw error

‎packages/vitest/src/node/pools/threads.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function createThreadsPool(ctx: Vitest, { execArgv, env, workerPath }: Po
106106

107107
// Intentionally cancelled
108108
else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message))
109-
ctx.state.cancelFiles(files, ctx.config.root, project.getName())
109+
ctx.state.cancelFiles(files, ctx.config.root, project.config.name)
110110

111111
else
112112
throw error

‎packages/vitest/src/node/pools/vm-threads.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function createVmThreadsPool(ctx: Vitest, { execArgv, env, vmPath }: Pool
111111

112112
// Intentionally cancelled
113113
else if (ctx.isCancelling && error instanceof Error && /The task has been cancelled/.test(error.message))
114-
ctx.state.cancelFiles(files, ctx.config.root, project.getName())
114+
ctx.state.cancelFiles(files, ctx.config.root, project.config.name)
115115

116116
else
117117
throw error
@@ -123,6 +123,9 @@ export function createVmThreadsPool(ctx: Vitest, { execArgv, env, vmPath }: Pool
123123
}
124124

125125
return async (specs, invalidates) => {
126+
// Cancel pending tasks from pool when possible
127+
ctx.onCancel(() => pool.cancelPendingTasks())
128+
126129
const configs = new Map<WorkspaceProject, ResolvedConfig>()
127130
const getConfig = (project: WorkspaceProject): ResolvedConfig => {
128131
if (configs.has(project))

0 commit comments

Comments
 (0)
Please sign in to comment.