forked from watson-developer-cloud/node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_integration_test.js
79 lines (70 loc) · 2.26 KB
/
report_integration_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
const fs = require('fs');
const path = require('path');
const axios = require('axios');
const test_output = fs.readFileSync(path.resolve('test-output.log'), { encoding: 'utf8' });
const test_ouput_json = JSON.parse(test_output);
const ansi_regex = new RegExp(
[
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
].join('|'),
'g'
);
const failed_suits = test_ouput_json.testResults.filter(suite => suite.status === 'failed');
const errors = {
service: [],
test: [],
};
failed_suits.map(suite => {
const failed_tests = suite.assertionResults.filter(test => test.status === 'failed');
const error_suite = {
name: suite.name.split('node-sdk/test')[1],
service: [],
test: [],
};
failed_tests.map(result => {
const message_clean = result.failureMessages.join('\n').replace(ansi_regex, '');
error_suite[message_clean.indexOf(/^Received: 5/m) > 0 ? 'service' : 'test'].push(
`${result.fullName}\n${message_clean}`
);
});
errors.service.push(`${error_suite.name}\n${error_suite.service.join('\n')}`);
errors.test.push(`${error_suite.name}\n${error_suite.test.join('\n')}`);
});
let body = '';
if (errors.service.length > 0) {
body = `${body}## Service Failures\n${errors.service.join('\n')}\n`;
}
if (errors.test.length > 0) {
body = `${body}## Possible Test Failures\n${errors.test.join('\n')}\n`;
}
if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false') {
// Send the result to the pull request if it is a pull request.
axios
.post(
`https://api.github.com/repos/${process.env.TRAVIS_REPO_SLUG}/issues/${process.env.TRAVIS_PULL_REQUEST}/comments`,
{
body: body,
},
{
headers: {
'User-Agent': 'watson-github-bot',
Authorization: `token ${process.env.GH_TOKEN}`,
},
}
)
.catch(error => {
console.error(error); // eslint-disable-line
})
.then(() => {
if (errors.test.length > 0) {
process.exit(1); // eslint-disable-line
}
});
} else {
// Write to stdout
console.log(body); // eslint-disable-line
if (errors.test.length > 0) {
process.exit(1); // eslint-disable-line
}
}