-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathutils.test.js
57 lines (47 loc) · 1.56 KB
/
utils.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
const fs = require('fs');
const crypto = require('crypto');
const execSync = require('child_process').execSync;
const utils = require('./utils');
const process = require('process');
const octokitFixtures = require("@octokit/fixtures");
const github = require('@actions/github');
const env = Object.assign({}, process.env);
const testLogFile = 'tempfile'+crypto.randomBytes(4).readUInt32LE(0);
const testLogFileMessage = `logline1
logline2
logline4
logline5`
beforeAll(() => {
fs.writeFileSync(testLogFile, testLogFileMessage);
execSync(`zip ${testLogFile}.zip ${testLogFile}`)
});
afterAll(() => {
process.env = env;
fs.unlinkSync(testLogFile)
fs.unlinkSync(testLogFile + ".zip")
});
test('format markdown block', async() => {
expect(utils.formatMarkdownBlock("test")).toEqual("```\ntest\n```\n")
});
test('format markdown block collapsible', async() => {
expect(utils.formatMarkdownBlock("test", true)).toEqual(
"<details><summary>Expand</summary>\n<br>\n\n```\ntest\n```\n</details>\n"
)
});
test('apply message modifier', async() => {
expect(utils.applyMessageModifier("test\ntest2", "grep test2")).toEqual("test2\n")
});
test('get workflow run', async() => {
process.env.GITHUB_REPOSITORY = "test/test"
process.env.GITHUB_RUN_ID = "123"
octokitFixtures.nock("https://api.github.com")
.get("/repos/test/test/actions/runs/123")
.reply(200, {
"workflow_id": 772800
});
expect((await utils.getRun(new github.GitHub("123")))).toEqual(
{
"workflow_id": 772800
}
);
});