From 00842c334229058810f42de9f0dd6dc57badbf7e Mon Sep 17 00:00:00 2001 From: Greg Soucy Date: Thu, 23 Apr 2026 22:56:05 -0400 Subject: [PATCH] Fix template test runner to skip missing optional suites --- typescript-sdk/scripts/template-tests.mjs | 50 +++++++++++++++++++---- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/typescript-sdk/scripts/template-tests.mjs b/typescript-sdk/scripts/template-tests.mjs index dc49d5d..17f3062 100644 --- a/typescript-sdk/scripts/template-tests.mjs +++ b/typescript-sdk/scripts/template-tests.mjs @@ -1,16 +1,48 @@ import { spawnSync } from "node:child_process"; +import { existsSync, readdirSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +const repoRoot = new URL("../..", import.meta.url); +const repoRootPath = fileURLToPath(repoRoot); const suites = [ - "runtime/tests/*.test.mjs", - "typescript-sdk/tests/*.test.mjs" + { dir: "runtime/tests", optional: true }, + { dir: "typescript-sdk/tests", optional: false } ]; -for (const pattern of suites) { - const run = spawnSync("node", ["--test", pattern], { - stdio: "inherit", - cwd: new URL("../..", import.meta.url) - }); - if (run.status !== 0) { - process.exit(run.status ?? 1); +for (const suite of suites) { + const suitePath = path.join(repoRootPath, suite.dir); + + if (!existsSync(suitePath)) { + if (suite.optional) { + continue; + } + console.error(`Missing required test directory: ${suite.dir}`); + process.exit(1); + } + + const testFiles = readdirSync(suitePath) + .filter((name) => name.endsWith(".test.mjs")) + .sort() + .map((name) => path.join(suite.dir, name)); + + if (testFiles.length === 0) { + if (suite.optional) { + continue; + } + console.error(`No required test files found in: ${suite.dir}`); + process.exit(1); + } + + for (const testFile of testFiles) { + const run = spawnSync("node", ["--test", testFile], { + stdio: "inherit", + cwd: repoRoot + }); + + if (run.status !== 0) { + process.exit(run.status ?? 1); + } } }