diff --git a/package.json b/package.json index 7e22828..2de9ee0 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "LICENSE" ], "scripts": { - "test": "node --test test/*.test.mjs", + "test": "node scripts/run-node-test-files.mjs", "pack:dry-run": "npm pack --dry-run" }, "keywords": [ diff --git a/plugins/omo/package.json b/plugins/omo/package.json index 646c7f1..2d8061d 100644 --- a/plugins/omo/package.json +++ b/plugins/omo/package.json @@ -27,6 +27,6 @@ "check": "npm run build && npm test", "sync:hooks": "node scripts/sync-hook-status-messages.mjs", "sync:skills": "node scripts/sync-skills.mjs", - "test": "node --test test/*.test.mjs" + "test": "node ../../scripts/run-node-test-files.mjs" } } diff --git a/plugins/omo/test/aggregate-build.test.mjs b/plugins/omo/test/aggregate-build.test.mjs index 3c1c0e3..c370677 100644 --- a/plugins/omo/test/aggregate-build.test.mjs +++ b/plugins/omo/test/aggregate-build.test.mjs @@ -1,9 +1,19 @@ import assert from "node:assert/strict"; -import { readFile } from "node:fs/promises"; +import { readFile, stat } from "node:fs/promises"; import { join } from "node:path"; import test from "node:test"; -import { readJson, root } from "./aggregate-plugin-fixture.mjs"; +import { readJson, repoRoot, root } from "./aggregate-plugin-fixture.mjs"; + +async function pathExists(path) { + try { + await stat(path); + return true; + } catch (error) { + if (error instanceof Error && "code" in error && error.code === "ENOENT") return false; + throw error; + } +} test("#given aggregate plugin build script #when inspected #then generated assets run before workspace builds", async () => { // given @@ -21,14 +31,19 @@ test("#given aggregate plugin build script #when inspected #then generated asset ); assert.match(buildScript, /^node scripts\/sync-version\.mjs &&/); assert.match(buildScript, /materialize-shared-upstreams\.mjs --strict && node scripts\/sync-skills\.mjs/); - assert.equal(testScript, "node --test test/*.test.mjs"); + assert.equal(testScript, "node ../../scripts/run-node-test-files.mjs"); assert(packageJson.workspaces.includes("components/ultrawork")); assert.doesNotMatch(packageText, /\bpython3?\b|ultrawork-detector\.py/); }); -test("#given omo-codex package build script #when inspected #then delegates to the aggregate plugin package", async () => { +test("#given omo-codex package build script #when inspected #then delegates to the aggregate plugin package", async (t) => { // given - const packageJson = JSON.parse(await readFile(join(root, "..", "package.json"), "utf8")); + const packageJsonPath = join(repoRoot, "packages", "omo-codex", "package.json"); + if (!(await pathExists(packageJsonPath))) { + t.skip("LazyCodex mirror does not include the omo-codex wrapper package"); + return; + } + const packageJson = JSON.parse(await readFile(packageJsonPath, "utf8")); // when const buildPluginScript = packageJson.scripts["build:plugin"]; diff --git a/scripts/run-node-test-files.mjs b/scripts/run-node-test-files.mjs new file mode 100644 index 0000000..0d3353a --- /dev/null +++ b/scripts/run-node-test-files.mjs @@ -0,0 +1,14 @@ +import { spawnSync } from "node:child_process" +import { readdirSync } from "node:fs" +import { join } from "node:path" + +const testFiles = readdirSync("test") + .filter((file) => file.endsWith(".test.mjs")) + .sort() + .map((file) => join("test", file)) + +const result = spawnSync(process.execPath, ["--test", ...testFiles], { + stdio: "inherit", +}) + +process.exit(result.status ?? 1) diff --git a/test/lazycodex-ai-bin.test.mjs b/test/lazycodex-ai-bin.test.mjs index babc96e..9e5af02 100644 --- a/test/lazycodex-ai-bin.test.mjs +++ b/test/lazycodex-ai-bin.test.mjs @@ -1,10 +1,11 @@ import assert from "node:assert/strict" import { existsSync, readFileSync } from "node:fs" -import { join } from "node:path" +import { dirname, join } from "node:path" import { spawnSync } from "node:child_process" import { describe, it } from "node:test" +import { fileURLToPath } from "node:url" -const root = new URL("..", import.meta.url).pathname +const root = dirname(dirname(fileURLToPath(import.meta.url))) const packageJsonPath = join(root, "package.json") const packageLockPath = join(root, "package-lock.json") const publishWorkflowPath = join(root, ".github", "workflows", "npm-publish.yml") @@ -23,6 +24,7 @@ describe("lazycodex-ai npm package", () => { assert.equal(manifest.name, "lazycodex-ai") assert.equal(manifest.version, releaseVersion) assert.equal(manifest.bin?.["lazycodex-ai"], "bin/lazycodex-ai.js") + assert.equal(manifest.scripts?.test, "node scripts/run-node-test-files.mjs") assert.equal(manifest.private, undefined) })