Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ To run browser tests on BrowserStack infrastructure, you need to create a `brows
* `browsers`: A list of browsers on which tests are to be run. Find a [list of all supported browsers and platforms on browerstack.com](https://www.browserstack.com/list-of-browsers-and-platforms?product=js_testing).
* `build`: A string to identify your test run in Browserstack. In `TRAVIS` setup `TRAVIS_COMMIT` will be the default identifier.
* `proxy`: Specify a proxy to use for the local tunnel. Object with `host`, `port`, `username` and `password` properties.
* `exit_with_fail`: If set to true the cli process will exit with fail if any of the tests failed. Useful for automatic build systems.

A sample configuration file:

Expand Down
10 changes: 6 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,11 @@ var statusPoller = {
}

logger.trace('[%s] worker.activityTimeout: all tests done', worker.id, config.status && 'with failures');
var testsFailedError = utils.createTestsFailedError(config);
if(server && server.reports) {
callback(null, server.reports);
callback(testsFailedError, server.reports);
} else {
callback(null, {});
callback(testsFailedError, {});
}
}
} else {
Expand All @@ -336,10 +337,11 @@ var statusPoller = {
}

logger.trace('[%s] worker.testActivityTimeout: all tests done', worker.id, config.status && 'with failures');
var testsFailedError = utils.createTestsFailedError(config);
if(server && server.reports) {
callback(null, server.reports);
callback(testsFailedError, server.reports);
} else {
callback(null, {});
callback(testsFailedError, {});
}
}
} else {
Expand Down
10 changes: 7 additions & 3 deletions bin/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ try {
var runner = require('./cli.js');
runner.run(config, function(err) {
if(err) {
console.error(err);
console.error(err.stack);
console.error('Invalid Command');
if (err.name === 'TestsFailedError') {
console.error('Exit with fail due to some tests failure.');
} else {
console.error(err);
console.error(err.stack);
console.error('Invalid Command');
}
process.exit(1);
}
process.exit(0);
Expand Down
3 changes: 2 additions & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ exports.Server = function Server(bsClient, workers, config, callback) {
}

logger.trace('[%s] _report: checkAndTerminateWorker: all tests done', worker.id, config.status && 'with failures');
callback(null, reports);
var testsFailedError = utils.createTestsFailedError(config);
callback(testsFailedError, reports);
}
});
});
Expand Down
10 changes: 10 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ var objectSize = function objectSize(obj) {
return size;
};

var createTestsFailedError = function createTestsFailedError(config) {
var error = null;
if (config.status && config.exit_with_fail) {
error = new Error('Some tests failed.');
error.name = 'TestsFailedError';
}
return error;
};

exports.titleCase = titleCase;
exports.uuid = uuid;
exports.browserString = browserString;
exports.objectSize = objectSize;
exports.createTestsFailedError = createTestsFailedError;