Skip to content

Commit fb6e3e6

Browse files
build: do not fail integration test when service is flaky (#874)
build: do not fail integration test when service is flaky
2 parents f97aa72 + b6ce2a6 commit fb6e3e6

16 files changed

+1542
-843
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ sdk.js
4242
**/*.js.map
4343
coverage.lcov
4444
.swagger-codegen-ignore
45+
*.log
46+
*.tmp

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ before_install:
1414
- npm install -g typescript
1515
script:
1616
- tsc
17-
- if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then npm run test-travis; else npm run
18-
test-unit-travis; fi
17+
- npm run test-unit-travis || travis_terminate 1
18+
- npm run test-integration-travis || node scripts/report_integration_test.js || (cat test-output.log && travis_terminate 1)
1919
- npm run check-packages
2020
- sh scripts/typedoc/generate_typedoc.sh
2121
after_success:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"test-unit": "jest --silent --verbose test/unit/",
119119
"test": "jest --silent --verbose test/",
120120
"test-unit-travis": "jest --silent --runInBand test/unit/",
121-
"test-travis": "jest --silent --runInBand --testNamePattern='^((?!@slow).)*$' test/",
121+
"test-integration-travis": "jest --silent --runInBand --no-colors --testNamePattern='^((?!@slow).)*$' --json test/integration > test-output.log",
122122
"report-coverage": "codecov",
123123
"watch-doc": "nodemon --watch ./ --ext js,tmpl,json --ignore dist/ --ignore doc/ --ignore test/ --ignore examples/ --exec npm run doc",
124124
"watch": "npm run test-unit -- --watch",

scripts/report_integration_test.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const axios = require('axios');
4+
const test_output = fs.readFileSync(path.resolve('test-output.log'), { encoding: 'utf8' });
5+
const test_ouput_json = JSON.parse(test_output);
6+
const ansi_regex = new RegExp(
7+
[
8+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
9+
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
10+
].join('|'),
11+
'g'
12+
);
13+
14+
const failed_suits = test_ouput_json.testResults.filter(suite => suite.status === 'failed');
15+
16+
const errors = {
17+
service: [],
18+
test: [],
19+
};
20+
21+
failed_suits.map(suite => {
22+
const failed_tests = suite.assertionResults.filter(test => test.status === 'failed');
23+
const error_suite = {
24+
name: suite.name.split('node-sdk/test')[1],
25+
service: [],
26+
test: [],
27+
};
28+
29+
failed_tests.map(result => {
30+
const message_clean = result.failureMessages.join('\n').replace(ansi_regex, '');
31+
error_suite[message_clean.indexOf(/^Received: 5/m) > 0 ? 'service' : 'test'].push(
32+
`${result.fullName}\n${message_clean}`
33+
);
34+
});
35+
36+
errors.service.push(`${error_suite.name}\n${error_suite.service.join('\n')}`);
37+
errors.test.push(`${error_suite.name}\n${error_suite.test.join('\n')}`);
38+
});
39+
40+
let body = '';
41+
if (errors.service.length > 0) {
42+
body = `${body}## Service Failures\n${errors.service.join('\n')}\n`;
43+
}
44+
45+
if (errors.test.length > 0) {
46+
body = `${body}## Possible Test Failures\n${errors.test.join('\n')}\n`;
47+
}
48+
49+
if (process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false') {
50+
// Send the result to the pull request if it is a pull request.
51+
axios
52+
.post(
53+
`https://api.github.com/repos/${process.env.TRAVIS_REPO_SLUG}/issues/${
54+
process.env.TRAVIS_PULL_REQUEST
55+
}/comments`,
56+
{
57+
body: body,
58+
},
59+
{
60+
headers: {
61+
'User-Agent': 'watson-github-bot',
62+
Authorization: `token ${process.env.GH_TOKEN}`,
63+
},
64+
}
65+
)
66+
.catch(error => {
67+
console.error(error); // eslint-disable-line
68+
})
69+
.then(() => {
70+
if (errors.test.length > 0) {
71+
process.exit(1); // eslint-disable-line
72+
}
73+
});
74+
} else {
75+
// Write to stdout
76+
console.log(body); // eslint-disable-line
77+
78+
if (errors.test.length > 0) {
79+
process.exit(1); // eslint-disable-line
80+
}
81+
}

0 commit comments

Comments
 (0)