From c33cd19a05bc24a8994ef782a667f660ca40efdd Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Mon, 30 Mar 2026 22:11:15 +0100 Subject: [PATCH] fix(site/scripts): guard check-compiler main block from test imports (#23825) --- site/scripts/check-compiler.mjs | 9 +++++++-- site/scripts/check-compiler.test.mjs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/site/scripts/check-compiler.mjs b/site/scripts/check-compiler.mjs index 793338b43c..a4e193237f 100644 --- a/site/scripts/check-compiler.mjs +++ b/site/scripts/check-compiler.mjs @@ -10,6 +10,7 @@ */ import { readFileSync, readdirSync } from "node:fs"; import { join, relative } from "node:path"; +import { fileURLToPath } from "node:url"; import { transformSync } from "@babel/core"; // Resolve the site/ directory (ESM equivalent of __dirname + ".."). @@ -205,9 +206,12 @@ function printReport(failures, totalCompiled, fileCount, hadErrors) { // Main // --------------------------------------------------------------------------- -let hadCollectionErrors = false; +// Only run the main block when executed directly, not when imported +// by tests for the exported pure functions. +if (process.argv[1] === fileURLToPath(import.meta.url)) { + let hadCollectionErrors = false; -const files = targetDirs.flatMap((d) => collectFiles(join(siteDir, d))); + const files = targetDirs.flatMap((d) => collectFiles(join(siteDir, d))); let totalCompiled = 0; const failures = []; @@ -225,3 +229,4 @@ printReport(failures, totalCompiled, files.length, hadCollectionErrors); if (failures.length > 0 || hadCollectionErrors) { process.exitCode = 1; } +} diff --git a/site/scripts/check-compiler.test.mjs b/site/scripts/check-compiler.test.mjs index 5485f571a3..9dce97f81c 100644 --- a/site/scripts/check-compiler.test.mjs +++ b/site/scripts/check-compiler.test.mjs @@ -35,7 +35,7 @@ describe("shortenMessage", () => { expect(shortenMessage("Single sentence.")).toBe("Single sentence"); }); - it("returns (unknown) for empty input", () => { + it("preserves empty string and (unknown) sentinel", () => { expect(shortenMessage("")).toBe(""); expect(shortenMessage("(unknown)")).toBe("(unknown)"); });