-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add functional tests #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e23c2e2
Add functional tests
mcmire 4709c44
Update the name of this test
mcmire cc6a7c2
Remove keys from process.env that were added in tests
mcmire 049fc68
No need to export ROOT_DIR
mcmire 4998200
Replace '...with which...' with better wording
mcmire 92c846d
Set the latest commit time better
mcmire 8b21141
Use buildChangelog
mcmire a8fa5a9
Don't make packages or workspaces optional
mcmire be14668
Tweaks
mcmire 86cedf0
Use knownKeysOf (and fix it for Partial records)
mcmire 7ee99bb
Remove this cast
mcmire eccfeba
Fix tests
mcmire b500a00
Make the last assertions easier to read
mcmire 4ff15a0
Make the assertions even clearer
mcmire 71dde41
Tweak the name of this test
mcmire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
import { withMonorepoProjectEnvironment } from '../tests/functional/helpers/with'; | ||
import { buildChangelog } from '../tests/functional/helpers/utils'; | ||
|
||
describe('create-release-branch (functional)', () => { | ||
describe('against a monorepo with independent versions', () => { | ||
it('updates the version of the root package to be the current date along with the versions of the specified packages', async () => { | ||
await withMonorepoProjectEnvironment( | ||
{ | ||
packages: { | ||
$root$: { | ||
name: '@scope/monorepo', | ||
version: '2022.1.1', | ||
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', | ||
}, | ||
e: { | ||
name: '@scope/e', | ||
version: '0.0.3', | ||
directoryPath: 'packages/e', | ||
}, | ||
}, | ||
workspaces: { | ||
'.': ['packages/*'], | ||
}, | ||
today: new Date('2022-06-24'), | ||
}, | ||
async (environment) => { | ||
await environment.runTool({ | ||
releaseSpecification: { | ||
packages: { | ||
a: 'major', | ||
b: 'minor', | ||
c: 'patch', | ||
d: '1.2.4', | ||
}, | ||
}, | ||
}); | ||
|
||
expect(await environment.readJsonFile('package.json')).toMatchObject({ | ||
version: '2022.6.24', | ||
}); | ||
expect( | ||
await environment.readJsonFileWithinPackage('a', 'package.json'), | ||
).toMatchObject({ | ||
version: '1.0.0', | ||
}); | ||
expect( | ||
await environment.readJsonFileWithinPackage('b', 'package.json'), | ||
).toMatchObject({ | ||
version: '1.2.0', | ||
}); | ||
expect( | ||
await environment.readJsonFileWithinPackage('c', 'package.json'), | ||
).toMatchObject({ | ||
version: '2.0.14', | ||
}); | ||
expect( | ||
await environment.readJsonFileWithinPackage('d', 'package.json'), | ||
).toMatchObject({ | ||
version: '1.2.4', | ||
}); | ||
expect( | ||
await environment.readJsonFileWithinPackage('e', 'package.json'), | ||
).toMatchObject({ | ||
version: '0.0.3', | ||
}); | ||
}, | ||
); | ||
}); | ||
|
||
it("updates each of the specified packages' changelogs by adding a new section which lists all commits concerning the package over the entire history of the repo", async () => { | ||
await withMonorepoProjectEnvironment( | ||
{ | ||
packages: { | ||
$root$: { | ||
name: '@scope/monorepo', | ||
version: '2022.1.1', | ||
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: 'major', | ||
}, | ||
}, | ||
}); | ||
|
||
// Both changelogs should get updated, with an additional | ||
// commit listed for "a" | ||
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] | ||
|
||
## [2.0.0] | ||
### Uncategorized | ||
- 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 | ||
`), | ||
); | ||
}, | ||
); | ||
}); | ||
|
||
it('switches to a new release branch and commits the changes', async () => { | ||
await withMonorepoProjectEnvironment( | ||
{ | ||
packages: { | ||
$root$: { | ||
name: '@scope/monorepo', | ||
version: '2022.1.1', | ||
directoryPath: '.', | ||
}, | ||
a: { | ||
name: '@scope/a', | ||
version: '1.0.0', | ||
directoryPath: 'packages/a', | ||
}, | ||
}, | ||
workspaces: { | ||
'.': ['packages/*'], | ||
}, | ||
today: new Date('2022-06-24'), | ||
}, | ||
async (environment) => { | ||
await environment.runTool({ | ||
releaseSpecification: { | ||
packages: { | ||
a: 'major', | ||
}, | ||
}, | ||
}); | ||
|
||
// Tests four things: | ||
// * The latest commit should be called "Release YYYY-MM-DD" | ||
// * The latest commit should be the current commit (HEAD) | ||
// * The latest branch should be called "release/YYYY-MM-DD" | ||
// * The latest branch should point to the latest commit | ||
const [latestCommitSubject, latestCommitId, latestCommitRevsMarker] = | ||
( | ||
await environment.runCommand('git', [ | ||
'log', | ||
'--pretty=%s%x09%H%x09%D', | ||
'--date-order', | ||
'--max-count=1', | ||
]) | ||
).stdout.split('\x09'); | ||
const latestCommitRevs = latestCommitRevsMarker.split(' -> '); | ||
const latestBranchCommitId = ( | ||
await environment.runCommand('git', [ | ||
'rev-list', | ||
'--branches', | ||
'--date-order', | ||
'--max-count=1', | ||
]) | ||
).stdout; | ||
expect(latestCommitSubject).toStrictEqual('Release 2022-06-24'); | ||
expect(latestCommitRevs).toContain('HEAD'); | ||
expect(latestCommitRevs).toContain('release/2022-06-24'); | ||
expect(latestBranchCommitId).toStrictEqual(latestCommitId); | ||
}, | ||
); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import path from 'path'; | ||
|
||
const ROOT_DIR = path.resolve(__dirname, '../../..'); | ||
export const TOOL_EXECUTABLE_PATH = path.join(ROOT_DIR, 'src', 'cli.ts'); | ||
export const TS_NODE_PATH = path.join( | ||
ROOT_DIR, | ||
'node_modules', | ||
'.bin', | ||
'ts-node', | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm only testing the happy paths right now. This file is going to grow larger as we add different features — for instance, right now there is no logic around changed packages, so once that happens we need to consider what happens when the repo has no tags, etc. — so I'm hesitant to add error/alternate cases. I figure it's easier to add more test cases later than remove them.