From abe69901b289034b9c96e5fd581fba7c851de793 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Mon, 9 Dec 2024 17:42:40 -0800 Subject: [PATCH] make the helper quieter --- package.json | 2 +- scripts/runner.node.mjs | 67 ++++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 07c30a8ccc..accf7ccaac 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,6 @@ "prettier:check": "bun run analysis:no-llvm --target prettier-check", "prettier:extra": "bun run analysis:no-llvm --target prettier-extra", "prettier:diff": "bun run analysis:no-llvm --target prettier-diff", - "node:test": "node ./scripts/runner.node.mjs --exec-path=$npm_execpath --node-tests " + "node:test": "node ./scripts/runner.node.mjs --quiet --exec-path=$npm_execpath --node-tests " } } diff --git a/scripts/runner.node.mjs b/scripts/runner.node.mjs index 9a9bc59256..6e763977de 100755 --- a/scripts/runner.node.mjs +++ b/scripts/runner.node.mjs @@ -41,7 +41,7 @@ import { unzip, } from "./utils.mjs"; import { userInfo } from "node:os"; - +let isQuiet = false; const cwd = import.meta.dirname ? dirname(import.meta.dirname) : process.cwd(); const testsPath = join(cwd, "test"); @@ -90,6 +90,10 @@ const { values: options, positionals: filters } = parseArgs({ multiple: true, default: undefined, }, + ["quiet"]: { + type: "boolean", + default: false, + }, ["smoke"]: { type: "string", default: undefined, @@ -101,6 +105,10 @@ const { values: options, positionals: filters } = parseArgs({ }, }); +if (options["quiet"]) { + isQuiet = true; +} + /** * * @returns {Promise} @@ -112,13 +120,13 @@ async function runTests() { } else { execPath = getExecPath(options["exec-path"]); } - console.log("Bun:", execPath); + !isQuiet && console.log("Bun:", execPath); const revision = getRevision(execPath); - console.log("Revision:", revision); + !isQuiet && console.log("Revision:", revision); const tests = getRelevantTests(testsPath); - console.log("Running tests:", tests.length); + !isQuiet && console.log("Running tests:", tests.length); /** @type {VendorTest[] | undefined} */ let vendorTests; @@ -127,7 +135,7 @@ async function runTests() { vendorTests = await getVendorTests(cwd); if (vendorTests.length) { vendorTotal = vendorTests.reduce((total, { testPaths }) => total + testPaths.length + 1, 0); - console.log("Running vendor tests:", vendorTotal); + !isQuiet && console.log("Running vendor tests:", vendorTotal); } } @@ -184,9 +192,11 @@ async function runTests() { return result; }; - for (const path of [cwd, testsPath]) { - const title = relative(cwd, join(path, "package.json")).replace(/\\/g, "/"); - await runTest(title, async () => spawnBunInstall(execPath, { cwd: path })); + if (!isQuiet) { + for (const path of [cwd, testsPath]) { + const title = relative(cwd, join(path, "package.json")).replace(/\\/g, "/"); + await runTest(title, async () => spawnBunInstall(execPath, { cwd: path })); + } } if (results.every(({ ok }) => ok)) { @@ -266,10 +276,10 @@ async function runTests() { } if (!isCI) { - console.log("-------"); - console.log("passing", results.length - failedTests.length, "/", results.length); + !isQuiet && console.log("-------"); + !isQuiet && console.log("passing", results.length - failedTests.length, "/", results.length); for (const { testPath } of failedTests) { - console.log("-", testPath); + !isQuiet && console.log("-", testPath); } } return results; @@ -977,7 +987,7 @@ function getRelevantTests(cwd) { const includes = options["include"]?.flatMap(getFilter); if (includes?.length) { availableTests.push(...tests.filter(testPath => includes.some(filter => isMatch(testPath, filter)))); - console.log("Including tests:", includes, availableTests.length, "/", tests.length); + !isQuiet && console.log("Including tests:", includes, availableTests.length, "/", tests.length); } else { availableTests.push(...tests); } @@ -992,7 +1002,7 @@ function getRelevantTests(cwd) { availableTests.splice(index, 1); } } - console.log("Excluding tests:", excludes, excludedTests.length, "/", availableTests.length); + !isQuiet && console.log("Excluding tests:", excludes, excludedTests.length, "/", availableTests.length); } } @@ -1000,7 +1010,7 @@ function getRelevantTests(cwd) { const maxShards = parseInt(options["max-shards"]); if (filters?.length) { filteredTests.push(...availableTests.filter(testPath => filters.some(filter => isMatch(testPath, filter)))); - console.log("Filtering tests:", filteredTests.length, "/", availableTests.length); + !isQuiet && console.log("Filtering tests:", filteredTests.length, "/", availableTests.length); } else if (options["smoke"] !== undefined) { const smokePercent = parseFloat(options["smoke"]) || 0.01; const smokeCount = Math.ceil(availableTests.length * smokePercent); @@ -1010,23 +1020,24 @@ function getRelevantTests(cwd) { smokeTests.add(availableTests[randomIndex]); } filteredTests.push(...Array.from(smokeTests)); - console.log("Smoking tests:", filteredTests.length, "/", availableTests.length); + !isQuiet && console.log("Smoking tests:", filteredTests.length, "/", availableTests.length); } else if (maxShards > 1) { for (let i = 0; i < availableTests.length; i++) { if (i % maxShards === shardId) { filteredTests.push(availableTests[i]); } } - console.log( - "Sharding tests:", - shardId, - "/", - maxShards, - "with tests", - filteredTests.length, - "/", - availableTests.length, - ); + !isQuiet && + console.log( + "Sharding tests:", + shardId, + "/", + maxShards, + "with tests", + filteredTests.length, + "/", + availableTests.length, + ); } else { filteredTests.push(...availableTests); } @@ -1462,7 +1473,9 @@ export async function main() { process.on(signal, () => onExit(signal)); } - printEnvironment(); + if (!isQuiet) { + printEnvironment(); + } // FIXME: Some DNS tests hang unless we set the DNS server to 8.8.8.8 // It also appears to hang on 1.1.1.1, which could explain this issue: @@ -1482,7 +1495,7 @@ export async function main() { const userCount = getLoggedInUserCount(); if (!userCount) { if (waitForUser) { - console.log("No users logged in, exiting runner..."); + !isQuiet && console.log("No users logged in, exiting runner..."); } break; }