Skip to content

Commit

Permalink
remove shims to avoid decrease in coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Sep 29, 2017
1 parent 1f3b39a commit 16ffca2
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 262 deletions.
4 changes: 2 additions & 2 deletions browser-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ process.removeListener = function (e, fn) {
} else {
global.onerror = function () {};
}
var i = Mocha.utils.indexOf(uncaughtExceptionHandlers, fn);
var i = uncaughtExceptionHandlers.indexOf(fn);
if (i !== -1) {
uncaughtExceptionHandlers.splice(i, 1);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ Mocha.Runner.immediately = function (callback) {
* only receive the 'message' attribute of the Error.
*/
mocha.throwError = function (err) {
Mocha.utils.forEach(uncaughtExceptionHandlers, function (fn) {
uncaughtExceptionHandlers.forEach(function (fn) {
fn(err);
});
throw err;
Expand Down
3 changes: 1 addition & 2 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ Context.prototype.slow = function (ms) {
* Mark a test as skipped.
*
* @api private
* @return {Context} self
* @throws Pending
*/
Context.prototype.skip = function () {
this.runnable().skip();
return this;
};

/**
Expand Down
33 changes: 14 additions & 19 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@ var utils = require('./utils');
var inherits = utils.inherits;
var debug = require('debug')('mocha:runner');
var Runnable = require('./runnable');
var filter = utils.filter;
var indexOf = utils.indexOf;
var some = utils.some;
var keys = utils.keys;
var stackFilter = utils.stackTraceFilter();
var stringify = utils.stringify;
var type = utils.type;
var undefinedError = utils.undefinedError;
var isArray = utils.isArray;

/**
* Non-enumerable globals.
Expand Down Expand Up @@ -150,11 +145,11 @@ Runner.prototype.grepTotal = function (suite) {
* @api private
*/
Runner.prototype.globalProps = function () {
var props = keys(global);
var props = Object.keys(global);

// non-enumerables
for (var i = 0; i < globals.length; ++i) {
if (~indexOf(props, globals[i])) {
if (~props.indexOf(globals[i])) {
continue;
}
props.push(globals[i]);
Expand Down Expand Up @@ -316,7 +311,7 @@ Runner.prototype.hook = function (name, fn) {
if (name === 'beforeEach' || name === 'afterEach') {
self.test.pending = true;
} else {
utils.forEach(suite.tests, function (test) {
suite.tests.forEach(function (test) {
test.pending = true;
});
// a pending hook won't be executed twice.
Expand Down Expand Up @@ -780,19 +775,19 @@ function cleanSuiteReferences (suite) {
}
}

if (isArray(suite._beforeAll)) {
if (Array.isArray(suite._beforeAll)) {
cleanArrReferences(suite._beforeAll);
}

if (isArray(suite._beforeEach)) {
if (Array.isArray(suite._beforeEach)) {
cleanArrReferences(suite._beforeEach);
}

if (isArray(suite._afterAll)) {
if (Array.isArray(suite._afterAll)) {
cleanArrReferences(suite._afterAll);
}

if (isArray(suite._afterEach)) {
if (Array.isArray(suite._afterEach)) {
cleanArrReferences(suite._afterEach);
}

Expand Down Expand Up @@ -890,16 +885,16 @@ function filterOnly (suite) {
} else {
// Otherwise, do not run any of the tests in this suite.
suite.tests = [];
utils.forEach(suite._onlySuites, function (onlySuite) {
suite._onlySuites.forEach(function (onlySuite) {
// If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
// Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
if (hasOnly(onlySuite)) {
filterOnly(onlySuite);
}
});
// Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
suite.suites = filter(suite.suites, function (childSuite) {
return indexOf(suite._onlySuites, childSuite) !== -1 || filterOnly(childSuite);
suite.suites = suite.suites.filter(function (childSuite) {
return suite._onlySuites.indexOf(childSuite) !== -1 || filterOnly(childSuite);
});
}
// Keep the suite only if there is something to run
Expand All @@ -914,7 +909,7 @@ function filterOnly (suite) {
* @api private
*/
function hasOnly (suite) {
return suite._onlyTests.length || suite._onlySuites.length || some(suite.suites, hasOnly);
return suite._onlyTests.length || suite._onlySuites.length || suite.suites.some(hasOnly);
}

/**
Expand All @@ -926,7 +921,7 @@ function hasOnly (suite) {
* @return {Array}
*/
function filterLeaks (ok, globals) {
return filter(globals, function (key) {
return globals.filter(function (key) {
// Firefox and Chrome exposes iframes as index inside the window object
if (/^\d+/.test(key)) {
return false;
Expand All @@ -950,7 +945,7 @@ function filterLeaks (ok, globals) {
return false;
}

var matched = filter(ok, function (ok) {
var matched = ok.filter(function (ok) {
if (~ok.indexOf('*')) {
return key.indexOf(ok.split('*')[0]) === 0;
}
Expand All @@ -969,7 +964,7 @@ function filterLeaks (ok, globals) {
function extraGlobals () {
if (typeof process === 'object' && typeof process.version === 'string') {
var parts = process.version.split('.');
var nodeVersion = utils.reduce(parts, function (a, v) {
var nodeVersion = parts.reduce(function (a, v) {
return a << 8 | v;
});

Expand Down
6 changes: 3 additions & 3 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ Suite.prototype.titlePath = function () {
* @return {number}
*/
Suite.prototype.total = function () {
return utils.reduce(this.suites, function (sum, suite) {
return this.suites.reduce(function (sum, suite) {
return sum + suite.total();
}, 0) + this.tests.length;
};
Expand All @@ -397,8 +397,8 @@ Suite.prototype.total = function () {
* @return {Suite}
*/
Suite.prototype.eachTest = function (fn) {
utils.forEach(this.tests, fn);
utils.forEach(this.suites, function (suite) {
this.tests.forEach(fn);
this.suites.forEach(function (suite) {
suite.eachTest(fn);
});
return this;
Expand Down
Loading

0 comments on commit 16ffca2

Please sign in to comment.