Skip to content

Commit d69a2ae

Browse files
committed
Added support to exit using non-zero exit code on mocha failures
1 parent b92ed62 commit d69a2ae

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

examples/mocha/github.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ describe('Github', function() {
55
.url('https://github.com/nightwatchjs/nightwatch')
66
.waitForElementVisible('body', 1000)
77
.assert.title('nightwatchjs/nightwatch · GitHub')
8-
.assert.visible('.container .breadcrumb a span')
9-
.assert.containsText('.container .breadcrumb a span', 'nightwatch', 'Checking project title is set to nightwatch');
8+
.assert.visible('.container h1 strong a')
9+
.assert.containsText('.container h1 strong a', 'nightwatch', 'Checking project title is set to nightwatch');
1010
});
1111

1212
after(function(client, done) {
13-
client.end(function() {
13+
if (client.sessionId) {
14+
client.end(function() {
15+
done();
16+
});
17+
} else {
1418
done();
15-
});
19+
}
1620
});
1721

1822
});

examples/tests/github.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ module.exports = {
33
'Demo test GitHub' : function (client) {
44
client
55
.url('https://github.com/nightwatchjs/nightwatch')
6-
.waitForElementVisible('body', 1000)
6+
.waitForElementVisible('xbody', 1000)
77
.assert.title('nightwatchjs/nightwatch · GitHub')
8-
.assert.visible('.container .breadcrumb a span')
9-
.assert.containsText('.container .breadcrumb a span', 'nightwatch', 'Checking project title is set to nightwatch');
8+
.assert.visible('.container h1 strong a')
9+
.assert.containsText('.container h1 strong a', 'nightwatch', 'Checking project title is set to nightwatch');
1010
},
1111

1212
after : function(client) {

lib/runner/cli/clirunner.js

+4
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ CliRunner.prototype = {
392392
fn(null, {
393393
failed : failures
394394
});
395+
396+
if (failures) {
397+
process.exit(10);
398+
}
395399
});
396400

397401
}.bind(this));

tests/run_tests.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ try {
3232
'src/runner',
3333
'src/expect',
3434
'src/page-object',
35-
'src/mocha',
3635
'src/protocol',
3736
'src/http',
3837
'src/index',
3938
'src/assertions',
40-
'src/commands'
39+
'src/mocha',
40+
'src/commands',
41+
4142
], options, function(err) {
4243
setTimeout(function() {
4344
server.close();

tests/src/mocha/testMochaIntegration.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var BASE_PATH = process.env.NIGHTWATCH_COV ? 'lib-cov' : 'lib';
22
var CliRunner = require('../../../'+ BASE_PATH +'/runner/cli/clirunner.js');
33

4+
var originalExit = process.exit;
45
module.exports = {
56
setUp: function(callback) {
67

@@ -10,6 +11,7 @@ module.exports = {
1011
tearDown: function(callback) {
1112
process.removeAllListeners('exit');
1213
process.removeAllListeners('uncaughtException');
14+
process.exit = originalExit;
1315
callback();
1416
},
1517

@@ -19,15 +21,19 @@ module.exports = {
1921
env : 'default'
2022
}).init();
2123

24+
test.expect(15);
2225
runner.test_settings.globals = {
2326
test : test
2427
};
2528

26-
test.expect(14);
29+
process.exit = function(code) {
30+
test.equals(code, 10);
31+
test.done();
32+
};
33+
2734
runner.runner(function(err, results) {
2835
test.equals(err, null);
2936
test.equals(results.failed, 2);
30-
test.done();
3137
});
3238
}
3339
};

0 commit comments

Comments
 (0)