Skip to content

Commit c472d79

Browse files
test(nodejs): verify CLI path resolution in both ESM and CJS builds
Replace the cliUrl-based test (which skipped getBundledCliPath()) with tests that construct CopilotClient without cliUrl, actually exercising the bundled CLI resolution in both module formats. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b975f81 commit c472d79

1 file changed

Lines changed: 20 additions & 9 deletions

File tree

nodejs/test/cjs-compat.test.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,33 @@ describe("Dual ESM/CJS build (#528)", () => {
4040
expect(output).toContain("CJS require: OK");
4141
});
4242

43-
it("CopilotClient constructor works in CJS context", () => {
43+
it("CJS build resolves bundled CLI path", () => {
4444
const script = `
4545
const sdk = require(${JSON.stringify(join(distDir, "cjs/index.js"))});
46-
try {
47-
const client = new sdk.CopilotClient({ cliUrl: "http://localhost:8080" });
48-
console.log('CopilotClient constructor: OK');
49-
} catch (e) {
50-
console.error('constructor failed:', e.message);
51-
process.exit(1);
52-
}
46+
const client = new sdk.CopilotClient({ autoStart: false });
47+
console.log('CJS CLI resolved: OK');
5348
`;
5449
const output = execFileSync(process.execPath, ["--eval", script], {
5550
encoding: "utf-8",
5651
timeout: 10000,
5752
cwd: join(import.meta.dirname, ".."),
5853
});
59-
expect(output).toContain("CopilotClient constructor: OK");
54+
expect(output).toContain("CJS CLI resolved: OK");
55+
});
56+
57+
it("ESM build resolves bundled CLI path", () => {
58+
const esmPath = join(distDir, "index.js");
59+
const script = `
60+
import { pathToFileURL } from 'node:url';
61+
const sdk = await import(pathToFileURL(${JSON.stringify(esmPath)}).href);
62+
const client = new sdk.CopilotClient({ autoStart: false });
63+
console.log('ESM CLI resolved: OK');
64+
`;
65+
const output = execFileSync(process.execPath, ["--input-type=module", "--eval", script], {
66+
encoding: "utf-8",
67+
timeout: 10000,
68+
cwd: join(import.meta.dirname, ".."),
69+
});
70+
expect(output).toContain("ESM CLI resolved: OK");
6071
});
6172
});

0 commit comments

Comments
 (0)