From e9ecbb07da216210c59a1e499816f31c025fe81d Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Wed, 6 Mar 2024 13:40:08 +0700 Subject: [PATCH] fix(scenario): Make sure to cleanup even if test fails (#10112) --- CHANGELOG.md | 3 +++ packages/testing/config/jest/api/jest.setup.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94df6dbedd01..3d331541789a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- fix(scenario): Make sure to clean up scenarios even if tests fail (#10112) + Fixes an issue where a unit test failure would cause the scenario cleanup to be skipped. Thanks @peraltafederico and @cjreimer for highlighting this! + - fix(serve): Allow periods in most paths (#10114) Partial fix for route paths with periods in them. diff --git a/packages/testing/config/jest/api/jest.setup.js b/packages/testing/config/jest/api/jest.setup.js index b962ff9ea476..2c6fba2a1ae0 100644 --- a/packages/testing/config/jest/api/jest.setup.js +++ b/packages/testing/config/jest/api/jest.setup.js @@ -104,13 +104,16 @@ const buildScenario = let { scenario } = loadScenarios(testPath, scenarioName) const scenarioData = await seedScenario(scenario) - const result = await testFunc(scenarioData) + try { + const result = await testFunc(scenarioData) - if (wasDbUsed()) { - await teardown() + return result + } finally { + // Make sure to cleanup, even if test fails + if (wasDbUsed()) { + await teardown() + } } - - return result }) }