Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions change/beachball-f72ae41e-d073-44c8-913c-699450fe9a0d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"comment": "Add v0-specific change descriptions",
"type": "minor",
"packageName": "beachball",
"email": "elcraig@microsoft.com",
"dependentChangeType": "patch"
}
20 changes: 10 additions & 10 deletions src/__e2e__/change.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('change command', () => {
await waitForPrompt();

// Use default change type and custom message
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
await stdin.sendByChar('\n');
// Also verify that the options shown are correct
expect(stdout.lastOutput()).toMatchInlineSnapshot(`
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('change command', () => {
const options = getOptions();
const changePromise = change(options);

expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
await stdin.sendByChar('\n'); // default change type
await stdin.sendByChar('commit me please\n'); // custom message
await changePromise;
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('change command', () => {
});
const changePromise = change(options);

expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
await stdin.sendByChar('\n'); // default change type
await stdin.sendByChar('commit me please\n'); // custom message
await changePromise;
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('change command', () => {
const changePromise = change(options);
await waitForPrompt();

expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
await stdin.sendByChar('\n'); // default change type
await stdin.sendByChar('stage me please\n'); // custom message
await changePromise;
Expand All @@ -218,7 +218,7 @@ describe('change command', () => {
const changePromise = change(options);

// use custom values for first package
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-1');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-1 (currently v1.0.0)');
stdin.emitKey({ name: 'down' });
await stdin.sendByChar('\n');
// also verify that the options shown are correct
Expand All @@ -230,7 +230,7 @@ describe('change command', () => {
await stdin.sendByChar('custom\n');

// use defaults for second package
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-2');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-2 (currently v1.0.0)');
await stdin.sendByChar('\n\n');

await changePromise;
Expand Down Expand Up @@ -260,13 +260,13 @@ describe('change command', () => {
const changePromise = change(options);

// use custom values for first package
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-1');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-1 (currently v1.0.0)');
stdin.emitKey({ name: 'down' });
await stdin.sendByChar('\n');
await stdin.sendByChar('custom\n');

// use defaults for second package
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-2');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-2 (currently v1.0.0)');
await stdin.sendByChar('\n\n');

await changePromise;
Expand Down Expand Up @@ -305,13 +305,13 @@ describe('change command', () => {
const changePromise = change(options);
await waitForPrompt();

expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-1');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-1 (currently v1.0.0)');
expect(stdout.lastOutput()).toMatch(/Change type/);
await stdin.sendByChar('\n');
expect(stdout.lastOutput()).toMatch(/Describe changes/);
await stdin.sendByChar('\n');

expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-2');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: pkg-2 (currently v1.0.0)');
expect(stdout.lastOutput()).toMatch(/custom question/);
await stdin.sendByChar('stuff\n');
expect(stdout.lastOutput()).toMatch(/Change type/);
Expand Down
70 changes: 65 additions & 5 deletions src/__tests__/changefile/getQuestionsForPackage.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it, jest } from '@jest/globals';
import prompts from 'prompts';
import { getQuestionsForPackage } from '../../changefile/getQuestionsForPackage';
import { ChangeFilePromptOptions } from '../../types/ChangeFilePrompt';
import { ChangeFilePromptOptions, ChangeTypeDescriptions } from '../../types/ChangeFilePrompt';
import { initMockLogs } from '../../__fixtures__/mockLogs';
import { makePackageInfos } from '../../__fixtures__/packageInfos';

Expand All @@ -28,10 +28,10 @@ describe('getQuestionsForPackage', () => {
expect(questions).toEqual([
{
choices: [
{ title: expect.stringContaining('Patch'), value: 'patch' },
{ title: expect.stringContaining('Minor'), value: 'minor' },
{ title: expect.stringContaining('None'), value: 'none' },
{ title: expect.stringContaining('Major'), value: 'major' },
{ title: ' Patch - bug fixes; no API changes', value: 'patch' },
{ title: ' Minor - new feature; backwards-compatible API changes', value: 'minor' },
{ title: ' None - this change does not affect the published package in any way', value: 'none' },
{ title: ' Major - breaking changes; major feature', value: 'major' },
],
message: 'Change type',
name: 'type',
Expand All @@ -48,6 +48,26 @@ describe('getQuestionsForPackage', () => {
]);
});

it('uses different descriptions for v0 package', () => {
const questions = getQuestionsForPackage({
...defaultQuestionsParams,
packageInfos: makePackageInfos({ [pkg]: { version: '0.1.0' } }),
});
expect(questions![0].choices).toEqual([
{
title:
' Patch - bug fixes; new features; backwards-compatible API changes (ok in patches for version < 1)',
value: 'patch',
},
{
title: ' Minor - breaking changes; major feature (ok in minors for version < 1)',
value: 'minor',
},
{ title: ' None - this change does not affect the published package in any way', value: 'none' },
{ title: ' Major - official release', value: 'major' },
]);
});

// it's somewhat debatable if this is correct (maybe --type should be the override for disallowedChangeTypes?)
it('errors if options.type is disallowed', () => {
const questions = getQuestionsForPackage({
Expand Down Expand Up @@ -163,6 +183,46 @@ describe('getQuestionsForPackage', () => {
);
});

it('uses options.changeTypeDescriptions if set', () => {
const changeTypeDescriptions: ChangeTypeDescriptions = {
major: 'exciting',
minor: { v0: 'exciting v0!', general: 'boring' },
premajor: 'almost exciting',
};
const questions = getQuestionsForPackage({
...defaultQuestionsParams,
packageInfos: makePackageInfos({
[pkg]: { version: '1.0.0', combinedOptions: { changeFilePrompt: { changeTypeDescriptions } } },
}),
});

expect(questions![0].choices).toEqual([
{ title: ' Major - exciting', value: 'major' },
{ title: ' Minor - boring', value: 'minor' },
{ title: ' Premajor - almost exciting', value: 'premajor' },
]);
});

it('uses v0-specific options.changeTypeDescriptions if set', () => {
const changeTypeDescriptions: ChangeTypeDescriptions = {
major: 'exciting',
minor: { v0: 'exciting v0!', general: 'boring' },
premajor: 'almost exciting',
};
const questions = getQuestionsForPackage({
...defaultQuestionsParams,
packageInfos: makePackageInfos({
[pkg]: { version: '0.1.0', combinedOptions: { changeFilePrompt: { changeTypeDescriptions } } },
}),
});

expect(questions![0].choices).toEqual([
{ title: ' Major - exciting', value: 'major' },
{ title: ' Minor - exciting v0!', value: 'minor' },
{ title: ' Premajor - almost exciting', value: 'premajor' },
]);
});

it('does case-insensitive filtering on description suggestions', async () => {
const recentMessages = ['Foo', 'Bar', 'Baz'];
const recentMessageChoices = [{ title: 'Foo' }, { title: 'Bar' }, { title: 'Baz' }];
Expand Down
12 changes: 6 additions & 6 deletions src/__tests__/changefile/promptForChange.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ describe('promptForChange', () => {
await waitForPrompt();

// verify asking for first package
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
// choose custom options for this package
stdin.emitKey({ name: 'down' });
await stdin.sendByChar('\n');
stdin.emitKey({ name: 'down' });
await stdin.sendByChar('\n');

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

Expand Down Expand Up @@ -120,11 +120,11 @@ describe('promptForChange', () => {
await waitForPrompt();

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

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

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

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

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

expect(await changeFilesPromise).toBeUndefined();
Expand Down
Loading