Skip to content

Commit 7e53f8c

Browse files
authored
test: add should generate changelog with remote origin urls (release-it#132)
* test: add should generate changelog with remote origin urls * refactor: change header and commit function globally to support urls
1 parent a8b9b8a commit 7e53f8c

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ const setup = () => {
6161

6262
const date = /\([0-9]{4}-[0-9]{2}-[0-9]{2}\)/.source;
6363
const sha = /[0-9a-f]{7}/.source;
64+
const shaLong = /[0-9a-f]{40}/.source;
6465
const level = (from, to) => `${/patch/.test(semver.diff(from, to)) ? '##' : '#'}`;
65-
const header = (from, to, suffix = '') =>
66-
`${level(from, to)} \\[${to}\\]\\(/compare/${from}${suffix}...${to}${suffix}\\) ${date}`;
66+
const header = (from, to, suffix = '', url = '') =>
67+
`${level(from, to)} \\[${to}\\]\\(${url}/compare/${from}${suffix}...${to}${suffix}\\) ${date}`;
6768
const features = EOL + EOL + EOL + '### Features' + EOL;
6869
const fixes = EOL + EOL + EOL + '### Bug Fixes' + EOL;
69-
const commit = (type, name) => EOL + `\\* \\*\\*${name}:\\*\\* ${type} ${name} ${sha}`;
70+
const commit = (type, name, url = '') => EOL + `\\* \\*\\*${name}:\\*\\* ${type} ${name} ${url ? `\\(\\[${sha}\\]\\(${url}/commit/${shaLong}\\)\\)` : sha}`;
7071

7172
const nl = value => value.split(/\r\n|\r|\n/g).join(EOL);
7273

@@ -433,3 +434,20 @@ test('should pass parserOpts and writerOpts', async () => {
433434
assert.match(changelog, /fix/);
434435
assert.match(changelog, /feat/);
435436
});
437+
438+
test('should generate changelog with origin urls', async () => {
439+
setup();
440+
441+
const url = 'https://github.com/release-it/conventional-changelog';
442+
sh.exec(`git tag 1.0.0`);
443+
sh.exec(`git remote add origin ${url}`)
444+
add('fix', 'bar');
445+
add('feat', 'baz');
446+
447+
const options = getOptions({ preset });
448+
const { changelog } = await runTasks(...options);
449+
const title = header('1.0.0', '1.1.0', '', url);
450+
const bar = commit('fix', 'bar', url);
451+
const baz = commit('feat', 'baz', url);
452+
assert.match(nl(changelog), new RegExp('^' + title + fixes + bar + features + baz + '$'));
453+
});

0 commit comments

Comments
 (0)