generated from actions/javascript-action
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
45 lines (37 loc) · 1.43 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
const bumpVersion = require('./version');
const process = require('process');
const cp = require('child_process');
const path = require('path');
test('throws invalid version', async () => {
await expect(bumpVersion(123, 'major')).rejects.toThrow('version not a string');
});
test('throws malformed version', async () => {
await expect(bumpVersion('1.0', 'major')).rejects.toThrow('version must be in the format x.y.z');
});
test('throws invalid bump', async () => {
await expect(bumpVersion('1.0.0', 'ultra')).rejects.toThrow("bump must be either 'major', 'minor', or 'patch'");
});
test('bump major', async () => {
const version = await bumpVersion('1.2.3', 'major');
expect(version).toBe('2.0.0');
});
test('bump minor', async () => {
const version = await bumpVersion('1.2.3', 'minor');
expect(version).toBe('1.3.0');
});
test('bump patch', async () => {
const version = await bumpVersion('1.2.3', 'patch');
expect(version).toBe('1.2.4');
});
test('bump none', async () => {
const version = await bumpVersion('1.2.3', 'none');
expect(version).toBe('1.2.3');
});
// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
process.env['INPUT_VERSION'] = '1.0.0';
process.env['INPUT_BUMP'] = 'major';
const ip = path.join(__dirname, 'index.js');
const result = cp.execSync(`node "${ip}"`, {env: process.env}).toString();
console.log(result);
})