|
| 1 | +import "./mocks.js" |
| 2 | +import { getArgs } from "../bin/helpers/get-args.js" |
| 3 | +import { reportCmd } from "../bin/helpers/cmd.js" |
| 4 | +import { setRootVersion } from "../bin/helpers/set-root-version.js" |
| 5 | +import { runNpm } from "../bin/modules/npm.js" |
| 6 | +import { runCommit } from "../bin/modules/commit.js" |
| 7 | +import { release } from "../bin/modules/release.js" |
| 8 | + |
| 9 | +jest.mock("../bin/helpers/get-args.js") |
| 10 | +jest.mock("../bin/helpers/cmd.js", () => ({ |
| 11 | + reportCmd: jest.fn(), |
| 12 | +})) |
| 13 | +jest.mock("../bin/helpers/set-root-version.js", () => ({ |
| 14 | + setRootVersion: jest.fn(), |
| 15 | +})) |
| 16 | +jest.mock("../bin/modules/commit.js", () => ({ |
| 17 | + runCommit: jest.fn(), |
| 18 | +})) |
| 19 | +jest.mock("../bin/modules/initialize.js") |
| 20 | +jest.mock("../bin/modules/npm.js", () => ({ |
| 21 | + runNpm: jest.fn(), |
| 22 | +})) |
| 23 | + |
| 24 | +const baseConfig = { |
| 25 | + npm: { |
| 26 | + increment: true, |
| 27 | + publish: true, |
| 28 | + }, |
| 29 | + hooks: { |
| 30 | + prenpm: "npm test", |
| 31 | + postnpm: "npm test", |
| 32 | + }, |
| 33 | + git: { |
| 34 | + commit: true, |
| 35 | + tag: true, |
| 36 | + }, |
| 37 | +} |
| 38 | + |
| 39 | +describe("release()", () => { |
| 40 | + afterEach(() => { |
| 41 | + getArgs.mockRestore() |
| 42 | + }) |
| 43 | + |
| 44 | + describe("all options", () => { |
| 45 | + beforeEach(() => { |
| 46 | + getArgs.mockImplementation(() => baseConfig) |
| 47 | + }) |
| 48 | + |
| 49 | + it("runs prenpm hook", async () => { |
| 50 | + // When |
| 51 | + await release() |
| 52 | + // Then |
| 53 | + expect(reportCmd).toBeCalledWith( |
| 54 | + baseConfig.hooks.prenpm, |
| 55 | + expect.objectContaining({ |
| 56 | + ...baseConfig, |
| 57 | + step: "Prenpm", |
| 58 | + }) |
| 59 | + ) |
| 60 | + }) |
| 61 | + |
| 62 | + it("runs npm step", async () => { |
| 63 | + // When |
| 64 | + await release() |
| 65 | + // Then |
| 66 | + expect(runNpm).toBeCalled() |
| 67 | + }) |
| 68 | + |
| 69 | + it("runs postnpm hook", async () => { |
| 70 | + // When |
| 71 | + await release() |
| 72 | + // Then |
| 73 | + expect(reportCmd).toBeCalledWith( |
| 74 | + baseConfig.hooks.postnpm, |
| 75 | + expect.objectContaining({ |
| 76 | + ...baseConfig, |
| 77 | + step: "Postnpm", |
| 78 | + }) |
| 79 | + ) |
| 80 | + }) |
| 81 | + |
| 82 | + it("sets root version", async () => { |
| 83 | + // When |
| 84 | + await release() |
| 85 | + // Then |
| 86 | + expect(setRootVersion).toBeCalled() |
| 87 | + }) |
| 88 | + |
| 89 | + it("runs commit step", async () => { |
| 90 | + // When |
| 91 | + await release() |
| 92 | + // Then |
| 93 | + expect(runCommit).toBeCalled() |
| 94 | + }) |
| 95 | + }) |
| 96 | +}) |
0 commit comments