diff --git a/package.json b/package.json index 4370bf3c8..488b5629d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "lint": "prettier --check --cache . && eslint --cache .", "format": "prettier --write .", "build": "bun run scripts/run-all.ts build", - "test": "bun test scripts/run-all.test.ts && bun run scripts/run-all.ts test", + "test": "bun test ./scripts/*.test.ts && bun run scripts/run-all.ts test", "test:e2e": "bun test scripts/e2e", "dev": "bun run scripts/dev.ts", "setup": "bun packages/cli/src/index.ts setup", diff --git a/scripts/db-setup.test.ts b/scripts/db-setup.test.ts index 1eda4c333..29b7d2e25 100644 --- a/scripts/db-setup.test.ts +++ b/scripts/db-setup.test.ts @@ -3,7 +3,7 @@ // the pre-re-pin numbering of workbench's own two migrations) is refused // with the reset instruction instead of being patched incrementally. // DB-gated: skipped when DATABASE_URL is unset. -import { afterAll, describe, expect, test } from "bun:test"; +import { describe, expect, test } from "bun:test"; import { dbTargetFromUrl, loadPostgres, setupDatabase } from "./db-setup"; @@ -19,32 +19,30 @@ const OLD_NUMBERING_TAIL = [ describeIfDb( "setupDatabase against a schema migrated under the old numbering", () => { - const schema = `db_setup_test_${Date.now().toString(36)}`; - const target = dbTargetFromUrl(databaseUrl); - const client = loadPostgres().then((postgres) => - postgres({ ...target, max: 1, onnotice: () => undefined }), - ); - afterAll(async () => { - const sql = await client; - await sql.unsafe(`DROP SCHEMA IF EXISTS "${schema}" CASCADE`); - await sql.end(); - }); - test("refuses to apply incrementally and names the reset", async () => { - const sql = await client; - await sql.unsafe(`CREATE SCHEMA "${schema}"`); - await sql.unsafe( - `CREATE TABLE "${schema}"."workbench_setup_migration" (filename text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())`, + const schema = `db_setup_test_${Date.now().toString(36)}`; + const target = dbTargetFromUrl(databaseUrl); + const sql = await loadPostgres().then((postgres) => + postgres({ ...target, max: 1, onnotice: () => undefined }), ); - for (const file of OLD_NUMBERING_TAIL) { + try { + await sql.unsafe(`CREATE SCHEMA "${schema}"`); await sql.unsafe( - `INSERT INTO "${schema}"."workbench_setup_migration" (filename) VALUES ($1)`, - [file], + `CREATE TABLE "${schema}"."workbench_setup_migration" (filename text PRIMARY KEY, applied_at timestamptz NOT NULL DEFAULT now())`, ); + for (const file of OLD_NUMBERING_TAIL) { + await sql.unsafe( + `INSERT INTO "${schema}"."workbench_setup_migration" (filename) VALUES ($1)`, + [file], + ); + } + await expect(setupDatabase(databaseUrl, { schema })).rejects.toThrow( + /different @intx\/db migration set[\s\S]*db-setup\.ts --reset/, + ); + } finally { + await sql.unsafe(`DROP SCHEMA IF EXISTS "${schema}" CASCADE`); + await sql.end(); } - await expect(setupDatabase(databaseUrl, { schema })).rejects.toThrow( - /different @intx\/db migration set[\s\S]*db-setup\.ts --reset/, - ); }); }, );