Closed
Description
Description
I want to run mocha tests programmatically multiple times.
I'm aware of the workaround with deleting require.cache but it works only for a small number of tests.
Steps to Reproduce
let mocha = new Mocha({
ui: 'bdd',
reporter: 'spec',
useColors: true,
timeout: 50000,
fullTrace: true
});
let alltests = 10, finished = 0;
for(let id=0;id<alltests;id++) {
let filename = '../test/sometest.spec.js';
mocha.addFile(filename);
mocha.run(failures => {
if(failures)
logger.error('#' +id + ' All done - test failures: ', failures);
})
.on('test', function(test) {
logger.info('#' +id + ' Test started: '+test.title);
})
.on('test end', function(test) {
logger.info('#' +id + ' Test done: '+test.title);
})
.on('pass', function(test) {
logger.info('#' +id + ' Test passed: '+test.title);
})
.on('fail', function(test, err) {
logger.info('#' +id + ' Test fail: '+test.title, err);
})
.on('end', function() {
logger.info('#' +id + ' All done');
});
//mocha.suite.suites = [];
let p = path.resolve(path.join(__dirname, filename));
let rp = require.resolve(p);
delete require.cache[rp];
}
Expected behavior:
All 10 runs should pass
Actual behavior:
First 7 runs pass, the last 3 runs fail with error:
TypeError: Cannot read property 'call' of undefined
If I uncomment mocha.suite.suites = [], all tests end right away.
Reproduces how often:
always
Versions
mocha --version: 3.5.3
node node_modules/.bin/mocha --version: 3.5.3
node --version: v6.11.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment