Fixed premature teardown in medusa-test-runner (#13038)
* Fixed premature teardown in medusa-test-runner * modified: packages/medusa-test-utils/src/medusa-test-runner.ts * new file: .changeset/clever-balloons-learn.md modified: packages/medusa-test-utils/src/medusa-test-runner.ts * modified: packages/medusa-test-utils/src/medusa-test-runner.ts * modified: packages/medusa-test-utils/src/medusa-test-runner.ts modified: packages/medusa-test-utils/src/medusa-test-runner.ts modified: packages/medusa-test-utils/src/medusa-test-runner.ts * modified: packages/medusa-test-utils/src/medusa-test-runner.ts * modified: packages/medusa-test-utils/src/medusa-test-runner.ts * Fix optional chaining in afterEach method * added missing implementation of disableAutoTeardown feature in the medusaIntegrationTestRunner method. --------- Co-authored-by: Trevor N. <trevor@pegasuscart.com> Co-authored-by: William Bouchard <46496014+willbouch@users.noreply.github.com> Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
This commit is contained in:
2 files changed
+15
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/test-utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix-medusa-test-runner-premature-teardown
|
||||||
@@ -45,6 +45,7 @@ interface TestRunnerConfig {
|
|||||||
env?: Record<string, any>
|
env?: Record<string, any>
|
||||||
dbName?: string
|
dbName?: string
|
||||||
medusaConfigFile?: string
|
medusaConfigFile?: string
|
||||||
|
disableAutoTeardown?: boolean
|
||||||
schema?: string
|
schema?: string
|
||||||
debug?: boolean
|
debug?: boolean
|
||||||
inApp?: boolean
|
inApp?: boolean
|
||||||
@@ -58,6 +59,7 @@ class MedusaTestRunner {
|
|||||||
private dbName: string
|
private dbName: string
|
||||||
private schema: string
|
private schema: string
|
||||||
private modulesConfigPath: string
|
private modulesConfigPath: string
|
||||||
|
private disableAutoTeardown: boolean
|
||||||
private cwd: string
|
private cwd: string
|
||||||
private env: Record<string, any>
|
private env: Record<string, any>
|
||||||
private debug: boolean
|
private debug: boolean
|
||||||
@@ -92,6 +94,7 @@ class MedusaTestRunner {
|
|||||||
this.env = config.env ?? {}
|
this.env = config.env ?? {}
|
||||||
this.debug = config.debug ?? false
|
this.debug = config.debug ?? false
|
||||||
this.inApp = config.inApp ?? false
|
this.inApp = config.inApp ?? false
|
||||||
|
this.disableAutoTeardown = config?.disableAutoTeardown ?? false
|
||||||
|
|
||||||
this.dbUtils = dbTestUtilFactory()
|
this.dbUtils = dbTestUtilFactory()
|
||||||
this.dbConfig = {
|
this.dbConfig = {
|
||||||
@@ -290,7 +293,11 @@ class MedusaTestRunner {
|
|||||||
public async afterEach(): Promise<void> {
|
public async afterEach(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await waitWorkflowExecutions(this.globalContainer as MedusaContainer)
|
await waitWorkflowExecutions(this.globalContainer as MedusaContainer)
|
||||||
|
|
||||||
|
if (!this.disableAutoTeardown) {
|
||||||
|
// Perform automatic teardown
|
||||||
await this.dbUtils.teardown({ schema: this.schema })
|
await this.dbUtils.teardown({ schema: this.schema })
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error tearing down database:", error?.message)
|
logger.error("Error tearing down database:", error?.message)
|
||||||
throw error
|
throw error
|
||||||
@@ -328,6 +335,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
testSuite,
|
testSuite,
|
||||||
hooks,
|
hooks,
|
||||||
cwd,
|
cwd,
|
||||||
|
disableAutoTeardown,
|
||||||
}: {
|
}: {
|
||||||
moduleName?: string
|
moduleName?: string
|
||||||
env?: Record<string, any>
|
env?: Record<string, any>
|
||||||
@@ -339,6 +347,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
testSuite: (options: MedusaSuiteOptions) => void
|
testSuite: (options: MedusaSuiteOptions) => void
|
||||||
hooks?: TestRunnerConfig["hooks"]
|
hooks?: TestRunnerConfig["hooks"]
|
||||||
cwd?: string
|
cwd?: string
|
||||||
|
disableAutoTeardown?: boolean
|
||||||
}) {
|
}) {
|
||||||
const runner = new MedusaTestRunner({
|
const runner = new MedusaTestRunner({
|
||||||
moduleName,
|
moduleName,
|
||||||
@@ -350,6 +359,7 @@ export function medusaIntegrationTestRunner({
|
|||||||
inApp,
|
inApp,
|
||||||
hooks,
|
hooks,
|
||||||
cwd,
|
cwd,
|
||||||
|
disableAutoTeardown,
|
||||||
})
|
})
|
||||||
|
|
||||||
return describe("", () => {
|
return describe("", () => {
|
||||||
|
|||||||
Reference in new issue
Block a user