Skip to content

Disable test caching on Windows, hide gotestsum skipped tests outside CI #685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,28 @@ function memoize(fn) {

const typeScriptSubmodulePath = path.join(__dirname, "_submodules", "TypeScript");

function assertTypeScriptCloned() {
const isTypeScriptSubmoduleCloned = memoize(() => {
try {
const stat = fs.statSync(path.join(typeScriptSubmodulePath, "package.json"));
if (stat.isFile()) {
return;
return true;
}
}
catch {}

throw new Error("_submodules/TypeScript does not exist; try running `git submodule update --init --recursive`");
return false;
});

const warnIfTypeScriptSubmoduleNotCloned = memoize(() => {
if (!isTypeScriptSubmoduleCloned()) {
console.warn(pc.yellow("Warning: TypeScript submodule is not cloned; some tests may be skipped."));
}
});

function assertTypeScriptCloned() {
if (!isTypeScriptSubmoduleCloned()) {
throw new Error("_submodules/TypeScript does not exist; try running `git submodule update --init --recursive`");
}
}

const tools = new Map([
Expand Down Expand Up @@ -209,12 +221,20 @@ const goTestFlags = [

const goTestEnv = {
...(options.concurrentTestPrograms ? { TS_TEST_PROGRAM_SINGLE_THREADED: "false" } : {}),
// Go test caching takes a long time on Windows.
// https://github.com/golang/go/issues/72992
...(process.platform === "win32" ? { GOFLAGS: "-count=1" } : {}),
};

const goTestSumFlags = [
"--format-hide-empty-pkg",
...(!isCI ? ["--hide-summary", "skipped"] : []),
];

const $test = $({ env: goTestEnv });

const gotestsum = memoize(() => {
const args = isInstalled("gotestsum") ? ["gotestsum", "--format-hide-empty-pkg", "--"] : ["go", "test"];
const args = isInstalled("gotestsum") ? ["gotestsum", ...goTestSumFlags, "--"] : ["go", "test"];
return args.concat(goTestFlags);
});

Expand All @@ -223,6 +243,7 @@ const goTest = memoize(() => {
});

async function runTests() {
warnIfTypeScriptSubmoduleNotCloned();
await $test`${gotestsum()} ./... ${isCI ? ["--timeout=45m"] : []}`;
}

Expand All @@ -232,6 +253,7 @@ export const test = task({
});

async function runTestBenchmarks() {
warnIfTypeScriptSubmoduleNotCloned();
// Run the benchmarks once to ensure they compile and run without errors.
await $test`${goTest()} -run=- -bench=. -benchtime=1x ./...`;
}
Expand Down