|
| 1 | +import { describe, expect, it, vi } from "vitest"; |
| 2 | + |
| 3 | +import { removeDependencies } from "./packages.js"; |
| 4 | + |
| 5 | +const mockExecaCommand = vi.fn(); |
| 6 | + |
| 7 | +vi.mock("execa", () => ({ |
| 8 | + get execaCommand() { |
| 9 | + return mockExecaCommand; |
| 10 | + }, |
| 11 | +})); |
| 12 | + |
| 13 | +describe("removeDependencies", () => { |
| 14 | + it("removes all packages that already exist when all already exist", async () => { |
| 15 | + await removeDependencies(["one", "two"], { |
| 16 | + one: "1.2.3", |
| 17 | + two: "4.5.6", |
| 18 | + }); |
| 19 | + |
| 20 | + expect(mockExecaCommand.mock.calls).toMatchInlineSnapshot(` |
| 21 | + [ |
| 22 | + [ |
| 23 | + "pnpm remove one two", |
| 24 | + ], |
| 25 | + ] |
| 26 | + `); |
| 27 | + }); |
| 28 | + |
| 29 | + it("removes only packages that already exist when some don't exist", async () => { |
| 30 | + await removeDependencies(["exists", "missing"], { |
| 31 | + exists: "1.2.3", |
| 32 | + }); |
| 33 | + |
| 34 | + expect(mockExecaCommand.mock.calls).toMatchInlineSnapshot(` |
| 35 | + [ |
| 36 | + [ |
| 37 | + "pnpm remove exists", |
| 38 | + ], |
| 39 | + ] |
| 40 | + `); |
| 41 | + }); |
| 42 | + |
| 43 | + it("adds a flag to removing packages when one is provided", async () => { |
| 44 | + await removeDependencies( |
| 45 | + ["exists", "missing"], |
| 46 | + { |
| 47 | + exists: "1.2.3", |
| 48 | + }, |
| 49 | + "-D", |
| 50 | + ); |
| 51 | + |
| 52 | + expect(mockExecaCommand.mock.calls).toMatchInlineSnapshot(` |
| 53 | + [ |
| 54 | + [ |
| 55 | + "pnpm remove exists -D", |
| 56 | + ], |
| 57 | + ] |
| 58 | + `); |
| 59 | + }); |
| 60 | + |
| 61 | + it("does nothing when no packages already exist", async () => { |
| 62 | + await removeDependencies(["missing"]); |
| 63 | + |
| 64 | + expect(mockExecaCommand.mock.calls).toMatchInlineSnapshot("[]"); |
| 65 | + }); |
| 66 | +}); |
0 commit comments