-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #2582 - making sure the test results are not discarded when an …
…uncaught exception occurs.
- Loading branch information
1 parent
edd0c77
commit 373fa1a
Showing
5 changed files
with
136 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe('passing test', function () { | ||
|
||
this.tags = ['uncaught-error']; | ||
|
||
test('demo Test Passing', function (client) { | ||
client | ||
.url('http://localhost') | ||
.assert.elementPresent('#weblogin') | ||
.waitForElementPresent('#weblogin') | ||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
describe('test with uncaught error', function () { | ||
|
||
this.tags = ['uncaught-error']; | ||
|
||
test('Passing test step', function (client) { | ||
client | ||
.url('http://localhost') | ||
.assert.elementPresent('#weblogin'); | ||
}); | ||
|
||
test('Uncaught error test step', function (client) { | ||
client.assert.elementPresent('#weblogin'); | ||
|
||
setTimeout(function () { | ||
throw new Error('Test Error Uncaught'); | ||
}, 25); | ||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
const common = require('../../common.js'); | ||
const MockServer = require('../../lib/mockserver.js'); | ||
const NightwatchClient = common.require('index.js'); | ||
|
||
describe('testRunWithUncaughtErrors', function() { | ||
|
||
before(function(done) { | ||
this.server = MockServer.init(); | ||
this.server.on('listening', () => { | ||
done(); | ||
}); | ||
}); | ||
|
||
after(function(done) { | ||
this.server.close(function() { | ||
done(); | ||
}); | ||
}); | ||
|
||
beforeEach(function() { | ||
process.removeAllListeners('exit'); | ||
process.removeAllListeners('uncaughtException'); | ||
process.removeAllListeners('unhandledRejection'); | ||
}); | ||
|
||
it('test runner with uncaught exception', function(done) { | ||
let testsPath = path.join(__dirname, '../../sampletests/withuncaughterrors'); | ||
let errorReported = false; | ||
let testErr; | ||
|
||
let globals = { | ||
reporter(results) { | ||
if (results.errmessages.length) { | ||
errorReported = true; | ||
try { | ||
assert.strictEqual(typeof results.modules.demoTestFine, 'object'); | ||
assert.strictEqual(typeof results.modules.demoTestWithError, 'object'); | ||
assert.strictEqual(results.passed, 4); | ||
assert.strictEqual(results.errors, 1); | ||
assert.strictEqual(results.assertions, 4); | ||
assert.strictEqual(results.modules.demoTestFine.assertionsCount, 2); | ||
assert.strictEqual(results.modules.demoTestFine.passedCount, 2); | ||
assert.strictEqual(results.modules.demoTestWithError.assertionsCount, 2); | ||
assert.strictEqual(results.modules.demoTestWithError.passedCount, 2); | ||
assert.ok(results.errmessages[0].includes('Error: Test Error Uncaught')); | ||
} catch (e) { | ||
testErr = e; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
|
||
const orig = process.exit; | ||
process.exit = function(code) {}; | ||
|
||
NightwatchClient.runTests(testsPath, { | ||
selenium: { | ||
port: 10195, | ||
version2: true, | ||
start_process: true | ||
}, | ||
output: true, | ||
silent: false, | ||
persist_globals: true, | ||
globals: globals, | ||
output_folder: false | ||
}); | ||
|
||
setTimeout(function () { | ||
process.exit = orig; | ||
try { | ||
if (testErr) { | ||
done(testErr); | ||
return; | ||
} | ||
|
||
assert.strictEqual(errorReported, true); | ||
done(); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}, 500); | ||
}); | ||
}); |