testSuitesOrDefinitionsAlone
--suites runs a package's suites alone, and --definitions the test definitions alone (as a verify's package
stage and its tests stage do, side by side); asking for both is refused, as it would run nothing.
import { okIn, tcmIn, tempDir } from "#codebase/tcmts/cli/test/e2e/harness"; import assert from "node:assert/strict"; import fs from "node:fs"; import path from "node:path"; export const testSuitesOrDefinitionsAlone = () => { const dir = tempDir("suites alone"); const ok = (...args: string[]) => okIn(dir, ...args); const scratch = (ns: string, text: string) => fs.writeFileSync(path.join(dir, "scratch.ts"), `// tcm: namespace ${ns}\n${text}`); ok("init"); scratch( "greeter", `export const greet = (name: string) => \`hello, \${name}\`; export const main = (...args: string[]) => console.log(greet(args[0] ?? "world")); export const testGreet = () => { if (greet("a") !== "hello, a") throw new Error(greet("a")); }; export const manifest = { name: "greeter", bin: { greet: "main" }, suites: { greet: ["e2e"] } }; `, ); ok("add"); scratch( "greeter.e2e", `import assert from "node:assert/strict"; import { spawnSync } from "node:child_process"; export const testGreets = () => { const r = spawnSync(process.execPath, [process.env.GREET_BIN!, "tcm"], { encoding: "utf8" }); assert.equal(r.stdout, "hello, tcm\\n"); }; `, ); ok("add"); const suites = ok("test", "--suites"); assert.match(suites, /✓ greeter\.e2e\.testGreets[\s\S]*suites: 1 passed, 0 failed\n/); assert.doesNotMatch(suites, /greeter\.testGreet\b/); const definitions = ok("test", "--definitions"); assert.match(definitions, /✓ greeter\.testGreet\b/); assert.doesNotMatch(definitions, /suites|testGreets/); // (what each ran holds for a run of both) assert.match(ok("test"), /\(1 cached\)[\s\S]*suites: 1 passed, 0 failed \(1 cached\)/); // with no suites where it looks, it says so assert.match(ok("test", "greeter.testGreet", "--suites"), /no suites under greeter\.testGreet/); const both = tcmIn(dir, "test", "--definitions", "--suites"); assert.notEqual(both.status, 0); assert.match(both.out, /--definitions and --suites leave each other nothing to run/); }