diff --git a/lib/steps/version-commit.js b/lib/steps/version-commit.js index c943500..85cca18 100644 --- a/lib/steps/version-commit.js +++ b/lib/steps/version-commit.js @@ -60,6 +60,10 @@ function commit(cwd, message) { }); } +function getCurrentDate() { + return new Date().toISOString().substring(0, 10); +} + function getHEAD(cwd) { return run('git', ['rev-parse', 'HEAD'], { cwd, @@ -99,7 +103,9 @@ function createVersionCommit(cwd, pkg, options) { changeLogContent = ''; } - changeLogContent = `### ${options.nextVersion}\n\n${options.changelog}${changeLogContent}`; + changeLogContent = `### ${options.nextVersion} - ${getCurrentDate()}\n\n${ + options.changelog + }${changeLogContent}`; fs.writeFileSync(changeLogFile, `${changeLogContent.trim()}\n`); const packageJsonFile = path.join(cwd, 'package.json'); pkg.version = options.nextVersion; diff --git a/test/steps/version-commit.test.js b/test/steps/version-commit.test.js index 4df1977..6610cc4 100644 --- a/test/steps/version-commit.test.js +++ b/test/steps/version-commit.test.js @@ -68,6 +68,7 @@ describe('createVersionCommit', () => { afterEach(resetVars); describe('with no package-lock.json', () => { const dirname = withFixture('multiple-commits'); + let currentDate; before('commits with the original author', done => { execFile( 'git', @@ -83,12 +84,23 @@ describe('createVersionCommit', () => { ); }); before('create version commit', () => { + currentDate = new Date().toISOString().substring(0, 10); return createVersionCommit(dirname, pkg, options); }); it('writes the correct HEAD sha', () => { const HEAD = fs.readFileSync(`${dirname}/.git/refs/heads/master`, 'utf8'); assert.equal(HEAD.trim(), options.versionCommitSha); }); + + it('writes the correct CHANGELOG', () => { + const [version, , commit1, commit2] = fs + .readFileSync(`${dirname}/CHANGELOG.md`, 'utf8') + .split('\n'); + assert.equal(`### 1.0.0 - ${currentDate}`, version); + assert.equal('* New stuff', commit1); + assert.equal('* Interesting features', commit2); + }); + it('commits with the proper user', done => { execFile( 'git',