fix(site/scripts): guard check-compiler main block from test imports (#23825)

This commit is contained in:
Danielle Maywood
2026-03-30 22:11:15 +01:00
committed by GitHub
parent adcea865c7
commit c33cd19a05
2 changed files with 8 additions and 3 deletions
+7 -2
View File
@@ -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;
}
}
+1 -1
View File
@@ -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)");
});