Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add v0-specific change descriptions #1005

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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": "[email protected]",
"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 @@
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 @@
]);
});

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 @@ -85,7 +105,7 @@
packageInfos: makePackageInfos({ [pkg]: { version: '1.0.0-beta.1' } }),
});
const choices = (questions![0].choices as prompts.Choice[]).map(c => c.value);
expect(choices).toEqual(['prerelease', 'patch', 'minor', 'none', 'major']);

Check failure on line 108 in src/__tests__/changefile/getQuestionsForPackage.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, npm 8)

getQuestionsForPackage › allows prerelease change for package with prerelease version

expect(received).toEqual(expected) // deep equality - Expected - 1 + Received + 0 Array [ - "prerelease", "patch", "minor", "none", "major", ] at Object.<anonymous> (src/__tests__/changefile/getQuestionsForPackage.test.ts:108:21)

Check failure on line 108 in src/__tests__/changefile/getQuestionsForPackage.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, npm 6)

getQuestionsForPackage › allows prerelease change for package with prerelease version

expect(received).toEqual(expected) // deep equality - Expected - 1 + Received + 0 Array [ - "prerelease", "patch", "minor", "none", "major", ] at Object.<anonymous> (src/__tests__/changefile/getQuestionsForPackage.test.ts:108:21)
});

// this is a bit weird as well, but documenting current behavior
Expand Down Expand Up @@ -130,7 +150,7 @@
},
}),
});
expect(questions).toHaveLength(1);

Check failure on line 153 in src/__tests__/changefile/getQuestionsForPackage.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, npm 8)

getQuestionsForPackage › excludes the change type question when prerelease is implicitly the only valid option

expect(received).toHaveLength(expected) Matcher error: received value must have a length property whose value must be a number Received has value: undefined at Object.<anonymous> (src/__tests__/changefile/getQuestionsForPackage.test.ts:153:23)

Check failure on line 153 in src/__tests__/changefile/getQuestionsForPackage.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, npm 6)

getQuestionsForPackage › excludes the change type question when prerelease is implicitly the only valid option

expect(received).toHaveLength(expected) Matcher error: received value must have a length property whose value must be a number Received has value: undefined at Object.<anonymous> (src/__tests__/changefile/getQuestionsForPackage.test.ts:153:23)
expect(questions![0].name).toBe('comment');
});

Expand Down Expand Up @@ -163,6 +183,46 @@
);
});

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([

Check failure on line 199 in src/__tests__/changefile/getQuestionsForPackage.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, npm 8)

getQuestionsForPackage › uses options.changeTypeDescriptions if set

expect(received).toEqual(expected) // deep equality - Expected - 4 + Received + 0 @@ -5,10 +5,6 @@ }, Object { "title": " Minor - boring", "value": "minor", }, - Object { - "title": " Premajor - almost exciting", - "value": "premajor", - }, ] at Object.<anonymous> (src/__tests__/changefile/getQuestionsForPackage.test.ts:199:35)

Check failure on line 199 in src/__tests__/changefile/getQuestionsForPackage.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, npm 6)

getQuestionsForPackage › uses options.changeTypeDescriptions if set

expect(received).toEqual(expected) // deep equality - Expected - 4 + Received + 0 @@ -5,10 +5,6 @@ }, Object { "title": " Minor - boring", "value": "minor", }, - Object { - "title": " Premajor - almost exciting", - "value": "premajor", - }, ] at Object.<anonymous> (src/__tests__/changefile/getQuestionsForPackage.test.ts:199:35)
{ 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([

Check failure on line 219 in src/__tests__/changefile/getQuestionsForPackage.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, npm 8)

getQuestionsForPackage › uses v0-specific options.changeTypeDescriptions if set

expect(received).toEqual(expected) // deep equality - Expected - 4 + Received + 0 @@ -5,10 +5,6 @@ }, Object { "title": " Minor - exciting v0!", "value": "minor", }, - Object { - "title": " Premajor - almost exciting", - "value": "premajor", - }, ] at Object.<anonymous> (src/__tests__/changefile/getQuestionsForPackage.test.ts:219:35)

Check failure on line 219 in src/__tests__/changefile/getQuestionsForPackage.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, npm 6)

getQuestionsForPackage › uses v0-specific options.changeTypeDescriptions if set

expect(received).toEqual(expected) // deep equality - Expected - 4 + Received + 0 @@ -5,10 +5,6 @@ }, Object { "title": " Minor - exciting v0!", "value": "minor", }, - Object { - "title": " Premajor - almost exciting", - "value": "premajor", - }, ] at Object.<anonymous> (src/__tests__/changefile/getQuestionsForPackage.test.ts:219:35)
{ 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
Loading