From 9ef3331f8504054ab7aea841c7d010a51689436c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Wed, 11 Nov 2026 01:56:44 +0100 Subject: [PATCH] test(pwa): give the sw-version script tests time to start node --- scripts/__tests__/generate-sw-version.test.ts | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/scripts/__tests__/generate-sw-version.test.ts b/scripts/__tests__/generate-sw-version.test.ts index e123c8a15..0df28757f 100644 --- a/scripts/__tests__/generate-sw-version.test.ts +++ b/scripts/__tests__/generate-sw-version.test.ts @@ -47,25 +47,37 @@ describe("public/sw.js CACHE_VERSION wiring", () => { }); }); +// Each test starts a fresh node process. On a busy CI runner one start +// has taken over six seconds, past the five-second default. +const SPAWN_TIMEOUT_MS = 30_000; + describe("scripts/generate-sw-version.mjs", () => { afterAll(() => { // Don't leave the generated artefact behind for the next test run. if (existsSync(GENERATED_PATH)) rmSync(GENERATED_PATH); }); - it("writes self.__APP_VERSION__ matching package.json", () => { - execFileSync("node", [SCRIPT_PATH], { stdio: "pipe" }); - expect(existsSync(GENERATED_PATH)).toBe(true); - const pkg = JSON.parse(readFileSync(PKG_PATH, "utf8")); - const generated = readFileSync(GENERATED_PATH, "utf8"); - expect(generated).toContain(`self.__APP_VERSION__ = "v${pkg.version}"`); - }); + it( + "writes self.__APP_VERSION__ matching package.json", + () => { + execFileSync("node", [SCRIPT_PATH], { stdio: "pipe" }); + expect(existsSync(GENERATED_PATH)).toBe(true); + const pkg = JSON.parse(readFileSync(PKG_PATH, "utf8")); + const generated = readFileSync(GENERATED_PATH, "utf8"); + expect(generated).toContain(`self.__APP_VERSION__ = "v${pkg.version}"`); + }, + SPAWN_TIMEOUT_MS, + ); - it("re-running the script is idempotent (overwrites with same content)", () => { - execFileSync("node", [SCRIPT_PATH], { stdio: "pipe" }); - const a = readFileSync(GENERATED_PATH, "utf8"); - execFileSync("node", [SCRIPT_PATH], { stdio: "pipe" }); - const b = readFileSync(GENERATED_PATH, "utf8"); - expect(b).toBe(a); - }); + it( + "re-running the script is idempotent (overwrites with same content)", + () => { + execFileSync("node", [SCRIPT_PATH], { stdio: "pipe" }); + const a = readFileSync(GENERATED_PATH, "utf8"); + execFileSync("node", [SCRIPT_PATH], { stdio: "pipe" }); + const b = readFileSync(GENERATED_PATH, "utf8"); + expect(b).toBe(a); + }, + SPAWN_TIMEOUT_MS, + ); });