diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ce2e44a..c7555f7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,6 +22,7 @@ on: - "github-action/action.yml" - "src/**" - "tests/**" + - "e2e/**" - "package.json" - "pnpm-lock.yaml" - "tsconfig.json" diff --git a/e2e/cli.test.ts b/e2e/cli.test.ts index d348c07..e321b3d 100644 --- a/e2e/cli.test.ts +++ b/e2e/cli.test.ts @@ -2,7 +2,7 @@ import 'reflect-metadata'; import { execSync, spawn } from 'node:child_process'; import { randomUUID } from 'node:crypto'; import { existsSync, readFileSync, writeFileSync } from 'node:fs'; -import { rm, unlink } from 'node:fs/promises'; +import { rm, unlink, writeFile } from 'node:fs/promises'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { @@ -40,25 +40,47 @@ const LOWKEY_VAULT_IMAGE = 'nagyesta/lowkey-vault:7.1.32'; const LOWKEY_VAULT_PORT = 8443; describe('Envilder (E2E)', () => { - beforeAll(async () => { - await cleanUpSystem(); - execSync('pnpm build', { cwd: rootDir, stdio: 'inherit' }); - execSync('node --loader ts-node/esm scripts/pack-and-install.ts', { - cwd: rootDir, - stdio: 'inherit', - }); - }, 60_000); + // Unique ID per test run prevents race conditions between concurrent CI runs + const runId = randomUUID().slice(0, 8); + const ssmPrefix = `/Test/${runId}`; const envilder = 'envilder'; const envFilePath = join(rootDir, 'e2e', 'sample', 'cli-validation.env'); - const mapFilePath = join(rootDir, 'e2e', 'sample', 'param-map.json'); + const mapFilePath = join(rootDir, 'e2e', 'sample', `param-map-${runId}.json`); const mapFileWithConfigPath = join( rootDir, 'e2e', 'sample', - 'param-map-with-aws-config.json', + `param-map-with-aws-config-${runId}.json`, ); - const singleSsmPath = '/Test/SingleVariable'; + const singleSsmPath = `${ssmPrefix}/SingleVariable`; + + beforeAll(async () => { + await Promise.all([ + writeFile( + mapFilePath, + JSON.stringify({ TOKEN_SECRET: `${ssmPrefix}/Token` }, null, 2), + ), + writeFile( + mapFileWithConfigPath, + JSON.stringify( + { + $config: { provider: 'aws' }, + TOKEN_SECRET: `${ssmPrefix}/Token`, + }, + null, + 2, + ), + ), + ]); + + await cleanUpSystem(); + execSync('pnpm build', { cwd: rootDir, stdio: 'inherit' }); + execSync('node --loader ts-node/esm scripts/pack-and-install.ts', { + cwd: rootDir, + stdio: 'inherit', + }); + }, 60_000); beforeEach(async () => { await cleanUpSsm(mapFilePath, singleSsmPath); @@ -72,6 +94,10 @@ describe('Envilder (E2E)', () => { afterAll(async () => { await cleanUpSystem(); + await Promise.all([ + rm(mapFilePath, { force: true }), + rm(mapFileWithConfigPath, { force: true }), + ]); }, 60_000); it('Should_PrintCorrectVersion_When_VersionFlagIsProvided', async () => {