Skip to content

Commit

Permalink
[CI] Unit test webdriver script exit code depends on test failure
Browse files Browse the repository at this point in the history
Unit test webdriver script now parses the Mocha test results XML to see
if any tests failed and if so, exit with a nonzero exit code, so that
CircleCI will report a CI failure
  • Loading branch information
laughinghan committed Sep 1, 2022
1 parent 98325ac commit d6deba1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions script/unit_test_webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ if (!baseDir) {
process.exit(1);
}

var success = true

var browserDriver = wd.promiseChainRemote('ondemand.saucelabs.com', 80, username, accessKey);
browserDriver.init({
browserName: 'Chrome',
Expand All @@ -40,12 +42,21 @@ browserDriver.init({
fs.writeFileSync(baseDir + '/test-results.xml', resultsXML);
console.log('Wrote to ' + baseDir + '/test-results.xml');

// TODO: exit status based on whether tests passed
const [_, failures, errors] = lines[0].match(/ failures="(\d+)" errors="(\d+)"/)
console.log(failures + ' failures, ' + errors + ' errors');
success = (failures + errors === 0);
})
.fail(function(err) {
console.log('ERROR:', JSON.stringify(err, null, 2));
success = false;
})
.then(function() {
return browserDriver.sauceJobStatus(success);
})
.quit();
.quit()
.then(function() {
process.exit(success ? 0 : 1);
});

function willLog() {
var msg = [].join.call(arguments, ' ');
Expand Down

0 comments on commit d6deba1

Please sign in to comment.