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

Commit d042898

Browse files
committed
test: adds reporter tests to modules
1 parent 61a44b8 commit d042898

File tree

4 files changed

+176
-19
lines changed

4 files changed

+176
-19
lines changed

__tests__/increment.spec.js

Lines changed: 66 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,6 @@ describe("runIncrement()", () => {
8282
)
8383
})
8484

85-
it("prints write command if dry run and verbose", async () => {
86-
// Given
87-
const dryConfig = { ...config, verbose: true, dryRun: true }
88-
// When
89-
await runIncrement(dryConfig, entryOne)
90-
// Then
91-
expect(report).toBeCalled()
92-
})
93-
94-
it("prints write command if verbose", async () => {
95-
// Given
96-
const verbConfig = { ...config, verbose: true }
97-
// When
98-
await runIncrement(verbConfig, entryOne)
99-
// Then
100-
expect(report).toBeCalled()
101-
})
102-
10385
it("does not write to package.json if dry run", async () => {
10486
// Given
10587
const dryConfig = { ...config, dryRun: true }
@@ -135,4 +117,70 @@ describe("runIncrement()", () => {
135117
expect(exitWithError).toBeCalled()
136118
})
137119
})
120+
121+
describe("reports", () => {
122+
beforeEach(() => {
123+
fs.writeFileSync = jest.fn()
124+
})
125+
126+
afterEach(() => {
127+
fs.writeFileSync.mockRestore()
128+
})
129+
130+
it("reports write command if dry run and verbose", async () => {
131+
// Given
132+
const dryConfig = { ...config, verbose: true, dryRun: true }
133+
// When
134+
await runIncrement(dryConfig, entryOne)
135+
// Then
136+
expect(report).toBeCalledWith(
137+
expect.objectContaining({
138+
m: `fs.writeFileSync(path.resolve(dir, "package.json"), newPkgJson, "utf8")`,
139+
type: "info",
140+
indent: true,
141+
})
142+
)
143+
})
144+
145+
it("reports write command if verbose", async () => {
146+
// Given
147+
const verbConfig = { ...config, verbose: true }
148+
// When
149+
await runIncrement(verbConfig, entryOne)
150+
// Then
151+
expect(report).toBeCalledWith(
152+
expect.objectContaining({
153+
m: `fs.writeFileSync(path.resolve(dir, "package.json"), newPkgJson, "utf8")`,
154+
type: "info",
155+
indent: true,
156+
})
157+
)
158+
})
159+
160+
it("reports start", async () => {
161+
// When
162+
await runIncrement(config, entryTwo)
163+
// Then
164+
expect(report).toBeCalledWith(
165+
expect.objectContaining({
166+
m: "Version",
167+
type: "start",
168+
indent: true,
169+
})
170+
)
171+
})
172+
173+
it("reports success", async () => {
174+
// When
175+
await runIncrement(config, entryTwo)
176+
// Then
177+
expect(report).toBeCalledWith(
178+
expect.objectContaining({
179+
m: "Version successful",
180+
type: "succeed",
181+
indent: true,
182+
})
183+
)
184+
})
185+
})
138186
})

__tests__/initialize.spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import "./mocks.js"
22
import { normalizeConfig } from "../bin/helpers/normalize-config.js"
3+
import { report } from "../bin/helpers/reporter.js"
34
import { checkUnstaged, checkRefStatus } from "../bin/helpers/git-helpers.js"
45
import { initialize } from "../bin/modules/initialize"
56

7+
jest.mock("../bin/helpers/reporter.js", () => ({
8+
report: jest.fn(),
9+
}))
610
jest.mock("../bin/helpers/normalize-config.js", () => ({
711
normalizeConfig: jest.fn(),
812
}))
@@ -46,4 +50,30 @@ describe("initialize()", () => {
4650
expect(checkUnstaged).not.toBeCalled()
4751
expect(checkRefStatus).not.toBeCalled()
4852
})
53+
54+
describe("reports", () => {
55+
it("reports start", async () => {
56+
// When
57+
await initialize({ git: { skipChecks: true } })
58+
// Then
59+
expect(report).toBeCalledWith(
60+
expect.objectContaining({
61+
m: "Preparing to release",
62+
type: "start",
63+
})
64+
)
65+
})
66+
67+
it("reports success", async () => {
68+
// When
69+
await initialize({ git: { skipChecks: true } })
70+
// Then
71+
expect(report).toBeCalledWith(
72+
expect.objectContaining({
73+
m: "Ready to release!",
74+
type: "succeed",
75+
})
76+
)
77+
})
78+
})
4979
})

