Skip to content

Commit 74bd2c7

Browse files
committed
override afterEach
1 parent 1e932bd commit 74bd2c7

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

packages/medusa-test-utils/src/medusa-test-runner.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,29 @@ class MedusaTestRunner {
9595
}
9696

9797
this.setupProcessHandlers()
98+
99+
/**
100+
* Override the afterEach hook to wait for workflow executions to finish.
101+
* This is necessary to ensure that the test are not considered done while
102+
* background workflow executions might still be running and can interfere with
103+
* the other tests.
104+
*/
105+
// @ts-ignore
106+
if (!global.afterEach.medusaTestRunnerAfterEachOverridden) {
107+
const originalAfterEach = global.afterEach
108+
global.afterEach = (fn, timeout) => {
109+
originalAfterEach(async (...args: any[]) => {
110+
await waitWorkflowExecutions(this.globalContainer as MedusaContainer)
111+
// @ts-ignore
112+
return fn(...args)
113+
}, timeout)
114+
}
115+
Object.defineProperty(global, "medusaTestRunnerAfterEachOverridden", {
116+
value: true,
117+
configurable: true,
118+
enumerable: false,
119+
})
120+
}
98121
}
99122

100123
private setupProcessHandlers(): void {
@@ -272,7 +295,6 @@ class MedusaTestRunner {
272295

273296
public async afterEach(): Promise<void> {
274297
try {
275-
await waitWorkflowExecutions(this.globalContainer as MedusaContainer)
276298
await this.dbUtils.teardown({ schema: this.schema })
277299
} catch (error) {
278300
logger.error("Error tearing down database:", error?.message)

0 commit comments

Comments
 (0)