-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
73 lines (68 loc) · 2.54 KB
/
index.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
const fs = require('fs');
const { spawn } = require('child_process');
const core = require('@actions/core');
const { WebClient } = require('@slack/web-api');
async function run() {
const web = new WebClient(core.getInput('slack-token'));
const test = spawn('npx', ['playwright', 'test'], { env: { ...process.env, URL: core.getInput('url'), PROD: core.getInput('prod') }});
let output = ''
let failedTestOutput = ''
let failedTests = 0
let warnings = 0
test.stdout.on('data', data => {
output += data
data = data.toString()
if (data.includes(`${failedTests + 1})`)) {
data = data.slice(0, data.search(/[1-9]{1,3} \|/)).trim()
data = data.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')
failedTestOutput += '```' + data + '```' + '\n'
failedTests++
} else if (data.includes('Warning:')) {
failedTestOutput += data + '\n'
warnings += 1
}
});
test.on('close', async () => {
if (failedTests) {
const message = await web.chat.postMessage({
attachments: [{'color': '#cc0000', 'text': `${failedTests} Tests failed :x:`, fallback: `${failedTests} Tests failed :x:`}],
channel: core.getInput('slack-channel'),
});
await web.chat.postMessage({
text: failedTestOutput,
channel: core.getInput('slack-channel'),
thread_ts: message.ts
})
if (fs.existsSync('./comparison')) {
const files = fs.readdirSync('./comparison');
files.forEach((filename) => {
web.files.upload({
file: fs.createReadStream('./comparison/' + filename),
channels: core.getInput('slack-channel'),
thread_ts: message.ts
})
})
}
core.info(output)
core.setFailed('Tests failed')
} else if(warnings) {
const message = await web.chat.postMessage({
attachments: [{'color': '#ffcc00', 'text': `Tests passed with ${warnings} warnings :warning:`, fallback: `Tests passed with ${warnings} warnings :warning:`}],
channel: core.getInput('slack-channel'),
});
await web.chat.postMessage({
text: failedTestOutput,
channel: core.getInput('slack-channel'),
thread_ts: message.ts
})
core.info(output)
} else {
await web.chat.postMessage({
attachments: [{'color': '#36a64f', 'text': 'All tests passed :white_check_mark:', fallback: 'All tests passed :white_check_mark:'}],
channel: core.getInput('slack-channel'),
});
core.info(output)
}
});
}
run()