// The guest npm's package.json and package-lock.json edits, checked in Node against // tests/fixtures/npm-cli.json: what real npm 11.7.0 wrote for each command // (`npm-oracle.mjs cli`). Each case's argv is parsed as the guest npm parses it, then // planned by the kernel's installer over the same registry; nothing is fetched or // installed, so this is the files alone. tests/npm-cli-guest.spec.ts runs the command. import { test, expect } from "@playwright/test"; import { parse } from "../src/npm-cli/command"; import { plan } from "../src/kernel/npm/install"; import { cli, startingPackage } from "./npm-cli-cases"; import { cliRegistry } from "./npm-registry"; for (const [name, c] of Object.entries(cli.cases)) { test(`${name}: npm ${c.args.join(" ")} leaves package.json and package-lock.json as npm did (${c.description})`, async () => { const parsed = parse(c.args, "/app").command; if (parsed.kind !== "install") throw new Error(`${name}: parses as ${parsed.kind}`); const text = startingPackage(c); const files = { root: "/app", packageJson: text === undefined ? undefined : { text, path: "/app/package.json" }, lockfile: c.npm.seedLock === undefined ? undefined : { text: c.npm.seedLock, path: "/app/package-lock.json" }, }; const outcome = await plan(parsed.request, files, cliRegistry(cli.registry)).then( (p) => ({ status: 0, packageJson: p.packageJson ?? text ?? null, lockfile: p.saveLock && p.lock ? p.lock.text : c.npm.seedLock ?? null, }), (e: Error & { code?: string }) => ({ status: 1, code: e.code, packageJson: text ?? null, lockfile: c.npm.seedLock ?? null }), ); const code = /^npm error code (\S+)$/m.exec(c.npm.stderr)?.[1]; expect(outcome).toEqual({ status: c.npm.status, ...(code && { code }), packageJson: c.npm.packageJson, lockfile: c.npm.lockfile }); }); }