This repository has been archived by the owner on Jun 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
108 lines (93 loc) · 3.47 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import {writeFileSync} from 'fs';
import execa from 'execa';
import shell from 'shelljs';
import test from 'ava';
import {version} from './package.json';
const today = new Date().toISOString().replace(/T.+/, '');
const fixtureDefault = [
version + ' / ' + today,
'==================\n',
' * Another commit',
' * Core: minor tweeks',
' * Event: Remove an internal argument',
' * CSS: Don\'t name the anonymous swap function',
' * core: Make jQuery objects iterable\n'
].join('\n');
const fixtureGrunt = [
'1.0.0:',
' date: ' + today,
' changes:',
' - Another commit',
' - Core: minor tweeks',
' - Event: Remove an internal argument',
' - CSS: Don\'t name the anonymous swap function',
' - core: Make jQuery objects iterable'
].join('\n');
const fixtureJQuery = [
'1.0.0 / ' + today,
'==================\n',
'## CSS',
' * Don\'t name the anonymous swap function\n',
'## Core',
' * Minor tweeks',
' * Make jQuery objects iterable\n',
'## Event',
' * Remove an internal argument\n',
'## Others',
' * Another commit\n'
].join('\n');
const fixtureNode = [
'1.0.0 / ' + today,
'==================\n',
'* [[`commit-hash`]](https://github.com/Arkni/changelog-generator/commit/commit-hash) - Another commit',
'* [[`commit-hash`]](https://github.com/Arkni/changelog-generator/commit/commit-hash) - **Core:** minor tweeks',
'* [[`commit-hash`]](https://github.com/Arkni/changelog-generator/commit/commit-hash) - **Event:** Remove an internal argument',
'* [[`commit-hash`]](https://github.com/Arkni/changelog-generator/commit/commit-hash) - **CSS:** Don\'t name the anonymous swap function',
'* [[`commit-hash`]](https://github.com/Arkni/changelog-generator/commit/commit-hash) - **core:** Make jQuery objects iterable'
].join('\n');
function _replaceCommitHash(commit) {
return commit
.replace(/`(.*)`/gm, '`commit-hash`')
.replace(/commit\/([^\)]+)/gm, 'commit/commit-hash');
}
test.before('Set up the test', () => {
shell.config.silent = true;
shell.rm('-rf', 'tmp');
shell.mkdir('tmp');
shell.cd('tmp');
shell.exec('git init');
shell.exec('git config --local user.name "Travis-CI"');
shell.exec('git config --local user.email "[email protected]"');
shell.exec('git remote add origin [email protected]:Arkni/changelog-generator.git');
writeFileSync('test1', '');
shell.exec('git add --all && git commit -m "core: Make jQuery objects iterable"');
writeFileSync('test2', '');
shell.exec('git add --all && git commit -m "CSS: Don\'t name the anonymous swap function"');
writeFileSync('test3', '');
shell.exec('git add --all && git commit -m "Event: Remove an internal argument"');
writeFileSync('test4', '');
shell.exec('git add --all && git commit -m "Core: minor tweeks"');
writeFileSync('test5', '');
shell.exec('git add --all && git commit -m "Another commit"');
});
test.after('cleanup', () => {
shell.cd('..');
shell.rm('-rf', 'tmp');
});
test('Changelog - default options', async t => {
const {stdout} = await execa('../cli.js');
t.is(stdout, fixtureDefault);
});
test('Changelog - grunt preset', async t => {
const {stdout} = await execa('../cli.js', ['-r=1.0.0', '-preset=grunt']);
t.is(stdout, fixtureGrunt);
});
test('Changelog - jQuery preset', async t => {
const {stdout} = await execa('../cli.js', ['-r=1.0.0', '-preset=jquery']);
t.is(stdout, fixtureJQuery);
});
test('Changelog - node preset', async t => {
let {stdout} = await execa('../cli.js', ['-r=1.0.0', '-preset=node']);
stdout = _replaceCommitHash(stdout);
t.is(stdout, fixtureNode);
});