Skip to content

Commit 3d825da

Browse files
authored
fix: make console.logs not hang vitest-pool-workers when using workflows (#8832)
This goes way beyond me, but I noticed that I didn't use `patchAndRunWithHandlerContext` in `createWorkflowEntrypointWrapper` but other entrypoints did it - that seems to fix it. However, I'm not really sure how does `ExecutionContext` relate to our custom `Console` mock. Probably the test runner uses `waitUntil` to write into the vitest's stdout?
1 parent 930ebb2 commit 3d825da

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

.changeset/eleven-papayas-take.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@cloudflare/vitest-pool-workers": patch
3+
---
4+
5+
Make vitest-pool-workers not hang when console.\* is used in a Workflow

fixtures/vitest-pool-workers-examples/workflows/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77

88
export class TestWorkflow extends WorkflowEntrypoint<Env> {
99
async run(_event: Readonly<WorkflowEvent<unknown>>, step: WorkflowStep) {
10+
console.log("ola");
1011
return "test-workflow";
1112
}
1213
}

packages/vitest-pool-workers/src/worker/entrypoints.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,9 @@ export function createWorkflowEntrypointWrapper(entrypoint: string) {
543543
}
544544
const maybeFn = instance["run"];
545545
if (typeof maybeFn === "function") {
546-
return maybeFn.call(instance, ...args);
546+
return patchAndRunWithHandlerContext(this.ctx, () =>
547+
maybeFn.call(instance, ...args)
548+
);
547549
} else {
548550
const message = `Expected ${entrypoint} export of ${mainPath} to define a \`run()\` method, but got ${typeof maybeFn}`;
549551
throw new TypeError(message);

0 commit comments

Comments
 (0)