Closed
Description
openedon Apr 5, 2016
When using Mocha programmatically with the new retries feature, tests that fail the first time but eventually succeed are not marked as "passed" in the suite's tests
array.
index.js:
var Mocha = require('mocha');
var mocha = new Mocha({
retries: 1
});
mocha.addFile('test.js');
mocha.run().on('suite end', function(suite) {
console.dir(suite);
});
test.js:
var currentRun = 0;
it('should mark tests that succeed on 2nd try as "passed"', function() {
currentRun++;
console.log('running test');
if (currentRun === 1) {
console.log('failing test');
throw new Error('hi');
}
console.log('passing test');
});
Output:
running test
failing test
running test
passing test
✓ should mark tests that succeed on 2nd try as "passed"
Suite {
title: '',
ctx:
Context {
_runnable:
Test {
title: 'should mark tests that succeed on 2nd try as "passed"',
fn: [Function],
async: 0,
sync: true,
_timeout: 2000,
_slow: 75,
_enableTimeouts: true,
timedOut: false,
_trace: [Error: done() called multiple times],
_retries: 1,
_currentRetry: 1,
pending: false,
type: 'test',
body: 'function () {\n currentRun++;\n console.log(\'running test\');\n if (currentRun === 1) {\n console.log(\'failing test\');\n throw new Error(\'hi\');\n }\n console.log(\'passing test\');\n}',
_allowedGlobals: undefined,
parent: [Circular],
file: '/Users/claytonwatts/dev/domo/domoweb/DomoWeb/test.js',
ctx: [Circular],
_events: [Object],
_eventsCount: 1,
callback: [Function: done],
duration: 0,
state: 'passed',
speed: 'fast' },
test:
Test {
title: 'should mark tests that succeed on 2nd try as "passed"',
fn: [Function],
async: 0,
sync: true,
_timeout: 2000,
_slow: 75,
_enableTimeouts: true,
timedOut: false,
_trace: [Error: done() called multiple times],
_retries: 1,
_currentRetry: 1,
pending: false,
type: 'test',
body: 'function () {\n currentRun++;\n console.log(\'running test\');\n if (currentRun === 1) {\n console.log(\'failing test\');\n throw new Error(\'hi\');\n }\n console.log(\'passing test\');\n}',
_allowedGlobals: undefined,
parent: [Circular],
file: '/Users/claytonwatts/dev/domo/domoweb/DomoWeb/test.js',
ctx: [Circular],
_events: [Object],
_eventsCount: 1,
callback: [Function: done],
duration: 0,
state: 'passed',
speed: 'fast' } },
suites: [],
tests:
[ Test {
title: 'should mark tests that succeed on 2nd try as "passed"',
async: 0,
sync: true,
_timeout: 2000,
_slow: 75,
_enableTimeouts: true,
timedOut: false,
_trace: [Error: done() called multiple times],
_retries: 1,
_currentRetry: 0,
pending: false,
type: 'test',
body: 'function () {\n currentRun++;\n console.log(\'running test\');\n if (currentRun === 1) {\n console.log(\'failing test\');\n throw new Error(\'hi\');\n }\n console.log(\'passing test\');\n}',
file: '/Users/claytonwatts/dev/domo/domoweb/DomoWeb/test.js',
parent: [Circular],
ctx: [Object],
_events: [Object],
_eventsCount: 1,
callback: [Function: done],
duration: 0 } ],
pending: false,
_beforeEach: [],
_beforeAll: [],
_afterEach: [],
_afterAll: [],
root: true,
_timeout: 2000,
_enableTimeouts: true,
_slow: 75,
_bail: undefined,
_retries: 1,
delayed: false,
_events: { 'pre-require': [ [Function], [Function] ] },
_eventsCount: 1 }
1 passing (22ms)
Notice that the test objects in Context are correctly marked with state: "passed"
, but the one in the tests
array is from the first run (note _currentRetry: 0
) and has no state
property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment