Skip to content

Commit c73504e

Browse files
authored
fix(workflow-engine-inmemory): Fail trap for integration tests (medusajs#11839)
**What** Jest is patching the event emitter meaning that sometimes it can lead to flacky behaviors and block the test execution if the done callback is never reached. To prevent that from happening, the fail trap will call the done callback after a given time and warn that the test could not be concluded because of jest blocking it
1 parent 5e892e2 commit c73504e

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

packages/modules/workflow-engine-inmemory/integration-tests/__tests__/index.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,21 @@ import {
2828
workflowEventGroupIdStep1Mock,
2929
workflowEventGroupIdStep2Mock,
3030
} from "../__fixtures__/workflow_event_group_id"
31+
import { setTimeout as setTimeoutSync } from "timers"
3132
import { createScheduled } from "../__fixtures__/workflow_scheduled"
3233

3334
jest.setTimeout(3000000)
3435

36+
const failTrap = (done) => {
37+
setTimeoutSync(() => {
38+
// REF:https://stackoverflow.com/questions/78028715/jest-async-test-with-event-emitter-isnt-ending
39+
console.warn(
40+
"Jest is breaking the event emit with its debouncer. This allows to continue the test by managing the timeout of the test manually."
41+
)
42+
done()
43+
}, 5000)
44+
}
45+
3546
moduleIntegrationTestRunner<IWorkflowEngineService>({
3647
moduleName: Modules.WORKFLOW_ENGINE,
3748
resolve: __dirname + "/../..",
@@ -307,6 +318,8 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
307318
},
308319
throwOnError: true,
309320
})
321+
322+
failTrap(done)
310323
})
311324

312325
it("should not run conditional steps if condition is false", (done) => {
@@ -327,6 +340,8 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
327340
},
328341
throwOnError: true,
329342
})
343+
344+
failTrap(done)
330345
})
331346
})
332347

packages/modules/workflow-engine-inmemory/integration-tests/__tests__/race.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ import "../__fixtures__"
1414

1515
jest.setTimeout(3000000)
1616

17+
const failTrap = (done) => {
18+
setTimeoutSync(() => {
19+
// REF:https://stackoverflow.com/questions/78028715/jest-async-test-with-event-emitter-isnt-ending
20+
console.warn(
21+
"Jest is breaking the event emit with its debouncer. This allows to continue the test by managing the timeout of the test manually."
22+
)
23+
done()
24+
}, 5000)
25+
}
26+
1727
moduleIntegrationTestRunner<IWorkflowEngineService>({
1828
moduleName: Modules.WORKFLOW_ENGINE,
1929
resolve: __dirname + "/../..",
@@ -87,6 +97,8 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
8797
expect(result).toBe("result from step 0")
8898
})
8999
.catch((e) => e)
100+
101+
failTrap(done)
90102
})
91103

92104
it("should prevent race continuation of the workflow compensation during retryIntervalAwaiting in background execution", (done) => {
@@ -176,6 +188,8 @@ moduleIntegrationTestRunner<IWorkflowEngineService>({
176188
expect(result).toBe("result from step 0")
177189
})
178190
.catch((e) => e)
191+
192+
failTrap(done)
179193
})
180194
})
181195
},

0 commit comments

Comments
 (0)