/
action.test.ts
135 lines (126 loc) · 5.25 KB
/
action.test.ts
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import {RunTarget, RunOptions} from "github-action-ts-run-api";
import * as dotenv from 'dotenv'
dotenv.config({path: 'tests.env'});
describe('git-get-release-action', () => {
const target = process.env.CI
? RunTarget.mainJs('action.yml')
: RunTarget.jsFile('lib/index.js', 'action.yml');
const options = RunOptions.create({
env: {
GITHUB_TOKEN: process.env.GITHUB_TOKEN,
GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY
}
});
it('should get by id', async () => {
const res = await target.run(options.clone()
.setInputs({ releaseId: '56669824' })
);
expect(res.isSuccess).toEqual(true);
expect(res.commands.outputs.id).toEqual('56669824');
expect(res.commands.outputs.tag_name).toEqual('testTag');
expect(res.commands.outputs.name).toEqual('test release name');
expect(res.commands.outputs.body).toEqual("test\r\nbody");
expect(res.commands.outputs.draft).toEqual('false');
expect(res.commands.outputs.prerelease).toEqual('true');
expect(res.commands.outputs.created_at).toEqual('2021-04-12T19:34:47Z');
expect(JSON.parse(res.commands.outputs.author as string).login).toEqual('cardinalby');
const assets = JSON.parse(res.commands.outputs.assets as string);
expect(Array.isArray(assets)).toBe(true);
expect(assets.length).toEqual(1);
expect(assets[0].name).toEqual('github-actions-webext.png');
expect(res.runnerWarnings).toHaveLength(0);
});
it('should not get by id', async () => {
const res = await target.run(options.clone()
.setInputs({
releaseId: '123456677',
doNotFailIfNotFound: 'true'
})
);
expect(res.isSuccess).toEqual(true);
expect(res.commands.outputs.id).toBeUndefined();
expect(res.commands.errors).toEqual([]);
expect(res.commands.warnings).not.toEqual([]);
expect(res.runnerWarnings).toHaveLength(0);
});
test.each([
['true', 'true', false],
[undefined, undefined, true],
['false', undefined, false],
['true', undefined, true]
])(
'should get by tag, prerelease: %s, draft: %s',
async (prerelease, draft, expectSuccess) => {
const res = await target.run(options.clone()
.setInputs({
tag: 'testTag',
prerelease: prerelease,
draft: draft,
doNotFailIfNotFound: 'true'
})
);
expect(res.isSuccess).toEqual(true);
expect(res.commands.errors).toEqual([]);
if (expectSuccess) {
expect(res.commands.outputs.id).toEqual('56669824');
}
expect(res.runnerWarnings).toHaveLength(0);
});
test.each([
['true', 'true', undefined],
[undefined, undefined, ['testTag', 'testTagDraft', '1.1.1']],
['false', undefined, ['testTagDraft', '1.1.1']],
[undefined, 'true', ['testTagDraft']],
['true', undefined, ['testTag']],
['false', 'false', ['1.1.1']],
])(
'should get by commit SHA, prerelease: %s, draft: %s, expected tag: %s',
async (prerelease, draft, tagName) => {
const res = await target.run(options.clone()
.setInputs({
commitSha: 'e92acb19de8845ad1f3cb6cfab421ac26002d6b6',
prerelease: prerelease,
draft: draft
})
);
expect(res.isSuccess).toEqual(tagName !== undefined);
if (res.isSuccess) {
expect(tagName).toContain(res.commands.outputs.tag_name);
expect(res.commands.errors).toEqual([]);
} else {
expect(res.commands.errors).not.toEqual([]);
}
expect(res.runnerWarnings).toHaveLength(0);
});
it('should not get by tag', async () => {
const res = await target.run(options.clone()
.setInputs({
tag: 'fjrefbjhb3j43r3',
doNotFailIfNotFound: 'true'
})
);
expect(res.isSuccess).toEqual(true);
expect(res.commands.outputs.id).toBeUndefined();
expect(res.commands.errors).toEqual([]);
expect(res.commands.warnings).not.toEqual([]);
expect(res.runnerWarnings).toHaveLength(0);
});
it('should get by releaseName', async () => {
const res = await target.run(options.clone()
.setInputs({ releaseName: 'Initial release' })
);
expect(res.isSuccess).toEqual(true);
expect(res.commands.outputs.id).toEqual('28737577');
expect(res.commands.outputs.tag_name).toEqual('1.0.0');
expect(res.runnerWarnings).toHaveLength(0);
});
it('should get by releaseNameRegEx', async () => {
const res = await target.run(options.clone()
.setInputs({ releaseNameRegEx: 'searchLimit \\w+' })
);
expect(res.isSuccess).toEqual(true);
expect(res.commands.outputs.name).toEqual('searchLimit input');
expect(res.commands.outputs.tag_name).toEqual('1.1.1');
expect(res.runnerWarnings).toHaveLength(0);
});
})