Skip to content

Commit 8b01729

Browse files
committed
add version
1 parent 2bb973e commit 8b01729

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

src/__tests__/changefile/getQuestionsForPackage.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ describe('getQuestionsForPackage', () => {
5656
expect(questions![0].choices).toEqual([
5757
{
5858
title:
59-
' [1mPatch[22m - bug fixes; new features; backwards-compatible API changes (ok in patches for v0.x packages)',
59+
' [1mPatch[22m - bug fixes; new features; backwards-compatible API changes (ok in patches for version < 1)',
6060
value: 'patch',
6161
},
6262
{
63-
title: ' [1mMinor[22m - breaking changes; major feature (ok in minor versions for v0.x packages)',
63+
title: ' [1mMinor[22m - breaking changes; major feature (ok in minors for version < 1)',
6464
value: 'minor',
6565
},
6666
{ title: ' None - this change does not affect the published package in any way', value: 'none' },

src/__tests__/changefile/promptForChange.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ describe('promptForChange', () => {
8383
await waitForPrompt();
8484

8585
// verify asking for first package
86-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
86+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
8787
// choose custom options for this package
8888
stdin.emitKey({ name: 'down' });
8989
await stdin.sendByChar('\n');
9090
stdin.emitKey({ name: 'down' });
9191
await stdin.sendByChar('\n');
9292

9393
// verify asking for second package
94-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: bar');
94+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: bar (currently v1.0.0)');
9595
// choose defaults
9696
await stdin.sendByChar('\n\n');
9797

@@ -120,11 +120,11 @@ describe('promptForChange', () => {
120120
await waitForPrompt();
121121

122122
// use defaults for first package
123-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
123+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
124124
await stdin.sendByChar('\n\n');
125125

126126
// cancel for second package
127-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: bar');
127+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: bar (currently v1.0.0)');
128128
stdin.emitKey({ name: 'c', ctrl: true });
129129

130130
// nothing is returned
@@ -148,12 +148,12 @@ describe('promptForChange', () => {
148148
await waitForPrompt();
149149

150150
// enter a valid type for foo
151-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
151+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
152152
expect(stdout.getOutput()).toMatch(/enter any type/);
153153
await stdin.sendByChar('patch\n');
154154

155155
// enter an invalid type for bar
156-
expect(logs.mocks.log).toHaveBeenCalledWith('Please describe the changes for: bar');
156+
expect(logs.mocks.log).toHaveBeenCalledWith('Please describe the changes for: bar (currently v1.0.0)');
157157
await stdin.sendByChar('invalid\n');
158158

159159
expect(await changeFilesPromise).toBeUndefined();

src/__tests__/changefile/promptForChange_promptForPackageChange.test.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ describe('promptForChange _promptForPackageChange', () => {
4343
expect.objectContaining({ name: 'comment', type: 'autocomplete' }),
4444
];
4545

46+
/** Info for the default package used in tests */
47+
const pkgInfo = defaultQuestionsParams.packageInfos[pkg];
48+
4649
/** Wait for the prompt to finish rendering (simulates real user input) */
4750
const waitForPrompt = () => new Promise(resolve => process.nextTick(resolve));
4851

@@ -61,7 +64,7 @@ describe('promptForChange _promptForPackageChange', () => {
6164
});
6265

6366
it('returns an empty object and logs nothing if there are no questions', async () => {
64-
const answers = await _promptForPackageChange([], pkg);
67+
const answers = await _promptForPackageChange([], pkgInfo);
6568
expect(answers).toEqual({});
6669
expect(logs.mocks.log).not.toHaveBeenCalled();
6770
});
@@ -70,13 +73,15 @@ describe('promptForChange _promptForPackageChange', () => {
7073
const questions = getQuestionsForPackage(defaultQuestionsParams);
7174
expect(questions).toEqual(expectedQuestions);
7275

73-
const answersPromise = _promptForPackageChange(questions!, pkg);
76+
const answersPromise = _promptForPackageChange(questions!, pkgInfo);
7477

7578
// input: press enter twice to use defaults (with a pause in between to simulate real user input)
7679
await stdin.sendByChar('\n\n');
7780
const answers = await answersPromise;
7881

79-
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`"Please describe the changes for: foo"`);
82+
expect(logs.getMockLines('log')).toMatchInlineSnapshot(
83+
`"Please describe the changes for: foo (currently v1.0.0)"`
84+
);
8085
expect(stdout.getOutput()).toMatchInlineSnapshot(`
8186
"? Change type » - Use arrow-keys. Return to submit.
8287
> Patch - bug fixes; no API changes
@@ -99,7 +104,7 @@ describe('promptForChange _promptForPackageChange', () => {
99104
});
100105
expect(questions).toEqual(expectedQuestions.slice(1));
101106

102-
const answerPromise = _promptForPackageChange(questions!, pkg);
107+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
103108
await waitForPrompt();
104109
expect(stdout.lastOutput()).toMatchInlineSnapshot(`
105110
"? Describe changes (type or choose one) »
@@ -112,7 +117,9 @@ describe('promptForChange _promptForPackageChange', () => {
112117
await stdin.sendByChar('abc\n');
113118
const answers = await answerPromise;
114119

115-
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`"Please describe the changes for: foo"`);
120+
expect(logs.getMockLines('log')).toMatchInlineSnapshot(
121+
`"Please describe the changes for: foo (currently v1.0.0)"`
122+
);
116123
expect(stdout.getOutput()).toMatchInlineSnapshot(`
117124
"? Describe changes (type or choose one) » a
118125
? Describe changes (type or choose one) » ab
@@ -130,7 +137,7 @@ describe('promptForChange _promptForPackageChange', () => {
130137
});
131138
expect(questions).toEqual(expectedQuestions.slice(1));
132139

133-
const answerPromise = _promptForPackageChange(questions!, pkg);
140+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
134141
await waitForPrompt();
135142
expect(stdout.lastOutput()).toMatchInlineSnapshot(`
136143
"? Describe changes (type or choose one) »
@@ -144,7 +151,9 @@ describe('promptForChange _promptForPackageChange', () => {
144151
await stdin.sendByChar('\n');
145152
const answers = await answerPromise;
146153

147-
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`"Please describe the changes for: foo"`);
154+
expect(logs.getMockLines('log')).toMatchInlineSnapshot(
155+
`"Please describe the changes for: foo (currently v1.0.0)"`
156+
);
148157
expect(stdout.getOutput()).toMatchInlineSnapshot(`
149158
"? Describe changes (type or choose one) » abc
150159
√ Describe changes (type or choose one) » abc"
@@ -160,7 +169,7 @@ describe('promptForChange _promptForPackageChange', () => {
160169
});
161170
expect(questions).toEqual(expectedQuestions.slice(1));
162171

163-
const answerPromise = _promptForPackageChange(questions!, pkg);
172+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
164173
await waitForPrompt();
165174
expect(stdout.lastOutput()).toMatchInlineSnapshot(`
166175
"? Describe changes (type or choose one) »
@@ -173,7 +182,9 @@ describe('promptForChange _promptForPackageChange', () => {
173182
stdin.send('abc\n');
174183
const answers = await answerPromise;
175184

176-
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`"Please describe the changes for: foo"`);
185+
expect(logs.getMockLines('log')).toMatchInlineSnapshot(
186+
`"Please describe the changes for: foo (currently v1.0.0)"`
187+
);
177188
expect(stdout.getOutput()).toMatchInlineSnapshot(`""`);
178189
expect(answers).toEqual({ comment: 'abc' });
179190
});
@@ -183,7 +194,7 @@ describe('promptForChange _promptForPackageChange', () => {
183194
const questions = getQuestionsForPackage({ ...defaultQuestionsParams, recentMessages });
184195
expect(questions).toEqual(expectedQuestions);
185196

186-
const answerPromise = _promptForPackageChange(questions!, pkg);
197+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
187198

188199
// arrow down to select the third type
189200
stdin.emitKey({ name: 'down' });
@@ -233,7 +244,7 @@ describe('promptForChange _promptForPackageChange', () => {
233244
});
234245
expect(questions).toEqual(expectedQuestions.slice(1));
235246

236-
const answerPromise = _promptForPackageChange(questions!, pkg);
247+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
237248

238249
// type "ba" and press enter to select "bar"
239250
await stdin.sendByChar('ba\n');
@@ -264,7 +275,7 @@ describe('promptForChange _promptForPackageChange', () => {
264275
});
265276
expect(questions).toEqual(expectedQuestions.slice(1));
266277

267-
const answerPromise = _promptForPackageChange(questions!, pkg);
278+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
268279

269280
// type "b", press backspace to delete it, press enter to select foo
270281
await stdin.sendByChar('b');
@@ -294,7 +305,7 @@ describe('promptForChange _promptForPackageChange', () => {
294305
const questions = getQuestionsForPackage(defaultQuestionsParams);
295306
expect(questions).toEqual(expectedQuestions);
296307

297-
const answerPromise = _promptForPackageChange(questions!, pkg);
308+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
298309

299310
// answer the first question
300311
await stdin.sendByChar('\n');
@@ -305,7 +316,7 @@ describe('promptForChange _promptForPackageChange', () => {
305316
const answers = await answerPromise;
306317

307318
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`
308-
"Please describe the changes for: foo
319+
"Please describe the changes for: foo (currently v1.0.0)
309320
Cancelled, no change files are written"
310321
`);
311322

src/changefile/promptForChange.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import prompts from 'prompts';
22
import { ChangeFileInfo, ChangeType } from '../types/ChangeInfo';
33
import { BeachballOptions } from '../types/BeachballOptions';
44
import { isValidChangeType } from '../validation/isValidChangeType';
5-
import { PackageGroups, PackageInfos } from '../types/PackageInfo';
5+
import { PackageGroups, PackageInfo, PackageInfos } from '../types/PackageInfo';
66
import { getQuestionsForPackage } from './getQuestionsForPackage';
77

88
type ChangePromptResponse = { type?: ChangeType; comment?: string };
@@ -19,7 +19,7 @@ export async function promptForChange(params: {
1919
email: string | null;
2020
options: Pick<BeachballOptions, 'message' | 'type' | 'dependentChangeType'>;
2121
}): Promise<ChangeFileInfo[] | undefined> {
22-
const { changedPackages, email, options } = params;
22+
const { changedPackages, packageInfos, email, options } = params;
2323
if (!changedPackages.length) {
2424
return;
2525
}
@@ -43,7 +43,7 @@ export async function promptForChange(params: {
4343
// Now prompt for each package
4444
const packageChangeInfo: ChangeFileInfo[] = [];
4545
for (let pkg of changedPackages) {
46-
const response = await _promptForPackageChange(packageQuestions[pkg], pkg);
46+
const response = await _promptForPackageChange(packageQuestions[pkg], packageInfos[pkg]);
4747
if (!response) {
4848
return; // user cancelled
4949
}
@@ -64,7 +64,7 @@ export async function promptForChange(params: {
6464
*/
6565
export async function _promptForPackageChange(
6666
questions: prompts.PromptObject[],
67-
pkg: string
67+
pkg: PackageInfo
6868
): Promise<ChangePromptResponse | undefined> {
6969
if (!questions.length) {
7070
// This MUST return an empty object rather than nothing, because returning nothing means the
@@ -73,7 +73,7 @@ export async function _promptForPackageChange(
7373
}
7474

7575
console.log('');
76-
console.log(`Please describe the changes for: ${pkg}`);
76+
console.log(`Please describe the changes for: ${pkg.name} (currently v${pkg.version})`);
7777

7878
let isCancelled = false;
7979
const onCancel = () => {

0 commit comments

Comments
 (0)