Files
n8n/packages/cli/test/setup-testcontainers.js
alighasami 3d5eaf9445
Some checks failed
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
first commit
2026-03-17 16:22:57 +03:30

38 lines
1.3 KiB
JavaScript

/**
* Jest global setup - plain JS to bypass Jest's transform system.
* Uses createServiceStack from n8n-containers for unified service management.
*/
const { createServiceStack } = require('n8n-containers');
const { randomBytes } = require('crypto');
module.exports = async () => {
const suffix = randomBytes(4).toString('hex');
const stack = await createServiceStack({
services: ['postgres'],
projectName: `n8n-integration-test-${suffix}`,
});
const pgResult = stack.serviceResults.postgres;
if (!pgResult) {
throw new Error('Failed to start postgres container');
}
const container = pgResult.container;
process.env.DB_TYPE = 'postgresdb';
process.env.DB_POSTGRESDB_HOST = container.getHost();
process.env.DB_POSTGRESDB_PORT = String(container.getMappedPort(5432));
process.env.DB_POSTGRESDB_DATABASE = pgResult.meta.database;
process.env.DB_POSTGRESDB_USER = pgResult.meta.username;
process.env.DB_POSTGRESDB_PASSWORD = pgResult.meta.password;
process.env.DB_POSTGRESDB_SCHEMA = 'alt_schema';
process.env.DB_TABLE_PREFIX = 'test_';
process.env.DB_POSTGRESDB_POOL_SIZE = '1'; // Detect connection pooling deadlocks
globalThis.__TESTCONTAINERS_STACK__ = stack;
console.log(
`\n✓ Postgres ready at ${process.env.DB_POSTGRESDB_HOST}:${process.env.DB_POSTGRESDB_PORT}\n`,
);
};