diff --git a/typescript-sdk/scripts/template-tests.mjs b/typescript-sdk/scripts/template-tests.mjs index dc49d5d..337d315 100644 --- a/typescript-sdk/scripts/template-tests.mjs +++ b/typescript-sdk/scripts/template-tests.mjs @@ -1,14 +1,30 @@ +import { existsSync, readdirSync } from "node:fs"; +import { join } from "node:path"; import { spawnSync } from "node:child_process"; -const suites = [ - "runtime/tests/*.test.mjs", - "typescript-sdk/tests/*.test.mjs" -]; +const root = new URL("../..", import.meta.url); -for (const pattern of suites) { - const run = spawnSync("node", ["--test", pattern], { +const suites = ["runtime/tests", "typescript-sdk/tests"]; + +const findTestFiles = (dir) => { + if (!existsSync(new URL(dir, root))) { + return []; + } + + return readdirSync(new URL(dir, root)) + .filter((name) => name.endsWith(".test.mjs")) + .map((name) => join(dir, name)); +}; + +for (const suiteDir of suites) { + const files = findTestFiles(suiteDir); + if (files.length === 0) { + continue; + } + + const run = spawnSync("node", ["--test", ...files], { stdio: "inherit", - cwd: new URL("../..", import.meta.url) + cwd: root }); if (run.status !== 0) { process.exit(run.status ?? 1);