|
| 1 | +// Plugin NPM Publish tests cover publish wrapper argument safety. |
| 2 | +import { spawnSync } from "node:child_process"; |
| 3 | +import { describe, expect, it } from "vitest"; |
| 4 | + |
| 5 | +const scriptPath = "scripts/plugin-npm-publish.sh"; |
| 6 | + |
| 7 | +function runPluginPublishWrapper(args: string[]) { |
| 8 | +return spawnSync("bash", [scriptPath, ...args], { |
| 9 | +cwd: process.cwd(), |
| 10 | +encoding: "utf8", |
| 11 | +}); |
| 12 | +} |
| 13 | + |
| 14 | +describe("plugin npm publish wrapper", () => { |
| 15 | +it("prints help before package or npm checks", () => { |
| 16 | +const result = runPluginPublishWrapper(["--help"]); |
| 17 | + |
| 18 | +expect(result.status).toBe(0); |
| 19 | +expect(result.stdout.trim()).toBe( |
| 20 | +"usage: bash scripts/plugin-npm-publish.sh [--dry-run|--pack-dry-run|--publish] <package-dir>", |
| 21 | +); |
| 22 | +expect(result.stderr).toBe(""); |
| 23 | +}); |
| 24 | + |
| 25 | +it("rejects missing mode before package checks", () => { |
| 26 | +const result = runPluginPublishWrapper([]); |
| 27 | + |
| 28 | +expect(result.status).toBe(2); |
| 29 | +expect(result.stdout).toBe(""); |
| 30 | +expect(result.stderr.trim()).toBe( |
| 31 | +"usage: bash scripts/plugin-npm-publish.sh [--dry-run|--pack-dry-run|--publish] <package-dir>", |
| 32 | +); |
| 33 | +}); |
| 34 | + |
| 35 | +it("rejects option-like package dirs before package checks", () => { |
| 36 | +const result = runPluginPublishWrapper(["--dry-run", "--wat"]); |
| 37 | + |
| 38 | +expect(result.status).toBe(2); |
| 39 | +expect(result.stdout).toBe(""); |
| 40 | +expect(result.stderr.trim()).toBe("unexpected plugin npm package-dir option: --wat"); |
| 41 | +}); |
| 42 | + |
| 43 | +it("rejects extra arguments before package checks", () => { |
| 44 | +const result = runPluginPublishWrapper(["--dry-run", "extensions/telegram", "extra"]); |
| 45 | + |
| 46 | +expect(result.status).toBe(2); |
| 47 | +expect(result.stdout).toBe(""); |
| 48 | +expect(result.stderr.trim()).toBe("unexpected plugin npm publish argument: extra"); |
| 49 | +}); |
| 50 | +}); |