From c2c9bd82ab1857009b8e4e5bcb514312fdd43975 Mon Sep 17 00:00:00 2001 From: Pete Cook Date: Sun, 1 Sep 2019 20:42:45 +0100 Subject: [PATCH] Update test data generation --- scripts/generate-test-data.js | 44 +++++------ test/data/commits.js | 2 +- test/data/releases.js | 144 +++++++++++++++++----------------- test/data/template-json.json | 142 ++++++++++++++++----------------- 4 files changed, 164 insertions(+), 168 deletions(-) diff --git a/scripts/generate-test-data.js b/scripts/generate-test-data.js index b81e8655..fc7a4d8a 100644 --- a/scripts/generate-test-data.js +++ b/scripts/generate-test-data.js @@ -3,16 +3,12 @@ import { readFile, writeFile } from '../src/utils' import { __get__ } from '../src/commits' import { parseReleases } from '../src/releases' import { compileTemplate } from '../src/template' +import remotes from '../test/data/remotes' const parseCommits = __get__('parseCommits') const DATA_DIR = join(__dirname, '..', 'test', 'data') -const remote = { - hostname: 'github.com', - url: 'https://github.com/user/repo' -} - const options = { unreleased: false, commitLimit: 3, @@ -20,29 +16,25 @@ const options = { tagPrefix: '' } -async function run () { - const gitLog = await readFile(join(DATA_DIR, 'git-log.txt')) - const commits = parseCommits(gitLog, remote, options) - const releases = parseReleases(commits, remote, null, options) - await writeFile(join(DATA_DIR, 'commits.js'), 'export default ' + JSON.stringify(commits, null, 2)) - await writeFile(join(DATA_DIR, 'commits-no-remote.js'), 'export default ' + JSON.stringify(commitsWithoutLinks(commits), null, 2)) - await writeFile(join(DATA_DIR, 'releases.js'), 'export default ' + JSON.stringify(releases, null, 2)) - await writeFile(join(DATA_DIR, 'template-compact.md'), await compileTemplate({ template: 'compact' }, { releases })) - await writeFile(join(DATA_DIR, 'template-keepachangelog.md'), await compileTemplate({ template: 'keepachangelog' }, { releases })) - await writeFile(join(DATA_DIR, 'template-json.json'), await compileTemplate({ template: 'json' }, { releases })) +function writeObject (filename, object) { + return writeFile(join(DATA_DIR, filename), `export default ${JSON.stringify(object, null, 2)}\n`) } -function commitsWithoutLinks (commits) { - return commits.map(commit => { - const merge = commit.merge ? { ...commit.merge, href: null, commit: { ...commit.merge.commit, href: null } } : null - const fixes = commit.fixes ? commit.fixes.map(fix => ({ ...fix, href: null })) : null - return { - ...commit, - href: null, - fixes, - merge - } - }) +async function writeTemplate (filename, template, releases) { + return writeFile(join(DATA_DIR, filename), await compileTemplate({ template }, { releases })) +} + +async function run () { + const gitLog = await readFile(join(DATA_DIR, 'git-log.txt')) + const commits = parseCommits(gitLog, remotes.github, options) + const commitsNoRemote = parseCommits(gitLog, remotes.null, options) + const releases = parseReleases(commits, remotes.github, null, options) + await writeObject('commits.js', commits) + await writeObject('commits-no-remote.js', commitsNoRemote) + await writeObject('releases.js', releases) + await writeTemplate('template-compact.md', 'compact', releases) + await writeTemplate('template-keepachangelog.md', 'keepachangelog', releases) + await writeTemplate('template-json.json', 'json', releases) } run().catch(e => console.error(e)) diff --git a/test/data/commits.js b/test/data/commits.js index a95f6cb2..5bafd5b9 100644 --- a/test/data/commits.js +++ b/test/data/commits.js @@ -307,4 +307,4 @@ export default [ "deletions": 22, "merge": null } -] \ No newline at end of file +] diff --git a/test/data/releases.js b/test/data/releases.js index aca3a53a..f5ec9a07 100644 --- a/test/data/releases.js +++ b/test/data/releases.js @@ -1,5 +1,10 @@ export default [ { + "tag": "v1.0.0", + "title": "v1.0.0", + "date": "2015-12-15T12:03:09.000Z", + "isoDate": "2015-12-15", + "niceDate": "15 December 2015", "commits": [ { "hash": "b0b304049847d9568585bc11399fa6cfa4cab5dc", @@ -19,18 +24,18 @@ export default [ "merge": null } ], - "fixes": [], "merges": [], - "tag": "v1.0.0", - "date": "2015-12-15T12:03:09.000Z", + "fixes": [], "summary": null, - "title": "v1.0.0", - "niceDate": "15 December 2015", - "isoDate": "2015-12-15", - "href": "https://github.com/user/repo/compare/v0.1.0...v1.0.0", - "major": true + "major": true, + "href": "https://github.com/user/repo/compare/v0.1.0...v1.0.0" }, { + "tag": "v0.1.0", + "title": "v0.1.0", + "date": "2015-12-29T21:19:17.000Z", + "isoDate": "2015-12-29", + "niceDate": "29 December 2015", "commits": [ { "hash": "12c0624e7e419a70bd5f3b403d7e0bd8f23ec617", @@ -67,19 +72,40 @@ export default [ "merge": null } ], - "fixes": [], "merges": [], - "tag": "v0.1.0", - "date": "2015-12-29T21:19:17.000Z", + "fixes": [], "summary": null, - "title": "v0.1.0", - "niceDate": "29 December 2015", - "isoDate": "2015-12-29", - "href": "https://github.com/user/repo/compare/v0.0.2...v0.1.0", - "major": false + "major": false, + "href": "https://github.com/user/repo/compare/v0.0.2...v0.1.0" }, { + "tag": "v0.0.2", + "title": "v0.0.2", + "date": "2015-12-28T21:17:17.000Z", + "isoDate": "2015-12-28", + "niceDate": "28 December 2015", "commits": [], + "merges": [ + { + "id": "5", + "message": "Should not parse #4 in PR title", + "href": "https://github.com/user/repo/pull/5", + "author": "Pete Cook", + "commit": { + "hash": "0e24bf427a51eac52133cc731b4b5d74a7e04672", + "shorthash": "0e24bf4", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-24T20:29:22.000Z", + "tag": null, + "subject": "Merge pull request #5 from repo/branch", + "message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title", + "fixes": null, + "href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672", + "breaking": false + } + } + ], "fixes": [ { "fixes": [ @@ -114,37 +140,16 @@ export default [ } } ], - "merges": [ - { - "id": "5", - "message": "Should not parse #4 in PR title", - "href": "https://github.com/user/repo/pull/5", - "author": "Pete Cook", - "commit": { - "hash": "0e24bf427a51eac52133cc731b4b5d74a7e04672", - "shorthash": "0e24bf4", - "author": "Pete Cook", - "email": "email@example.com", - "date": "2015-12-24T20:29:22.000Z", - "tag": null, - "subject": "Merge pull request #5 from repo/branch", - "message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title", - "fixes": null, - "href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672", - "breaking": false - } - } - ], - "tag": "v0.0.2", - "date": "2015-12-28T21:17:17.000Z", "summary": null, - "title": "v0.0.2", - "niceDate": "28 December 2015", - "isoDate": "2015-12-28", - "href": "https://github.com/user/repo/compare/v0.0.1...v0.0.2", - "major": false + "major": false, + "href": "https://github.com/user/repo/compare/v0.0.1...v0.0.2" }, { + "tag": "v0.0.1", + "title": "v0.0.1", + "date": "2015-12-15T12:03:09.000Z", + "isoDate": "2015-12-15", + "niceDate": "15 December 2015", "commits": [ { "hash": "158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69", @@ -164,6 +169,27 @@ export default [ "merge": null } ], + "merges": [ + { + "id": "3", + "message": "Third commit with same name as PR", + "href": "https://github.com/user/repo/pull/3", + "author": "Pete Cook", + "commit": { + "hash": "31b7d3da24d64e32a0a7e558f254d01c348613f3", + "shorthash": "31b7d3d", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-15T11:37:05.000Z", + "tag": null, + "subject": "Merge pull request #3 from repo/branch", + "message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR", + "fixes": null, + "href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3", + "breaking": false + } + } + ], "fixes": [ { "fixes": [ @@ -208,32 +234,8 @@ export default [ } } ], - "merges": [ - { - "id": "3", - "message": "Third commit with same name as PR", - "href": "https://github.com/user/repo/pull/3", - "author": "Pete Cook", - "commit": { - "hash": "31b7d3da24d64e32a0a7e558f254d01c348613f3", - "shorthash": "31b7d3d", - "author": "Pete Cook", - "email": "email@example.com", - "date": "2015-12-15T11:37:05.000Z", - "tag": null, - "subject": "Merge pull request #3 from repo/branch", - "message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR", - "fixes": null, - "href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3", - "breaking": false - } - } - ], - "tag": "v0.0.1", - "date": "2015-12-15T12:03:09.000Z", "summary": null, - "title": "v0.0.1", - "niceDate": "15 December 2015", - "isoDate": "2015-12-15" + "major": false, + "href": null } -] \ No newline at end of file +] diff --git a/test/data/template-json.json b/test/data/template-json.json index e301d5e7..c87a294e 100644 --- a/test/data/template-json.json +++ b/test/data/template-json.json @@ -1,5 +1,10 @@ [ { + "tag": "v1.0.0", + "title": "v1.0.0", + "date": "2015-12-15T12:03:09.000Z", + "isoDate": "2015-12-15", + "niceDate": "15 December 2015", "commits": [ { "hash": "b0b304049847d9568585bc11399fa6cfa4cab5dc", @@ -19,18 +24,18 @@ "merge": null } ], - "fixes": [], "merges": [], - "tag": "v1.0.0", - "date": "2015-12-15T12:03:09.000Z", + "fixes": [], "summary": null, - "title": "v1.0.0", - "niceDate": "15 December 2015", - "isoDate": "2015-12-15", - "href": "https://github.com/user/repo/compare/v0.1.0...v1.0.0", - "major": true + "major": true, + "href": "https://github.com/user/repo/compare/v0.1.0...v1.0.0" }, { + "tag": "v0.1.0", + "title": "v0.1.0", + "date": "2015-12-29T21:19:17.000Z", + "isoDate": "2015-12-29", + "niceDate": "29 December 2015", "commits": [ { "hash": "12c0624e7e419a70bd5f3b403d7e0bd8f23ec617", @@ -67,19 +72,40 @@ "merge": null } ], - "fixes": [], "merges": [], - "tag": "v0.1.0", - "date": "2015-12-29T21:19:17.000Z", + "fixes": [], "summary": null, - "title": "v0.1.0", - "niceDate": "29 December 2015", - "isoDate": "2015-12-29", - "href": "https://github.com/user/repo/compare/v0.0.2...v0.1.0", - "major": false + "major": false, + "href": "https://github.com/user/repo/compare/v0.0.2...v0.1.0" }, { + "tag": "v0.0.2", + "title": "v0.0.2", + "date": "2015-12-28T21:17:17.000Z", + "isoDate": "2015-12-28", + "niceDate": "28 December 2015", "commits": [], + "merges": [ + { + "id": "5", + "message": "Should not parse #4 in PR title", + "href": "https://github.com/user/repo/pull/5", + "author": "Pete Cook", + "commit": { + "hash": "0e24bf427a51eac52133cc731b4b5d74a7e04672", + "shorthash": "0e24bf4", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-24T20:29:22.000Z", + "tag": null, + "subject": "Merge pull request #5 from repo/branch", + "message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title", + "fixes": null, + "href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672", + "breaking": false + } + } + ], "fixes": [ { "fixes": [ @@ -114,37 +140,16 @@ } } ], - "merges": [ - { - "id": "5", - "message": "Should not parse #4 in PR title", - "href": "https://github.com/user/repo/pull/5", - "author": "Pete Cook", - "commit": { - "hash": "0e24bf427a51eac52133cc731b4b5d74a7e04672", - "shorthash": "0e24bf4", - "author": "Pete Cook", - "email": "email@example.com", - "date": "2015-12-24T20:29:22.000Z", - "tag": null, - "subject": "Merge pull request #5 from repo/branch", - "message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title", - "fixes": null, - "href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672", - "breaking": false - } - } - ], - "tag": "v0.0.2", - "date": "2015-12-28T21:17:17.000Z", "summary": null, - "title": "v0.0.2", - "niceDate": "28 December 2015", - "isoDate": "2015-12-28", - "href": "https://github.com/user/repo/compare/v0.0.1...v0.0.2", - "major": false + "major": false, + "href": "https://github.com/user/repo/compare/v0.0.1...v0.0.2" }, { + "tag": "v0.0.1", + "title": "v0.0.1", + "date": "2015-12-15T12:03:09.000Z", + "isoDate": "2015-12-15", + "niceDate": "15 December 2015", "commits": [ { "hash": "158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69", @@ -164,6 +169,27 @@ "merge": null } ], + "merges": [ + { + "id": "3", + "message": "Third commit with same name as PR", + "href": "https://github.com/user/repo/pull/3", + "author": "Pete Cook", + "commit": { + "hash": "31b7d3da24d64e32a0a7e558f254d01c348613f3", + "shorthash": "31b7d3d", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-15T11:37:05.000Z", + "tag": null, + "subject": "Merge pull request #3 from repo/branch", + "message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR", + "fixes": null, + "href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3", + "breaking": false + } + } + ], "fixes": [ { "fixes": [ @@ -208,32 +234,8 @@ } } ], - "merges": [ - { - "id": "3", - "message": "Third commit with same name as PR", - "href": "https://github.com/user/repo/pull/3", - "author": "Pete Cook", - "commit": { - "hash": "31b7d3da24d64e32a0a7e558f254d01c348613f3", - "shorthash": "31b7d3d", - "author": "Pete Cook", - "email": "email@example.com", - "date": "2015-12-15T11:37:05.000Z", - "tag": null, - "subject": "Merge pull request #3 from repo/branch", - "message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR", - "fixes": null, - "href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3", - "breaking": false - } - } - ], - "tag": "v0.0.1", - "date": "2015-12-15T12:03:09.000Z", "summary": null, - "title": "v0.0.1", - "niceDate": "15 December 2015", - "isoDate": "2015-12-15" + "major": false, + "href": null } ]