generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
64 lines (56 loc) · 1.56 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
const setVersion = require('./set-version');
const process = require('process');
const cp = require('child_process');
const path = require('path');
const fs = require('fs');
test('setVersion works', () => {
expect(setVersion(fs.readFileSync('./fixtures/Cargo.toml').toString(), '0.24.4778923')).toEqual({
content: fs.readFileSync('./fixtures/Cargo.patched.toml').toString(),
version: '0.24.4778923'
});
expect(setVersion(`
version = "0.24.0"
`, '1.0.1', false)).toEqual({
content: `
version = "1.0.1"
`, version: '1.0.1'
});
expect(setVersion(`
version = "0.24.0"
`, '0.24.4778923')).toEqual({
content: `
version = "0.24.4778923"
`, version: '0.24.4778923'
});
expect(setVersion(`
version = "0.24.4778923"
`, '0.24.0')).toEqual({
content: `
version = "0.24.0"
`, version: '0.24.0'
});
expect(setVersion(`
version="0.24.0"
`, '0.24.4778923')).toEqual({
content: `
version="0.24.4778923"
`, version: '0.24.4778923'
});
expect(setVersion(`
version="0.24.0"
`, '4778923', true)).toEqual({
content: `
version="0.24.4778923"
`, version: '0.24.4778923'
});
});
test('setVersion throws when version string is invalid', () => {
expect(() => setVersion(fs.readFileSync('./fixtures/Cargo.toml').toString(), 'this is not a valid version string')).toThrowError('Invalid version string');
});
test('test runs', () => {
process.env['INPUT_CARGOFILE'] = './fixtures/Cargo.toml';
process.env['INPUT_VERSION'] = '1.0.1';
const ip = path.join(__dirname, 'index.js');
const result = cp.execSync(`node ${ip}`, {env: process.env}).toString();
console.log(result);
})