Skip to content

Commit 004efb4

Browse files
fix(workflows-shared): fix always-truthy .filter() in vi.waitUntil calls
Two waitForEvent tests used .filter() (returns Array, always truthy) inside vi.waitUntil callbacks instead of .some() (returns boolean). This made the waits resolve immediately on the first poll without actually checking whether the expected events had been logged. - Replace .filter() with .some() so vi.waitUntil actually polls - Use === instead of == for strict equality - Add { expect } from test context and real assertions verifying WAIT_START and WORKFLOW_SUCCESS events are present in the logs - Remove the eslint-disable jest/expect-expect comments since the tests now contain proper assertions
1 parent 12519ed commit 004efb4

1 file changed

Lines changed: 26 additions & 10 deletions

File tree

packages/workflows-shared/tests/engine.test.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ describe("Engine", () => {
104104
).toHaveLength(1);
105105
});
106106

107-
// eslint-disable-next-line jest/expect-expect
108-
it("waitForEvent should receive events while active", async () => {
107+
it("waitForEvent should receive events while active", async ({ expect }) => {
109108
const engineStub = await runWorkflow(
110109
"MOCK-INSTANCE-ID-WAIT-FOR-EVENT",
111110
async (_, step) => {
@@ -119,7 +118,7 @@ describe("Engine", () => {
119118
await vi.waitUntil(
120119
async () => {
121120
const logs = (await engineStub.readLogs()) as EngineLogs;
122-
return logs.logs.filter((val) => val.event == InstanceEvent.WAIT_START);
121+
return logs.logs.some((val) => val.event === InstanceEvent.WAIT_START);
123122
},
124123
{ timeout: 5000 }
125124
);
@@ -133,16 +132,25 @@ describe("Engine", () => {
133132
await vi.waitUntil(
134133
async () => {
135134
const logs = (await engineStub.readLogs()) as EngineLogs;
136-
return logs.logs.filter(
137-
(val) => val.event == InstanceEvent.WORKFLOW_SUCCESS
135+
return logs.logs.some(
136+
(val) => val.event === InstanceEvent.WORKFLOW_SUCCESS
138137
);
139138
},
140139
{ timeout: 5000 }
141140
);
141+
142+
const logs = (await engineStub.readLogs()) as EngineLogs;
143+
expect(logs.logs.some((v) => v.event === InstanceEvent.WAIT_START)).toBe(
144+
true
145+
);
146+
expect(
147+
logs.logs.some((v) => v.event === InstanceEvent.WORKFLOW_SUCCESS)
148+
).toBe(true);
142149
});
143150

144-
// eslint-disable-next-line jest/expect-expect
145-
it("waitForEvent should receive events even if not active", async () => {
151+
it("waitForEvent should receive events even if not active", async ({
152+
expect,
153+
}) => {
146154
const engineStub = await runWorkflow(
147155
"MOCK-INSTANCE-ID-WAIT-FOR-EVENT-NOT-ACTIVE",
148156
async (_, step) => {
@@ -156,7 +164,7 @@ describe("Engine", () => {
156164
await vi.waitUntil(
157165
async () => {
158166
const logs = (await engineStub.readLogs()) as EngineLogs;
159-
return logs.logs.filter((val) => val.event == InstanceEvent.WAIT_START);
167+
return logs.logs.some((val) => val.event === InstanceEvent.WAIT_START);
160168
},
161169
{ timeout: 5000 }
162170
);
@@ -183,12 +191,20 @@ describe("Engine", () => {
183191
await vi.waitUntil(
184192
async () => {
185193
const logs = (await newStub.readLogs()) as EngineLogs;
186-
return logs.logs.filter(
187-
(val) => val.event == InstanceEvent.WORKFLOW_SUCCESS
194+
return logs.logs.some(
195+
(val) => val.event === InstanceEvent.WORKFLOW_SUCCESS
188196
);
189197
},
190198
{ timeout: 5000 }
191199
);
200+
201+
const logs = (await newStub.readLogs()) as EngineLogs;
202+
expect(logs.logs.some((v) => v.event === InstanceEvent.WAIT_START)).toBe(
203+
true
204+
);
205+
expect(
206+
logs.logs.some((v) => v.event === InstanceEvent.WORKFLOW_SUCCESS)
207+
).toBe(true);
192208
});
193209

194210
it("waitForEvent should not deliver events to timed-out events with the same type", async ({

0 commit comments

Comments
 (0)