Skip to content
This repository was archived by the owner on Jun 3, 2023. It is now read-only.

Commit 89458ef

Browse files
committed
test: adds tests for top level release.js
1 parent 9a004af commit 89458ef

File tree

16 files changed

+136
-33
lines changed

16 files changed

+136
-33
lines changed

__tests__/commit.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
getPushCmd,
77
} from "../bin/helpers/git-commands.js"
88
import { setVersionToString } from "../bin/helpers/transformers.js"
9-
import { runCommit } from "../bin/commit.js"
109
import { reportCmd } from "../bin/helpers/cmd.js"
10+
import { runCommit } from "../bin/modules/commit.js"
1111

1212
jest.mock("../bin/helpers/cmd.js", () => ({
1313
reportCmd: jest.fn(),

__tests__/increment.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import "./mocks.js"
22
import fs from "fs"
33
import path from "path"
4-
import { runIncrement } from "../bin/increment.js"
54
import { pkgReporter, exitWithError } from "../bin/helpers/reporter.js"
65
import { cmd } from "../bin/helpers/cmd.js"
76
import { getVersionCommand } from "../bin/helpers/npm-commands.js"
7+
import { runIncrement } from "../bin/modules/increment.js"
88

99
jest.mock("../bin/helpers/cmd.js", () => ({
1010
cmd: jest.fn(),

__tests__/initialize.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import "./mocks.js"
2-
import { initialize } from "../bin/initialize"
32
import { normalizeConfig } from "../bin/helpers/normalize-config.js"
43
import { checkUnstaged, checkRefStatus } from "../bin/helpers/git-helpers.js"
4+
import { initialize } from "../bin/modules/initialize"
55

66
jest.mock("../bin/helpers/normalize-config.js", () => ({
77
normalizeConfig: jest.fn(),

__tests__/mocks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ jest.mock("ora", () => () => ({
88
jest.mock("fs")
99
jest.mock("child_process")
1010
jest.mock("util")
11+
jest.mock("yargs")
12+
jest.mock("find-up", () => ({
13+
findUpSync: jest.fn(),
14+
}))

__tests__/npm.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import "./mocks.js"
22
import path from "path"
3-
import { runNpm } from "../bin/npm.js"
4-
import { runIncrement } from "../bin/increment.js"
5-
import { runPublish } from "../bin/publish.js"
3+
import { runNpm } from "../bin/modules/npm.js"
4+
import { runIncrement } from "../bin/modules/increment.js"
5+
import { runPublish } from "../bin/modules/publish.js"
66

7-
jest.mock("../bin/increment.js", () => ({
7+
jest.mock("../bin/modules/increment.js", () => ({
88
runIncrement: jest.fn(),
99
}))
1010

11-
jest.mock("../bin/publish.js", () => ({
11+
jest.mock("../bin/modules/publish.js", () => ({
1212
runPublish: jest.fn(),
1313
}))
1414

__tests__/publish.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import "./mocks.js"
22
import path from "path"
33
import { getAddCommand } from "../bin/helpers/git-commands.js"
4-
import { runPublish } from "../bin/publish.js"
54
import { cmd } from "../bin/helpers/cmd.js"
65
import { pkgReporter } from "../bin/helpers/reporter.js"
76
import { getPublishCommand } from "../bin/helpers/npm-commands.js"
7+
import { runPublish } from "../bin/modules/publish.js"
88

99
jest.mock("../bin/helpers/cmd.js", () => ({
1010
cmd: jest.fn(),

__tests__/release.spec.js

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
})

bin/cli.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
import { release } from "./modules/release.js"
4+
5+
await release()

bin/commit.js renamed to bin/modules/commit.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env node
22

3-
import { ReportSteps } from "./helpers/constants.js"
4-
import { getCommitCmd, getTagCmd, getPushCmd } from "./helpers/git-commands.js"
5-
import { setVersionToString } from "./helpers/transformers.js"
6-
import { reportCmd } from "./helpers/cmd.js"
3+
import { ReportSteps } from "../helpers/constants.js"
4+
import { getCommitCmd, getTagCmd, getPushCmd } from "../helpers/git-commands.js"
5+
import { setVersionToString } from "../helpers/transformers.js"
6+
import { reportCmd } from "../helpers/cmd.js"
77

88
export async function runCommit(config) {
99
const {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
import fs from "fs"
44
import path from "path"
5-
import { exitWithError, pkgReporter } from "./helpers/reporter.js"
6-
import { ROOT_PACKAGE_FILE } from "./helpers/constants.js"
7-
import { cmd } from "./helpers/cmd.js"
8-
import { getVersionCommand } from "./helpers/npm-commands.js"
5+
import { exitWithError, pkgReporter } from "../helpers/reporter.js"
6+
import { ROOT_PACKAGE_FILE } from "../helpers/constants.js"
7+
import { cmd } from "../helpers/cmd.js"
8+
import { getVersionCommand } from "../helpers/npm-commands.js"
99

1010
function getSemverRangePart(version) {
1111
let rangePart = ""

0 commit comments

Comments
 (0)