49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
// Vitest globalSetup for the production e2e suite.
|
|
//
|
|
// Setup: seeds a fresh project on prod (unless RUDDER_E2E_PROJECT_KEY is provided) and
|
|
// writes .e2e-prod.local.json for the tests to read.
|
|
// Teardown: deletes the seeded project (default). Set RUDDER_E2E_KEEP=1 to keep it.
|
|
|
|
import { runSeed, deleteProject } from './seed.js';
|
|
import { readArtifact, writeArtifact, removeArtifact } from './artifact.js';
|
|
import type { SeedArtifact } from './types.js';
|
|
|
|
export default async function setup(): Promise<() => Promise<void>> {
|
|
const baseUrl = process.env.RUDDER_E2E_BASE_URL ?? 'https://api.rudder.build';
|
|
|
|
// Externally-provided project: skip seeding, just verify an artifact/env exists.
|
|
if (process.env.RUDDER_E2E_PROJECT_KEY) {
|
|
const existing = readArtifact();
|
|
if (!existing) {
|
|
writeArtifact({
|
|
baseUrl,
|
|
projectKey: process.env.RUDDER_E2E_PROJECT_KEY,
|
|
// Remaining fields are unknown for an external project; tests relying on the
|
|
// seeded dataset/admin token will require a real seed run.
|
|
} as unknown as SeedArtifact);
|
|
}
|
|
return async () => {};
|
|
}
|
|
|
|
const log = (m: string) => console.log(`[seed] ${m}`);
|
|
log(`seeding ${baseUrl} ...`);
|
|
const artifact = await runSeed(baseUrl, log);
|
|
writeArtifact(artifact);
|
|
log(`seed complete: project=${artifact.projectId}`);
|
|
|
|
return async () => {
|
|
if (process.env.RUDDER_E2E_KEEP === '1') {
|
|
console.log('[seed] RUDDER_E2E_KEEP=1 — leaving project in place');
|
|
return;
|
|
}
|
|
try {
|
|
await deleteProject(artifact);
|
|
console.log(`[seed] deleted project ${artifact.projectId}`);
|
|
} catch (err) {
|
|
console.warn(`[seed] failed to delete project ${artifact.projectId}: ${String(err)}`);
|
|
} finally {
|
|
removeArtifact();
|
|
}
|
|
};
|
|
}
|