Skip to content

Commit a59408d

Browse files
Merge pull request #183 from lookout/fail-process
Add an option of exit with fail on tests fail
2 parents 2e28f70 + a89e542 commit a59408d

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ To run browser tests on BrowserStack infrastructure, you need to create a `brows
172172
* `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).
173173
* `build`: A string to identify your test run in Browserstack. In `TRAVIS` setup `TRAVIS_COMMIT` will be the default identifier.
174174
* `proxy`: Specify a proxy to use for the local tunnel. Object with `host`, `port`, `username` and `password` properties.
175+
* `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.
175176

176177
A sample configuration file:
177178

bin/cli.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,11 @@ var statusPoller = {
306306
}
307307

308308
logger.trace('[%s] worker.activityTimeout: all tests done', worker.id, config.status && 'with failures');
309+
var testsFailedError = utils.createTestsFailedError(config);
309310
if(server && server.reports) {
310-
callback(null, server.reports);
311+
callback(testsFailedError, server.reports);
311312
} else {
312-
callback(null, {});
313+
callback(testsFailedError, {});
313314
}
314315
}
315316
} else {
@@ -336,10 +337,11 @@ var statusPoller = {
336337
}
337338

338339
logger.trace('[%s] worker.testActivityTimeout: all tests done', worker.id, config.status && 'with failures');
340+
var testsFailedError = utils.createTestsFailedError(config);
339341
if(server && server.reports) {
340-
callback(null, server.reports);
342+
callback(testsFailedError, server.reports);
341343
} else {
342-
callback(null, {});
344+
callback(testsFailedError, {});
343345
}
344346
}
345347
} else {

bin/runner.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ try {
3939
var runner = require('./cli.js');
4040
runner.run(config, function(err) {
4141
if(err) {
42-
console.error(err);
43-
console.error(err.stack);
44-
console.error('Invalid Command');
42+
if (err.name === 'TestsFailedError') {
43+
console.error('Exit with fail due to some tests failure.');
44+
} else {
45+
console.error(err);
46+
console.error(err.stack);
47+
console.error('Invalid Command');
48+
}
4549
process.exit(1);
4650
}
4751
process.exit(0);

lib/server.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ exports.Server = function Server(bsClient, workers, config, callback) {
476476
}
477477

478478
logger.trace('[%s] _report: checkAndTerminateWorker: all tests done', worker.id, config.status && 'with failures');
479-
callback(null, reports);
479+
var testsFailedError = utils.createTestsFailedError(config);
480+
callback(testsFailedError, reports);
480481
}
481482
});
482483
});

lib/utils.js

+10
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,17 @@ var objectSize = function objectSize(obj) {
4343
return size;
4444
};
4545

46+
var createTestsFailedError = function createTestsFailedError(config) {
47+
var error = null;
48+
if (config.status && config.exit_with_fail) {
49+
error = new Error('Some tests failed.');
50+
error.name = 'TestsFailedError';
51+
}
52+
return error;
53+
};
54+
4655
exports.titleCase = titleCase;
4756
exports.uuid = uuid;
4857
exports.browserString = browserString;
4958
exports.objectSize = objectSize;
59+
exports.createTestsFailedError = createTestsFailedError;

0 commit comments

Comments
 (0)