File tree Expand file tree Collapse file tree
packages/medusa-test-utils/src Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments