test(opencode-plugin): ESM default-export test (#3967)

The plugin became ESM-only when the CJS bundle was dropped to fix the OpenCode loader
(#3883), so tests/scaffold.test.ts's 'CJS default export resolves via require()' test
fails at publish time with 'Cannot find module ../dist/index.cjs' (it only runs in the
npm-publish opencode-plugin job, so the cycle never caught it). Replaced with an ESM
import of the built dist/index.js asserting the same v1 { id, server } shape; dropped the
now-unused createRequire import. omniroute@3.8.26 itself already published fine.
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-06-16 02:50:40 -03:00
committed by GitHub
parent d59cd14391
commit ca1e17f740

View File

@@ -1,6 +1,5 @@
import test from "node:test"; import test from "node:test";
import assert from "node:assert/strict"; import assert from "node:assert/strict";
import { createRequire } from "node:module";
import { import {
OmniRoutePlugin, OmniRoutePlugin,
OMNIROUTE_PROVIDER_KEY, OMNIROUTE_PROVIDER_KEY,
@@ -63,11 +62,12 @@ test("OmniRoutePlugin: returns an empty hooks object (scaffold)", async () => {
assert.notEqual(hooks, null); assert.notEqual(hooks, null);
}); });
test("scaffold: CJS default export resolves via require() with v1 shape", () => { test("scaffold: built ESM default export resolves with the v1 plugin shape", async () => {
const require_ = createRequire(import.meta.url); // The plugin is ESM-only now — the CJS bundle was dropped to fix the OpenCode
const cjs = require_("../dist/index.cjs"); // loader (#3883), so there is no more ../dist/index.cjs. Validate that the built
// after cjsInterop:true, default export is on cjs.default // distributable's default export still carries the OpenCode v1 { id, server } shape.
assert.strictEqual(typeof cjs.default, "object"); const mod = await import("../dist/index.js");
assert.strictEqual(cjs.default.id, "@omniroute/opencode-plugin"); assert.strictEqual(typeof mod.default, "object");
assert.strictEqual(typeof cjs.default.server, "function"); assert.strictEqual(mod.default.id, "@omniroute/opencode-plugin");
assert.strictEqual(typeof mod.default.server, "function");
}); });