Skip to content
Merged
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
301 changes: 284 additions & 17 deletions src/functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ describe('create-release-branch (functional)', () => {
version: '1.2.3',
directoryPath: 'packages/d',
},
e: {
name: '@scope/e',
version: '0.0.3',
directoryPath: 'packages/e',
},
},
workspaces: {
'.': ['packages/*'],
Expand Down Expand Up @@ -68,11 +63,6 @@ describe('create-release-branch (functional)', () => {
foo: 'bar',
},
});
await environment.updateJsonFileWithinPackage('e', 'package.json', {
scripts: {
foo: 'bar',
},
});

await environment.runTool({
releaseSpecification: {
Expand Down Expand Up @@ -120,13 +110,6 @@ describe('create-release-branch (functional)', () => {
version: '1.2.4',
scripts: { foo: 'bar' },
});
expect(
await environment.readJsonFileWithinPackage('e', 'package.json'),
).toStrictEqual({
name: '@scope/e',
version: '0.0.3',
scripts: { foo: 'bar' },
});
},
);
});
Expand Down Expand Up @@ -289,5 +272,289 @@ describe('create-release-branch (functional)', () => {
},
);
});

it('errors before making any changes if the edited release spec omits changed packages', async () => {
await withMonorepoProjectEnvironment(
{
packages: {
$root$: {
name: '@scope/monorepo',
version: '1.0.0',
directoryPath: '.',
},
a: {
name: '@scope/a',
version: '0.1.2',
directoryPath: 'packages/a',
},
b: {
name: '@scope/b',
version: '1.1.4',
directoryPath: 'packages/b',
},
c: {
name: '@scope/c',
version: '2.0.13',
directoryPath: 'packages/c',
},
d: {
name: '@scope/d',
version: '1.2.3',
directoryPath: 'packages/d',
},
},
workspaces: {
'.': ['packages/*'],
},
},
async (environment) => {
await expect(
environment.runTool({
releaseSpecification: {
packages: {
a: 'major',
c: 'patch',
},
},
}),
).toThrowExecaError(
`
Error: Your release spec could not be processed due to the following issues:

* The following packages, which have changed since their latest release, are missing.

- @scope/b
- @scope/d

Consider including them in the release spec so that any packages that rely on them won't break in production.

If you are ABSOLUTELY SURE that this won't occur, however, and want to postpone the release of a package, then list it with a directive of "intentionally-skip". For example:

packages:
"@scope/b": intentionally-skip
"@scope/d": intentionally-skip

The release spec file has been retained for you to edit again and make the necessary fixes. Once you've done this, re-run this tool.

<<release-spec-file-path>>
<<stack-trace>>
`.trim(),
{
replacements: [
{
from: `${environment.tempDirectoryPath}/RELEASE_SPEC`,
to: '<<release-spec-file-path>>',
},
],
},
);

expect(await environment.readJsonFile('package.json')).toStrictEqual({
name: '@scope/monorepo',
version: '1.0.0',
private: true,
workspaces: ['packages/*'],
});
expect(
await environment.readJsonFileWithinPackage('a', 'package.json'),
).toStrictEqual({
name: '@scope/a',
version: '0.1.2',
});
expect(
await environment.readJsonFileWithinPackage('b', 'package.json'),
).toStrictEqual({
name: '@scope/b',
version: '1.1.4',
});
expect(
await environment.readJsonFileWithinPackage('c', 'package.json'),
).toStrictEqual({
name: '@scope/c',
version: '2.0.13',
});
expect(
await environment.readJsonFileWithinPackage('d', 'package.json'),
).toStrictEqual({
name: '@scope/d',
version: '1.2.3',
});
},
);
});

it('does not update the versions of any packages that have been tagged with intentionally-skip', async () => {
await withMonorepoProjectEnvironment(
{
packages: {
$root$: {
name: '@scope/monorepo',
version: '1.0.0',
directoryPath: '.',
},
a: {
name: '@scope/a',
version: '0.1.2',
directoryPath: 'packages/a',
},
b: {
name: '@scope/b',
version: '1.1.4',
directoryPath: 'packages/b',
},
c: {
name: '@scope/c',
version: '2.0.13',
directoryPath: 'packages/c',
},
d: {
name: '@scope/d',
version: '1.2.3',
directoryPath: 'packages/d',
},
},
workspaces: {
'.': ['packages/*'],
},
},
async (environment) => {
await environment.runTool({
releaseSpecification: {
packages: {
a: 'major',
b: 'intentionally-skip',
c: 'patch',
d: 'intentionally-skip',
},
},
});

expect(await environment.readJsonFile('package.json')).toStrictEqual({
name: '@scope/monorepo',
version: '2.0.0',
private: true,
workspaces: ['packages/*'],
});
expect(
await environment.readJsonFileWithinPackage('a', 'package.json'),
).toStrictEqual({
name: '@scope/a',
version: '1.0.0',
});
expect(
await environment.readJsonFileWithinPackage('b', 'package.json'),
).toStrictEqual({
name: '@scope/b',
version: '1.1.4',
});
expect(
await environment.readJsonFileWithinPackage('c', 'package.json'),
).toStrictEqual({
name: '@scope/c',
version: '2.0.14',
});
expect(
await environment.readJsonFileWithinPackage('d', 'package.json'),
).toStrictEqual({
name: '@scope/d',
version: '1.2.3',
});
},
);
});

it('does not update the changelogs of any packages that have been tagged with intentionally-skip', async () => {
await withMonorepoProjectEnvironment(
{
packages: {
$root$: {
name: '@scope/monorepo',
version: '1.0.0',
directoryPath: '.',
},
a: {
name: '@scope/a',
version: '1.0.0',
directoryPath: 'packages/a',
},
b: {
name: '@scope/b',
version: '1.0.0',
directoryPath: 'packages/b',
},
},
workspaces: {
'.': ['packages/*'],
},
createInitialCommit: false,
},
async (environment) => {
// Create an initial commit
await environment.writeFileWithinPackage(
'a',
'CHANGELOG.md',
buildChangelog(`
## [Unreleased]

[Unreleased]: https://github.com/example-org/example-repo
`),
);
await environment.writeFileWithinPackage(
'b',
'CHANGELOG.md',
buildChangelog(`
## [Unreleased]

[Unreleased]: https://github.com/example-org/example-repo
`),
);
await environment.createCommit('Initial commit');

// Create another commit that only changes "a"
await environment.writeFileWithinPackage(
'a',
'dummy.txt',
'Some content',
);
await environment.createCommit('Update "a"');

// Run the tool
await environment.runTool({
releaseSpecification: {
packages: {
a: 'major',
b: 'intentionally-skip',
},
},
});

// Only "a" should get updated
expect(
await environment.readFileWithinPackage('a', 'CHANGELOG.md'),
).toStrictEqual(
buildChangelog(`
## [Unreleased]

## [2.0.0]
### Uncategorized
- Update "a"
- Initial commit

[Unreleased]: https://github.com/example-org/example-repo/compare/v2.0.0...HEAD
[2.0.0]: https://github.com/example-org/example-repo/releases/tag/v2.0.0
`),
);
expect(
await environment.readFileWithinPackage('b', 'CHANGELOG.md'),
).toStrictEqual(
buildChangelog(`
## [Unreleased]

[Unreleased]: https://github.com/example-org/example-repo
`),
);
},
);
});
});
});
Loading