import assert from "node:assert/strict"; import { test } from "node:test"; import { launch } from "../src/launch.ts"; test("npm and npx run the guest npm with their arguments as they are", () => { assert.deepEqual(launch(["npm", "run", "dev"], "/app"), { entry: "/usr/local/bin/npm", argv: ["run", "dev"] }); assert.deepEqual(launch(["npx", "cowsay", "hi"], "/app"), { entry: "/usr/local/bin/npx", argv: ["cowsay", "hi"] }); }); test("node runs a file relative to the working directory", () => { assert.deepEqual(launch(["node", "server.js", "--port", "3000"], "/app"), { entry: "/app/server.js", argv: ["--port", "3000"] }); assert.deepEqual(launch(["node", "../lib/./x.mjs"], "/app/src"), { entry: "/app/lib/x.mjs", argv: [] }); assert.deepEqual(launch(["node", "/tmp/y.js"], "/app"), { entry: "/tmp/y.js", argv: [] }); }); test("node -e, -p, and -v run their source from a file beside the working directory", () => { const e = launch(["node", "-e", "console.log(1)", "a"], "/app"); assert.ok(e && "entry" in e); assert.match(e.entry, /^\/app\/\.nib-eval-\d+\.cjs$/); assert.deepEqual([e.argv, e.source], [["a"], "console.log(1)"]); const p = launch(["node", "-p", "1 + 1"], "/app"); assert.equal(p && "source" in p ? p.source : undefined, "console.log((1 + 1))"); const m = launch(["node", "-e", "import x from 'y'"], "/app"); assert.match(m && "entry" in m ? m.entry : "", /\.mjs$/); const v = launch(["node", "--version"], "/app"); assert.equal(v && "source" in v ? v.source : undefined, "console.log(process.version)"); }); test("other commands are not launched, and node refuses what it can't run", () => { assert.equal(launch(["ls"], "/app"), undefined); assert.deepEqual(launch(["node"], "/app"), { error: "node: the REPL is not available in this terminal; pass a file or -e", code: 1 }); assert.deepEqual(launch(["node", "--inspect", "x.js"], "/app"), { error: "node: bad option: --inspect", code: 9 }); });