Skip to content

Commit cca8aea

Browse files
committed
test(testcontainers): register the warmup per collecting suite
1 parent 8aa5670 commit cca8aea

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

internal-packages/testcontainers/src/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,7 @@ const withWarmup = <T extends WarmableTestApi>(
324324
api: T,
325325
warmUp: (context: any) => Promise<void>
326326
): T => {
327-
let registered = false;
328-
329327
const register = () => {
330-
if (registered) {
331-
return;
332-
}
333-
registered = true;
334328
api.beforeAll(warmUp, CONTAINER_WARMUP_TIMEOUT_MS);
335329
};
336330

internal-packages/testcontainers/src/warmup.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { describe, expect, vi } from "vitest";
2-
import { containerTest } from "./index";
2+
import { clickhouseTest, containerTest } from "./index";
33

44
vi.setConfig({ testTimeout: 10_000 });
55

6+
describe.skip("a skipped suite that touches the fixture first", () => {
7+
containerTest("never runs", async ({ prisma }) => {
8+
expect(prisma).toBeDefined();
9+
});
10+
});
11+
612
describe("container fixture warmup", () => {
713
containerTest("the first test is not billed for the container boot", async ({ prisma }) => {
814
const rows = await prisma.$queryRawUnsafe<Array<{ ok: number }>>("SELECT 1 as ok");
@@ -16,3 +22,12 @@ describe("container fixture warmup", () => {
1622
expect(rows[0]?.ok).toBe(2);
1723
});
1824
});
25+
26+
describe("worker-scoped fixtures are warmed too", () => {
27+
clickhouseTest("clickhouse is up before the first test", async ({ clickhouseClient }) => {
28+
const rs = await clickhouseClient.query({ query: "SELECT 1 AS ok", format: "JSONEachRow" });
29+
const rows = await rs.json<{ ok: number }>();
30+
31+
expect(rows[0]?.ok).toBe(1);
32+
});
33+
});

0 commit comments

Comments
 (0)