// tests/fixtures/npm-cli.json, what real npm 11.7.0 did for each command over the cli // registry (`npm-oracle.mjs cli`), shared by the Node-side and browser specs. import { readFileSync } from "node:fs"; import type { FakePackages } from "./npm-registry"; // @ts-expect-error: an untyped .mjs script import { cliPackageText } from "../scripts/npm-oracle.mjs"; export interface CliCase { description: string; args: string[]; package?: Record; seed?: Record; indent?: string | number; newline?: string; npm: { status: number; stdout: string; stderr: string; seedLock?: string; packageJson: string | null; lockfile: string | null; modules: string[] }; } /** What npm printed and how it exited. */ export interface Output { status: number; stdout: string; stderr: string; } /** A script, `npm exec` or npx case: `files` written into the project, run as `bin`. */ export interface ScriptCase { description: string; args: string[]; bin?: "npm" | "npx"; package?: Record; seed?: Record; files: Record; /** Run twice; the second run's output and registry requests are `npm.again`. */ again?: boolean; npm: Output & { /** The npx cache by hash: its package.json and package-lock.json. */ npx: Record | null; again?: Output & { requests: string[] }; }; } export const cli = JSON.parse(readFileSync("tests/fixtures/npm-cli.json", "utf8")) as { registry: FakePackages; cases: Record; scripts: Record; }; /** package.json as npm found it when the command ran: the case's own, else the seed's. */ export const startingPackage = (c: CliCase): string | undefined => (c.package ?? c.seed) && (cliPackageText(c, c.package ?? c.seed) as string);