mirror of
https://github.com/coder/coder.git
synced 2026-09-21 12:44:32 +08:00
fix(site/scripts): guard check-compiler main block from test imports (#23825)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user