Skip to content

Commit

Permalink
test: add test to prevent duplicate headers
Browse files Browse the repository at this point in the history
Add a failing test that proves conventional-changelog#305 so that a subsequent commit can fix
it.
  • Loading branch information
jthomerson committed Feb 25, 2019
1 parent 04513e8 commit 3423bfb
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('cli', function () {
})

describe('CHANGELOG.md exists', function () {
it('appends the new release above the last release, removing the old header', function () {
it('appends the new release above the last release, removing the old header (legacy format)', function () {
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')

commit('feat: first commit')
Expand All @@ -164,6 +164,25 @@ describe('cli', function () {
content.should.not.match(/legacy header format/)
})

it('appends the new release above the last release, removing the old header (new format)', function () {
commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('fix: patch release')

execCli().code.should.equal(0)
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')

// remove commit hashes and dates to make testing against a static string easier:
content = content.replace(/patch release [0-9a-f]{6,8}/g, 'patch release ABCDEFXY').replace(/\([0-9]{4}-[0-9]{2}-[0-9]{2}\)/g, '(YYYY-MM-DD)')
content.should.equal('# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n\n## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n')

commit('fix: another patch release')
execCli().code.should.equal(0)
content = fs.readFileSync('CHANGELOG.md', 'utf-8')
content = content.replace(/patch release [0-9a-f]{6,8}/g, 'patch release ABCDEFXY').replace(/\([0-9]{4}-[0-9]{2}-[0-9]{2}\)/g, '(YYYY-MM-DD)')
content.should.equal('# Change Log\n\nAll notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.\n\n## [1.0.2](/compare/v1.0.1...v1.0.2) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* another patch release ABCDEFXY\n\n\n\n## [1.0.1](/compare/v1.0.0...v1.0.1) (YYYY-MM-DD)\n\n\n### Bug Fixes\n\n* patch release ABCDEFXY\n')
})

it('commits all staged files', function () {
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')

Expand Down

0 comments on commit 3423bfb

Please sign in to comment.