diff --git a/.changeset/beige-wolves-kneel.md b/.changeset/beige-wolves-kneel.md new file mode 100644 index 0000000000..2c768a3f03 --- /dev/null +++ b/.changeset/beige-wolves-kneel.md @@ -0,0 +1,5 @@ +--- +'@backstage/backend-test-utils': patch +--- + +Lazy-load `testcontainers` module in order to avoid side-effects. diff --git a/packages/backend-test-utils/src/database/startMysqlContainer.ts b/packages/backend-test-utils/src/database/startMysqlContainer.ts index 9601854cb3..fa99389cbc 100644 --- a/packages/backend-test-utils/src/database/startMysqlContainer.ts +++ b/packages/backend-test-utils/src/database/startMysqlContainer.ts @@ -15,7 +15,6 @@ */ import createConnection, { Knex } from 'knex'; -import { GenericContainer } from 'testcontainers'; import { v4 as uuid } from 'uuid'; async function waitForMysqlReady( @@ -50,6 +49,9 @@ export async function startMysqlContainer(image: string) { const user = 'root'; const password = uuid(); + // Lazy-load to avoid side-effect of importing testcontainers + const { GenericContainer } = await import('testcontainers'); + const container = await new GenericContainer(image) .withExposedPorts(3306) .withEnv('MYSQL_ROOT_PASSWORD', password) diff --git a/packages/backend-test-utils/src/database/startPostgresContainer.ts b/packages/backend-test-utils/src/database/startPostgresContainer.ts index 89a0417e22..81358e01d3 100644 --- a/packages/backend-test-utils/src/database/startPostgresContainer.ts +++ b/packages/backend-test-utils/src/database/startPostgresContainer.ts @@ -15,7 +15,6 @@ */ import createConnection, { Knex } from 'knex'; -import { GenericContainer } from 'testcontainers'; import { v4 as uuid } from 'uuid'; async function waitForPostgresReady( @@ -50,6 +49,9 @@ export async function startPostgresContainer(image: string) { const user = 'postgres'; const password = uuid(); + // Lazy-load to avoid side-effect of importing testcontainers + const { GenericContainer } = await import('testcontainers'); + const container = await new GenericContainer(image) .withExposedPorts(5432) .withEnv('POSTGRES_PASSWORD', password)