-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
95 lines (80 loc) · 2.26 KB
/
index.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
import { describe, expect, test } from '@jest/globals';
import { factory, runTasks } from 'release-it/test/util/index.js';
import tmp from 'tmp';
import Plugin from './index.js';
tmp.setGracefulCleanup();
class TestPlugin extends Plugin {
constructor() {
super(...arguments);
// basic harness for mocking executable command output
this.responses = {
// always assume v1.0.0 unless specifically overridden
'git describe --tags --abbrev=0': 'v1.0.0',
};
this.commands = [];
this.shell.execFormattedCommand = async (command, options) => {
this.commands.push([command, options]);
if (this.responses[command]) {
let response = this.responses[command];
if (typeof response === 'string') {
return response;
} else if (
typeof response === 'object' &&
response !== null &&
response.reject === true
) {
throw new Error(response.value);
}
}
};
}
}
function buildPlugin(config = {}, _Plugin = TestPlugin) {
const namespace = '@release-it-plugins/gh-changelog';
const options = { [namespace]: config };
const plugin = factory(_Plugin, { namespace, options });
return plugin;
}
describe('@release-it-plugins/gh-changelog', () => {
test('it determines the latest tag', async () => {
let plugin = buildPlugin();
await runTasks(plugin);
expect(plugin.commands).toMatchInlineSnapshot(`
[
[
"git describe --tags --abbrev=0",
{
"write": false,
},
],
]
`);
});
test('it falls back to determining first commit if no tags exist', async () => {
let plugin = buildPlugin();
Object.assign(plugin.responses, {
'git describe --tags --abbrev=0': {
reject: true,
value: 'fatal: No names found, cannot describe anything.',
},
'git rev-list --max-parents=0 HEAD': 'aabc',
});
await runTasks(plugin);
expect(plugin.commands).toMatchInlineSnapshot(`
[
[
"git describe --tags --abbrev=0",
{
"write": false,
},
],
[
"git rev-list --max-parents=0 HEAD",
{
"write": false,
},
],
]
`);
});
});