From 70d855bd1be0ab654ff319d3780469e0c8a0fe36 Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Tue, 30 Sep 2025 17:06:05 +0200 Subject: [PATCH] fix(): Module test runner lifecycle does not shutdown properly (#13628) * fix(): Module test runner lifecycle does not shutdown properly * Create late-feet-think.md --- .changeset/late-feet-think.md | 5 +++++ packages/medusa-test-utils/src/init-modules.ts | 15 ++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .changeset/late-feet-think.md diff --git a/.changeset/late-feet-think.md b/.changeset/late-feet-think.md new file mode 100644 index 0000000000..9f40a56986 --- /dev/null +++ b/.changeset/late-feet-think.md @@ -0,0 +1,5 @@ +--- +"@medusajs/test-utils": patch +--- + +fix(): Module test runner lifecycle does not shutdown properly diff --git a/packages/medusa-test-utils/src/init-modules.ts b/packages/medusa-test-utils/src/init-modules.ts index fc0beb6784..70951c1f7a 100644 --- a/packages/medusa-test-utils/src/init-modules.ts +++ b/packages/medusa-test-utils/src/init-modules.ts @@ -63,14 +63,13 @@ export async function initModules({ await medusaApp.onApplicationStart() async function shutdown() { - if (shouldDestroyConnectionAutomatically) { - await medusaApp.onApplicationPrepareShutdown() + const promises: Promise[] = [] + promises.push(medusaApp.onApplicationPrepareShutdown()) + promises.push(medusaApp.onApplicationShutdown()) - await promiseAll([ - (sharedPgConnection as any).context?.destroy(), - (sharedPgConnection as any).destroy(), - medusaApp.onApplicationShutdown(), - ]) + if (shouldDestroyConnectionAutomatically) { + promises.push((sharedPgConnection as any).context?.destroy()) + promises.push((sharedPgConnection as any).destroy()) } else { if (!preventConnectionDestroyWarning) { logger.info( @@ -78,6 +77,8 @@ export async function initModules({ ) } } + + await promiseAll(promises) moduleSdkImports.MedusaModule.clearInstances() }