__tests__/npm.spec.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import "./mocks.js"
22
import path from "path"
3+
import { report } from "../bin/helpers/reporter.js"
34
import { runNpm } from "../bin/modules/npm.js"
45
import { runIncrement } from "../bin/modules/increment.js"
56
import { runPublish } from "../bin/modules/publish.js"
67

8+
jest.mock("../bin/helpers/reporter.js", () => ({
9+
report: jest.fn(),
10+
}))
711
jest.mock("../bin/modules/increment.js", () => ({
812
runIncrement: jest.fn(),
913
}))
10-
1114
jest.mock("../bin/modules/publish.js", () => ({
1215
runPublish: jest.fn(),
1316
}))
@@ -72,4 +75,35 @@ describe("runNpm()", () => {
7275
// Then
7376
expect(runPublish).not.toBeCalled()
7477
})
78+
79+
describe("report", () => {
80+
it("reports for each package", async () => {
81+
// When
82+
await runNpm(config)
83+
// Then
84+
for (const pkg of config.packages) {
85+
expect(report).toBeCalledWith(
86+
expect.objectContaining({
87+
m: {
88+
text: `${pkg.name}@${config.releaseVersion}`,
89+
symbol: "📦",
90+
},
91+
type: "stopAndPersist",
92+
})
93+
)
94+
}
95+
})
96+
97+
it("reports success", async () => {
98+
// When
99+
await runNpm(config)
100+
// Then
101+
expect(report).toBeCalledWith(
102+
expect.objectContaining({
103+
m: "All packages versioned/published without errors",
104+
type: "succeed",
105+
})
106+
)
107+
})
108+
})
75109
})

__tests__/publish.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ import "./mocks.js"
22
import path from "path"
33
import { getAddCommand, getPublishCommand } from "../bin/helpers/commands.js"
44
import { cmd } from "../bin/helpers/cmd.js"
5+
import { report } from "../bin/helpers/reporter.js"
56
import { runPublish } from "../bin/modules/publish.js"
67

78
jest.mock("../bin/helpers/cmd.js", () => ({
89
cmd: jest.fn(),
910
}))
11+
jest.mock("../bin/helpers/reporter.js", () => ({
12+
report: jest.fn(),
13+
}))
1014

1115
const entry = {
1216
name: "@test/one",
@@ -109,4 +113,45 @@ describe("runPublish()", () => {
109113
true
110114
)
111115
})
116+
117+
describe("report", () => {
118+
it("reports start", async () => {
119+
// When
120+
await runPublish(baseConfig, entry)
121+
// Then
122+
expect(report).toBeCalledWith(
123+
expect.objectContaining({
124+
m: "Publish",
125+
type: "start",
126+
indent: true,
127+
})
128+
)
129+
})
130+
131+
it("reports private publish skipped", async () => {
132+
// When
133+
await runPublish(baseConfig, privateEntry)
134+
// Then
135+
expect(report).toBeCalledWith(
136+
expect.objectContaining({
137+
m: "Publish skipped (private)",
138+
type: "succeed",
139+
indent: true,
140+
})
141+
)
142+
})
143+
144+
it("reports publish success", async () => {
145+
// When
146+
await runPublish(baseConfig, entry)
147+
// Then
148+
expect(report).toBeCalledWith(
149+
expect.objectContaining({
150+
m: "Publish successful",
151+
type: "succeed",
152+
indent: true,
153+
})
154+
)
155+
})
156+
})
112157
})

0 commit comments

Comments
 (0)