Skip to content

Commit 781362a

Browse files
committed
feat(cli): ChangelogCommand
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 8db3a7e commit 781362a

15 files changed

+796
-190
lines changed

.github/workflows/release.yml

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ jobs:
4949
outputs:
5050
prerelease: ${{ steps.dist-tag.outputs.prerelease }}
5151
tag: ${{ steps.tag.outputs.result }}
52-
version: ${{ steps.version.outputs.result }}
5352
steps:
5453
- id: debug
5554
name: Print environment variables and event payload

CHANGELOG.md

+212-130
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
/**
2+
* @file Functional Tests - ChangelogCommand
3+
* @module grease/cli/commands/tests/functional/ChangelogCommand
4+
*/
5+
6+
import to from '#fixtures/git/grease/sha'
7+
import GreaseService from '#src/grease.service'
8+
import type { Mock } from '#tests/interfaces'
9+
import { CliUtilityService } from '@flex-development/nest-commander'
10+
import { CommandTestFactory } from '@flex-development/nest-commander/testing'
11+
import type { TestingModule } from '@nestjs/testing'
12+
import TestSubject from '../changelog.command'
13+
14+
describe('functional:cli/commands/ChangelogCommand', () => {
15+
let args: ['changelog']
16+
let changelog: Mock<GreaseService['changelog']>
17+
let command: TestingModule
18+
19+
beforeAll(() => {
20+
args = ['changelog']
21+
})
22+
23+
beforeEach(async () => {
24+
command = await CommandTestFactory.createTestingCommand({
25+
providers: [
26+
CliUtilityService,
27+
TestSubject,
28+
{
29+
provide: GreaseService,
30+
useValue: {
31+
changelog: changelog = vi.fn().mockName('GreaseService#changelog')
32+
}
33+
}
34+
]
35+
})
36+
37+
vi.stubEnv('GREASE_CONFIG', '0')
38+
})
39+
40+
describe('--infile, -i <path>', () => {
41+
let infile: string
42+
43+
beforeAll(() => {
44+
infile = 'CHANGELOG.md'
45+
})
46+
47+
it('should parse flag', async () => {
48+
// Act
49+
await CommandTestFactory.run(command, [...args, `--infile=${infile}`])
50+
51+
// Expect
52+
expect(changelog).toHaveBeenCalledOnce()
53+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ infile })
54+
})
55+
56+
it('should parse short flag', async () => {
57+
// Act
58+
await CommandTestFactory.run(command, [...args, '-i', infile])
59+
60+
// Expect
61+
expect(changelog).toHaveBeenCalledOnce()
62+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ infile })
63+
})
64+
})
65+
66+
describe('--outfile, -o <outfile>', () => {
67+
let outfile: string
68+
69+
beforeAll(() => {
70+
outfile = 'CHANGELOG.md'
71+
})
72+
73+
it('should parse flag', async () => {
74+
// Act
75+
await CommandTestFactory.run(command, [...args, `--outfile=${outfile}`])
76+
77+
// Expect
78+
expect(changelog).toHaveBeenCalledOnce()
79+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ outfile })
80+
})
81+
82+
it('should parse short flag', async () => {
83+
// Act
84+
await CommandTestFactory.run(command, [...args, '-o', outfile])
85+
86+
// Expect
87+
expect(changelog).toHaveBeenCalledOnce()
88+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ outfile })
89+
})
90+
})
91+
92+
describe('--releases, -r <count>', () => {
93+
let releases: number
94+
95+
beforeAll(() => {
96+
releases = 0
97+
})
98+
99+
it('should parse flag', async () => {
100+
// Act
101+
await CommandTestFactory.run(command, [...args, `--releases=${releases}`])
102+
103+
// Expect
104+
expect(changelog).toHaveBeenCalledOnce()
105+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ releases })
106+
})
107+
108+
it('should parse short flag', async () => {
109+
// Act
110+
await CommandTestFactory.run(command, [...args, '-r', `${releases}`])
111+
112+
// Expect
113+
expect(changelog).toHaveBeenCalledOnce()
114+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ releases })
115+
})
116+
})
117+
118+
describe('--samefile, -s', () => {
119+
let samefile: boolean
120+
121+
beforeAll(() => {
122+
samefile = true
123+
})
124+
125+
it('should parse flag', async () => {
126+
// Act
127+
await CommandTestFactory.run(command, [...args, '--samefile'])
128+
129+
// Expect
130+
expect(changelog).toHaveBeenCalledOnce()
131+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ samefile })
132+
})
133+
134+
it('should parse short flag', async () => {
135+
// Act
136+
await CommandTestFactory.run(command, [...args, '-s'])
137+
138+
// Expect
139+
expect(changelog).toHaveBeenCalledOnce()
140+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ samefile })
141+
})
142+
})
143+
144+
describe('--to, -t <commitish>', () => {
145+
it('should parse flag', async () => {
146+
// Act
147+
await CommandTestFactory.run(command, [...args, `--to=${to}`])
148+
149+
// Expect
150+
expect(changelog).toHaveBeenCalledOnce()
151+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ to })
152+
})
153+
154+
it('should parse short flag', async () => {
155+
// Act
156+
await CommandTestFactory.run(command, [...args, '-t', to])
157+
158+
// Expect
159+
expect(changelog).toHaveBeenCalledOnce()
160+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ to })
161+
})
162+
})
163+
164+
describe('--unstable, -u [choice]', () => {
165+
let unstable: boolean
166+
167+
beforeAll(() => {
168+
unstable = false
169+
})
170+
171+
it('should parse flag', async () => {
172+
// Act
173+
await CommandTestFactory.run(command, [...args, `--unstable=${unstable}`])
174+
175+
// Expect
176+
expect(changelog).toHaveBeenCalledOnce()
177+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ unstable })
178+
})
179+
180+
it('should parse short flag', async () => {
181+
// Act
182+
await CommandTestFactory.run(command, [...args, '-u', '0'])
183+
184+
// Expect
185+
expect(changelog).toHaveBeenCalledOnce()
186+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ unstable })
187+
})
188+
})
189+
190+
describe('--write, -w', () => {
191+
let write: boolean
192+
193+
beforeAll(() => {
194+
write = true
195+
})
196+
197+
it('should parse flag', async () => {
198+
// Act
199+
await CommandTestFactory.run(command, [...args, '--write'])
200+
201+
// Expect
202+
expect(changelog).toHaveBeenCalledOnce()
203+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ write })
204+
})
205+
206+
it('should parse short flag', async () => {
207+
// Act
208+
await CommandTestFactory.run(command, [...args, '-w'])
209+
210+
// Expect
211+
expect(changelog).toHaveBeenCalledOnce()
212+
expect(changelog.mock.lastCall?.[0]).toMatchObject({ write })
213+
})
214+
})
215+
})
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @file Commands - ChangelogCommandOpts
3+
* @module grease/commands/ChangelogCommandOpts
4+
*/
5+
6+
import type { ChangelogOperation } from '#src/changelog'
7+
8+
/**
9+
* Parsed `changelog` command options.
10+
*
11+
* @see {@linkcode ChangelogOperation}
12+
*
13+
* @extends {ChangelogOperation}
14+
*/
15+
interface ChangelogCommandOpts extends ChangelogOperation {}
16+
17+
export type { ChangelogCommandOpts as default }

0 commit comments

Comments
 (0)