|
| 1 | +import { mkdtempSync, rmSync, symlinkSync } from "node:fs"; |
| 2 | +import { tmpdir } from "node:os"; |
| 3 | +import path from "node:path"; |
| 4 | +import { spawnSync } from "node:child_process"; |
| 5 | +import { fileURLToPath } from "node:url"; |
| 6 | +import { describe, expect, it } from "vitest"; |
| 7 | + |
| 8 | +describe("npm CLI executable", () => { |
| 9 | + it("runs through the symlink created by npm and returns useful exit codes", () => { |
| 10 | + const directory = mkdtempSync(path.join(tmpdir(), "chartkit-cli-entry-")); |
| 11 | + const link = path.join(directory, "chart-kit"); |
| 12 | + try { |
| 13 | + symlinkSync( |
| 14 | + fileURLToPath(new URL("../bin/chart-kit.mjs", import.meta.url)), |
| 15 | + link |
| 16 | + ); |
| 17 | + const help = spawnSync(process.execPath, [link, "--help"], { |
| 18 | + encoding: "utf8" |
| 19 | + }); |
| 20 | + expect(help.status).toBe(0); |
| 21 | + expect(help.stdout).toContain("Chart Kit documentation CLI"); |
| 22 | + const invalid = spawnSync(process.execPath, [link, "unknown"], { |
| 23 | + encoding: "utf8" |
| 24 | + }); |
| 25 | + expect(invalid.status).toBe(1); |
| 26 | + expect(JSON.parse(invalid.stderr).error.code).toBe("INVALID_ARGUMENT"); |
| 27 | + } finally { |
| 28 | + rmSync(directory, { recursive: true, force: true }); |
| 29 | + } |
| 30 | + }); |
| 31 | +}); |
0 commit comments