-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
85 lines (75 loc) · 2.81 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
const packageJsonLinks = require('./package-json-links');
const clientVersion = '0.1.8';
test('extraction of project name from JSON dependency', async () => {
expect(packageJsonLinks.getProjectFromDependency('@actions/core')).toBe('core');
expect(packageJsonLinks.getProjectFromDependency('color-name')).toBe('color-name');
expect(packageJsonLinks.getProjectFromDependency('@babel/plugin-syntax-numeric-separator')).toBe('plugin-syntax-numeric-separator');
expect(packageJsonLinks.getProjectFromDependency('@nemerosa/ontrack-github-action-client')).toBe('ontrack-github-action-client');
});
test('missing dependency field', async () => {
const links = await packageJsonLinks.readFromPackageJson(`
- name: "@nemerosa/ontrack-github-action-client"
`)
expect(links).toStrictEqual({});
});
test('missing dependency', async () => {
const links = await packageJsonLinks.readFromPackageJson(`
- name: "@nemerosa/unknown"
`)
expect(links).toStrictEqual({});
});
test('simple dependency', async () => {
const links = await packageJsonLinks.readFromPackageJson(`
- dependency: "@nemerosa/ontrack-github-action-client"
`)
expect(links).toStrictEqual({
'ontrack-github-action-client': clientVersion
});
});
test('project mapping', async () => {
const links = await packageJsonLinks.readFromPackageJson(`
- dependency: "@nemerosa/ontrack-github-action-client"
project: github-action-client
`)
expect(links).toStrictEqual({
'github-action-client': clientVersion
});
});
test('build label', async () => {
const links = await packageJsonLinks.readFromPackageJson(`
- dependency: "@nemerosa/ontrack-github-action-client"
build-label: true
`)
expect(links).toStrictEqual({
'ontrack-github-action-client': `#${clientVersion}`
});
});
test('build label and prefix', async () => {
const links = await packageJsonLinks.readFromPackageJson(`
- dependency: "@nemerosa/ontrack-github-action-client"
build-label: true
prefix: "v"
`)
expect(links).toStrictEqual({
'ontrack-github-action-client': `#v${clientVersion}`
});
});
test('build name and prefix', async () => {
const links = await packageJsonLinks.readFromPackageJson(`
- dependency: "@nemerosa/ontrack-github-action-client"
prefix: "v"
`)
expect(links).toStrictEqual({
'ontrack-github-action-client': `v${clientVersion}`
});
});
test('two simple dependencies', async () => {
const links = await packageJsonLinks.readFromPackageJson(`
- dependency: "@nemerosa/ontrack-github-action-client"
- dependency: "@actions/core"
`)
expect(links).toStrictEqual({
'ontrack-github-action-client': clientVersion,
'core': '1.8.2'
});
});