Skip to content

Commit 749179f

Browse files
committed
feat(cli): json output
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent f98bc04 commit 749179f

File tree

93 files changed

+1472
-705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1472
-705
lines changed

.eslintrc.base.cjs

+6
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,12 @@ const config = {
884884
'@typescript-eslint/no-redundant-type-constituents': 0
885885
}
886886
},
887+
{
888+
files: '**/*.abstract.ts',
889+
rules: {
890+
'@typescript-eslint/no-useless-constructor': 0
891+
}
892+
},
887893
{
888894
files: ['**/decorators/*.constraint.ts', '**/*.decorator.ts'],
889895
rules: {

.github/ISSUE_TEMPLATE/bug.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ body:
5454
type: textarea
5555
attributes:
5656
label: Environment info
57-
description: Output of `grease info -p <package-manager>`
57+
description: Output of `grease info -jp <package-manager>`
5858
render: jsonc
5959
validations:
6060
required: true

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"dependencies": {
9494
"@flex-development/aggregate-error-ponyfill": "3.1.1",
9595
"@flex-development/commitlint-config": "1.0.1",
96+
"@flex-development/errnode": "2.0.0",
9697
"@flex-development/mkbuild": "1.0.0-alpha.23",
9798
"@flex-development/mlly": "1.0.0-alpha.18",
9899
"@flex-development/pathe": "2.0.0",
@@ -184,8 +185,7 @@
184185
"chai": "5.0.0-alpha.1"
185186
},
186187
"engines": {
187-
"node": ">=16.20.0 <20.6.0 || >20.6.0",
188-
"yarn": "4.0.0-rc.50"
188+
"node": ">=16.20.0 <20.6.0 || >20.6.0"
189189
},
190190
"packageManager": "[email protected]",
191191
"readme": "README.md",

src/__snapshots__/grease.service.snap

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3-
exports[`unit:GreaseService > #bump > should return package manifest 1`] = `
3+
exports[`unit:GreaseService > #bump > should return bump version 1`] = `
44
{
5-
"name": "premajor",
5+
"build": [],
6+
"major": 3,
7+
"minor": 0,
8+
"patch": 0,
9+
"prerelease": [
10+
"rc",
11+
1,
12+
],
613
"version": "3.0.0-rc.1",
714
}
815
`;
916

1017
exports[`unit:GreaseService > #recommend > should return recommended version bump 1`] = `
11-
RecommendedBump {
18+
{
1219
"breaks": 1,
13-
"bump": "major",
20+
"bump": "premajor",
1421
"commits": 72,
1522
"features": 16,
23+
"unstable": true,
1624
}
1725
`;
1826

src/__tests__/grease.service.spec.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ConfigModule } from '#src/config'
1919
import { ReleaseType } from '#src/enums'
2020
import { GitModule, GitService, TagOperation } from '#src/git'
2121
import { LogModule } from '#src/log'
22-
import { PackageManifest } from '#src/models'
22+
import { Version } from '#src/models'
2323
import { set } from '@flex-development/tutils'
2424
import { CqrsModule } from '@nestjs/cqrs'
2525
import { Test } from '@nestjs/testing'
@@ -58,13 +58,13 @@ describe('unit:GreaseService', () => {
5858
}
5959
})
6060

61-
it('should return package manifest', async () => {
61+
it('should return bump version', async () => {
6262
// Act
6363
const result = await subject.bump(operation)
6464

6565
// Expect
66-
expect(result).to.be.instanceof(PackageManifest)
67-
expect(result.pkg).toMatchSnapshot()
66+
expect(result).to.be.instanceof(Version)
67+
expect(result).toMatchSnapshot()
6868
})
6969
})
7070

@@ -101,7 +101,8 @@ describe('unit:GreaseService', () => {
101101
// Act
102102
const result = await subject.recommend({
103103
tagprefix: gc.tagprefix,
104-
to: sha
104+
to: sha,
105+
unstable: true
105106
})
106107

107108
// Expect

src/cli/commands/__tests__/bump.command.functional.spec.ts

+113-6
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,104 @@
33
* @module grease/cli/commands/tests/functional/BumpCommand
44
*/
55

6+
import { RecommendedBump } from '#src/bump'
67
import { ReleaseType } from '#src/enums'
78
import GreaseService from '#src/grease.service'
9+
import { LogObject, LoggerService } from '#src/log'
10+
import { Version } from '#src/models'
811
import type { ReleaseVersion } from '#src/types'
912
import type { Mock } from '#tests/interfaces'
1013
import { CliUtilityService } from '@flex-development/nest-commander'
1114
import { CommandTestFactory } from '@flex-development/nest-commander/testing'
1215
import type { TestingModule } from '@nestjs/testing'
1316
import TestSubject from '../bump.command'
17+
import GreaseCommand from '../grease.command'
1418

1519
describe('functional:cli/commands/BumpCommand', () => {
1620
let args: ['bump', ReleaseVersion]
1721
let bump: Mock<GreaseService['bump']>
1822
let command: TestingModule
23+
let debug: Mock<LoggerService['debug']>
24+
let log: Mock<LoggerService['log']>
1925
let recommend: Mock<GreaseService['recommend']>
26+
let success: Mock<LoggerService['success']>
2027

2128
beforeAll(() => {
2229
args = ['bump', ReleaseType.PREMAJOR]
2330
})
2431

2532
beforeEach(async () => {
2633
command = await CommandTestFactory.createTestingCommand({
34+
positional: false,
2735
providers: [
2836
CliUtilityService,
37+
GreaseCommand,
38+
LoggerService,
2939
TestSubject,
3040
{
3141
provide: GreaseService,
3242
useValue: {
33-
bump: bump = vi.fn().mockName('GreaseService#bump'),
34-
recommend: recommend = vi.fn().mockName('GreaseService#recommend')
43+
bump: bump = vi
44+
.fn()
45+
.mockReturnValue(new Version(faker.system.semver()))
46+
.mockName('GreaseService#bump'),
47+
config: vi
48+
.fn()
49+
.mockReturnValue({})
50+
.mockName('GreaseService#config'),
51+
recommend: recommend = vi
52+
.fn()
53+
.mockReturnValue(new RecommendedBump({
54+
breaks: 1,
55+
commits: 72,
56+
features: 16,
57+
unstable: true
58+
}))
59+
.mockName('GreaseService#recommend')
60+
}
61+
},
62+
{
63+
provide: LoggerService,
64+
useValue: {
65+
debug: debug = vi.fn().mockName('LoggerService#debug'),
66+
log: log = vi.fn().mockName('LoggerService#log'),
67+
success: success = vi.fn().mockName('LoggerService#success'),
68+
withTag: vi.fn().mockReturnValue({
69+
debug,
70+
log,
71+
success,
72+
sync: vi.fn().mockName('LoggerService#sync')
73+
})
3574
}
3675
}
3776
]
3877
})
3978
})
4079

80+
describe('--json, -j', () => {
81+
it('should parse flag', async () => {
82+
// Act
83+
await CommandTestFactory.run(command, [...args, '--json'])
84+
85+
// Expect
86+
expect(log).toHaveBeenCalledOnce()
87+
expect(log).toHaveBeenCalledWith(expect.any(LogObject))
88+
expect(debug).not.toHaveBeenCalled()
89+
expect(success).not.toHaveBeenCalled()
90+
})
91+
92+
it('should parse short flag', async () => {
93+
// Act
94+
await CommandTestFactory.run(command, [...args, '-j'])
95+
96+
// Expect
97+
expect(log).toHaveBeenCalledOnce()
98+
expect(log).toHaveBeenCalledWith(expect.any(LogObject))
99+
expect(debug).not.toHaveBeenCalled()
100+
expect(success).not.toHaveBeenCalled()
101+
})
102+
})
103+
41104
describe('--preid <id>', () => {
42105
let preid: string
43106

@@ -52,6 +115,9 @@ describe('functional:cli/commands/BumpCommand', () => {
52115
// Expect
53116
expect(bump).toHaveBeenCalledOnce()
54117
expect(bump.mock.lastCall?.[0]).to.have.property('preid', preid)
118+
expect(success).toHaveBeenCalledOnce()
119+
expect(debug).not.toHaveBeenCalled()
120+
expect(log).not.toHaveBeenCalled()
55121
})
56122
})
57123

@@ -69,6 +135,9 @@ describe('functional:cli/commands/BumpCommand', () => {
69135
// Expect
70136
expect(bump).toHaveBeenCalledOnce()
71137
expect(bump.mock.lastCall?.[0]).to.have.property('prestart', prestart)
138+
expect(success).toHaveBeenCalledOnce()
139+
expect(debug).not.toHaveBeenCalled()
140+
expect(log).not.toHaveBeenCalled()
72141
})
73142
})
74143

@@ -80,6 +149,9 @@ describe('functional:cli/commands/BumpCommand', () => {
80149
// Expect
81150
expect(recommend).toHaveBeenCalledOnce()
82151
expect(recommend).toHaveBeenCalledWith(expect.any(Object))
152+
expect(log).toHaveBeenCalledOnce()
153+
expect(debug).toHaveBeenCalledTimes(3)
154+
expect(success).not.toHaveBeenCalled()
83155
})
84156

85157
it('should parse short flag', async () => {
@@ -89,26 +161,61 @@ describe('functional:cli/commands/BumpCommand', () => {
89161
// Expect
90162
expect(recommend).toHaveBeenCalledOnce()
91163
expect(recommend).toHaveBeenCalledWith(expect.any(Object))
164+
expect(log).toHaveBeenCalledOnce()
165+
expect(debug).toHaveBeenCalledTimes(3)
166+
expect(success).not.toHaveBeenCalled()
167+
})
168+
})
169+
170+
describe('--unstable, -u', () => {
171+
it('should parse flag', async () => {
172+
// Act
173+
await CommandTestFactory.run(command, [args[0], '-r', '--unstable'])
174+
175+
// Expect
176+
expect(recommend).toHaveBeenCalledOnce()
177+
expect(recommend.mock.lastCall?.[0]).to.have.property('unstable').be.true
178+
expect(log).toHaveBeenCalledOnce()
179+
expect(debug).toHaveBeenCalledTimes(3)
180+
expect(success).not.toHaveBeenCalled()
181+
})
182+
183+
it('should parse short flag', async () => {
184+
// Act
185+
await CommandTestFactory.run(command, [args[0], '-r', '-u'])
186+
187+
// Expect
188+
expect(recommend).toHaveBeenCalledOnce()
189+
expect(recommend.mock.lastCall?.[0]).to.have.property('unstable').be.true
190+
expect(log).toHaveBeenCalledOnce()
191+
expect(debug).toHaveBeenCalledTimes(3)
192+
expect(success).not.toHaveBeenCalled()
92193
})
93194
})
94195

95-
describe('--write, -w [choice]', () => {
196+
describe('--write, -w', () => {
96197
it('should parse flag', async () => {
97198
// Act
98199
await CommandTestFactory.run(command, [...args, '--write'])
99200

100201
// Expect
101202
expect(bump).toHaveBeenCalledOnce()
102-
expect(bump.mock.lastCall?.[0]).to.have.property('write', true)
203+
expect(bump.mock.lastCall?.[0]).to.have.property('write').be.true
204+
expect(success).toHaveBeenCalledOnce()
205+
expect(debug).not.toHaveBeenCalled()
206+
expect(log).not.toHaveBeenCalled()
103207
})
104208

105209
it('should parse short flag', async () => {
106210
// Act
107-
await CommandTestFactory.run(command, [...args, '-w', 'n'])
211+
await CommandTestFactory.run(command, [...args, '-w'])
108212

109213
// Expect
110214
expect(bump).toHaveBeenCalledOnce()
111-
expect(bump.mock.lastCall?.[0]).to.have.property('write', false)
215+
expect(bump.mock.lastCall?.[0]).to.have.property('write').be.true
216+
expect(success).toHaveBeenCalledOnce()
217+
expect(debug).not.toHaveBeenCalled()
218+
expect(log).not.toHaveBeenCalled()
112219
})
113220
})
114221
})

src/cli/commands/__tests__/changelog.command.functional.spec.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import GreaseService from '#src/grease.service'
88
import type { Mock } from '#tests/interfaces'
99
import { CliUtilityService } from '@flex-development/nest-commander'
1010
import { CommandTestFactory } from '@flex-development/nest-commander/testing'
11+
import { constant } from '@flex-development/tutils'
1112
import type { TestingModule } from '@nestjs/testing'
1213
import TestSubject from '../changelog.command'
14+
import GreaseCommand from '../grease.command'
1315

1416
describe('functional:cli/commands/ChangelogCommand', () => {
1517
let args: ['changelog']
@@ -22,13 +24,16 @@ describe('functional:cli/commands/ChangelogCommand', () => {
2224

2325
beforeEach(async () => {
2426
command = await CommandTestFactory.createTestingCommand({
27+
positional: false,
2528
providers: [
2629
CliUtilityService,
30+
GreaseCommand,
2731
TestSubject,
2832
{
2933
provide: GreaseService,
3034
useValue: {
31-
changelog: changelog = vi.fn().mockName('GreaseService#changelog')
35+
changelog: changelog = vi.fn().mockName('GreaseService#changelog'),
36+
config: vi.fn(constant({})).mockName('GreaseService#config')
3237
}
3338
}
3439
]
@@ -159,6 +164,26 @@ describe('functional:cli/commands/ChangelogCommand', () => {
159164
})
160165
})
161166

167+
describe('--unstable, -u [choice]', () => {
168+
it('should parse flag', async () => {
169+
// Act
170+
await CommandTestFactory.run(command, [...args, '--unstable'])
171+
172+
// Expect
173+
expect(changelog).toHaveBeenCalledOnce()
174+
expect(changelog.mock.lastCall?.[0]).to.have.property('unstable').be.true
175+
})
176+
177+
it('should parse short flag', async () => {
178+
// Act
179+
await CommandTestFactory.run(command, [...args, '-u', '0'])
180+
181+
// Expect
182+
expect(changelog).toHaveBeenCalledOnce()
183+
expect(changelog.mock.lastCall?.[0]).to.have.property('unstable').be.false
184+
})
185+
})
186+
162187
describe('--write, -w', () => {
163188
let write: boolean
164189

src/cli/commands/__tests__/grease.command.functional.spec.ts

-18
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,4 @@ describe('functional:cli/commands/GreaseCommand', () => {
135135
expect(exitOverride).not.toHaveBeenCalled()
136136
})
137137
})
138-
139-
describe('--unstable, -u [choice]', () => {
140-
it('should parse flag', async () => {
141-
// Act
142-
await CommandTestFactory.run(command, ['--unstable=false'])
143-
144-
// Expect
145-
expect(exitOverride).not.toHaveBeenCalled()
146-
})
147-
148-
it('should parse short flag', async () => {
149-
// Act
150-
await CommandTestFactory.run(command, ['-u', '0'])
151-
152-
// Expect
153-
expect(exitOverride).not.toHaveBeenCalled()
154-
})
155-
})
156138
})

0 commit comments

Comments
 (0)