Skip to content

Commit

Permalink
Made modifications for the two proposed changes:
Browse files Browse the repository at this point in the history
  • Loading branch information
RossVertizan committed Mar 9, 2021
1 parent c6f874f commit 037dfc9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ function Mocha(options = {}) {
this.retries(options.retries);
}

// Read the cleanReferencesAfterRun option
if ('cleanReferencesAfterRun' in options) {
this.cleanReferencesAfterRun(options.cleanReferencesAfterRun);
}

[
'allowUncaught',
'asyncOnly',
Expand Down
31 changes: 26 additions & 5 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,12 @@ Runner.prototype.runTests = function(suite, fn) {
* @param {Suite} suite
* @param {Function} fn
*/
Runner.prototype.runSuite = function(suite, fn) {
Runner.prototype.runSuite = function(suite, fn, opts) {
var i = 0;
var self = this;
var total = this.grepTotal(suite);
// Initialise curr as undefined, but may need to chnage this in the future
var curr;

debug('runSuite(): running %s', suite.fullTitle());

Expand Down Expand Up @@ -880,7 +882,26 @@ Runner.prototype.runSuite = function(suite, fn) {
return done();
}

var curr = suite.suites[i++];
/**
* If opts.nextSuiteSelectFunction is undefined, then behave in the default
* manner, otherwise evaluate the function
*
* opts.nextSuiteSelectFunction has a signature of (suite, currentSuite). It
* should return undefined when the tests are finished.
*/
if (typeof opts.nextSuiteSelectFunction === 'undefined') {
curr = suite.suites[i++];
}
else {
try {
curr = eval(opts.nextSuiteSelectFunction);
}
catch (err) {
debug(err);
console.error(err);
}
}

if (!curr) {
return done();
}
Expand All @@ -890,10 +911,10 @@ Runner.prototype.runSuite = function(suite, fn) {
// See comment in `this.runTests()` for more information.
if (self._grep !== self._defaultGrep) {
Runner.immediately(function() {
self.runSuite(curr, next);
self.runSuite(curr, next, opts);
});
} else {
self.runSuite(curr, next);
self.runSuite(curr, next, opts);
}
}

Expand Down Expand Up @@ -1051,7 +1072,7 @@ Runner.prototype.run = function(fn, opts = {}) {
this.emit(constants.EVENT_RUN_BEGIN);
debug('run(): emitted %s', constants.EVENT_RUN_BEGIN);

this.runSuite(rootSuite, end);
this.runSuite(rootSuite, end, this._opts);
};

const prepare = () => {
Expand Down

0 comments on commit 037dfc9

Please sign in to comment.