Skip to content

Commit

Permalink
Merge pull request #2 from Lana-Light/patch-4
Browse files Browse the repository at this point in the history
Patch 4
  • Loading branch information
Lana-Light authored Dec 22, 2018
2 parents a8283dd + 0eda3bd commit 8736b46
Show file tree
Hide file tree
Showing 44 changed files with 2,578 additions and 3,782 deletions.
58 changes: 44 additions & 14 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ parserOptions:
ecmaVersion: 5
ecmaFeatures:
globalReturn: no
experimentalObjectRestSpread: no
jsx: no
sourceType: script
rules:
Expand All @@ -18,30 +17,61 @@ rules:
- safe
overrides:
- files:
- scripts/**/*.js
- package-scripts.js
- karma.conf.js
- .wallaby.js
- bin/*
- lib/cli/**/*.js
- test/node-unit/**/*.js
- scripts/**/*.js
- package-scripts.js
- karma.conf.js
- .wallaby.js
- bin/*
- lib/cli/**/*.js
- test/node-unit/**/*.js
parserOptions:
ecmaVersion: 6
env:
browser: no

- files:
- test/**/*.{js,mjs}
- test/**/*.{js,mjs}
env:
mocha: yes
globals:
expect: no
- files:
- doc/**/*.js
env:
node: no
- bin/*
- lib/**/*.js
rules:
no-restricted-globals:
- error
- name: setTimeout
message: &GH-237 See https://github.com/mochajs/mocha/issues/237
- name: clearTimeout
message: *GH-237
- name: setInterval
message: *GH-237
- name: clearInterval
message: *GH-237
- name: setImmediate
message: *GH-237
- name: clearImmediate
message: *GH-237
- name: Date
message: *GH-237
no-restricted-modules:
- error
- timers
no-restricted-syntax:
- error
# disallow `global.setTimeout()`, `global.setInterval()`, etc.
- selector: 'CallExpression[callee.object.name=global][callee.property.name=/(set|clear)(Timeout|Immediate|Interval)/]'
message: *GH-237
# disallow `new global.Date()`
- selector: 'NewExpression[callee.object.name=global][callee.property.name=Date]'
message: *GH-237
# disallow property access of `global.<timer>.*`
- selector: '*[object.object.name=global][object.property.name=/(Date|(set|clear)(Timeout|Immediate|Interval))/]:expression'
message: *GH-237

- files:
- test/**/*.mjs
- test/**/*.mjs
parserOptions:
ecmaVersion: 6
sourceType: module

3 changes: 2 additions & 1 deletion .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"linters": {
"(bin/*|*.{js,json}|**/*.{js,json})": ["prettier-eslint --write", "git add"]
"(bin/*|*.js|**/*.js)": ["eslint --fix", "git add"],
"(*.{json,yml}|**/*.{json,yml})": ["prettier --write", "git add"]
},
"ignore": ["docs/**/*.js", "test/**/*.fixture.js", "package*.json"]
}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ node_js: '11'
addons:
apt:
packages:
- libnotify-bin
- libnotify-bin
# `nvm install` happens before the cache is restored, which means
# we must install our own npm elsewhere (`~/npm`)
before_install: |
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ Enforce a rule that tests must be written in "async" style, meaning each test pr

### `--bail, -b`

Causes Mocha to stop running tests after the first test failure it encounters.
Causes Mocha to stop running tests after the first test failure it encounters. Corresponding `after()` and `afterEach()` hooks are executed for potential cleanup.

`--bail` does *not* imply `--exit`.

Expand Down
3 changes: 1 addition & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ module.exports = config => {
browserify: {
debug: true,
configure: function configure(b) {
b
.ignore('glob')
b.ignore('glob')
.ignore('fs')
.ignore('path')
.ignore('supports-color')
Expand Down
13 changes: 0 additions & 13 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ var supportsColor = process.browser ? null : require('supports-color');

exports = module.exports = Base;

/**
* Save timer references to avoid Sinon interfering.
* See: https://github.com/mochajs/mocha/issues/237
*/

/* eslint-disable no-unused-vars, no-native-reassign */
var Date = global.Date;
var setTimeout = global.setTimeout;
var setInterval = global.setInterval;
var clearTimeout = global.clearTimeout;
var clearInterval = global.clearInterval;
/* eslint-enable no-unused-vars, no-native-reassign */

/**
* Check if both stdio streams are associated with a tty.
*/
Expand Down
8 changes: 1 addition & 7 deletions lib/reporters/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@ var escape = utils.escape;
* Save timer references to avoid Sinon interfering (see GH-237).
*/

/* eslint-disable no-unused-vars, no-native-reassign */
var Date = global.Date;
var setTimeout = global.setTimeout;
var setInterval = global.setInterval;
var clearTimeout = global.clearTimeout;
var clearInterval = global.clearInterval;
/* eslint-enable no-unused-vars, no-native-reassign */

/**
* Expose `HTML`.
Expand Down Expand Up @@ -232,7 +226,7 @@ function HTML(runner) {

function updateStats() {
// TODO: add to stats
var percent = (stats.tests / runner.total * 100) | 0;
var percent = ((stats.tests / runner.total) * 100) | 0;
if (progress) {
progress.update(percent).draw(ctx);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/landing.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function Landing(runner) {

runner.on('test end', function(test) {
// check if the plane crashed
var col = crashed === -1 ? (width * ++n / total) | 0 : crashed;
var col = crashed === -1 ? ((width * ++n) / total) | 0 : crashed;

// show the crash
if (test.state === 'failed') {
Expand Down
7 changes: 0 additions & 7 deletions lib/reporters/xunit.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ var path = require('path');
/**
* Save timer references to avoid Sinon interfering (see GH-237).
*/

/* eslint-disable no-unused-vars, no-native-reassign */
var Date = global.Date;
var setTimeout = global.setTimeout;
var setInterval = global.setInterval;
var clearTimeout = global.clearTimeout;
var clearInterval = global.clearInterval;
/* eslint-enable no-unused-vars, no-native-reassign */

/**
* Expose `XUnit`.
Expand Down
6 changes: 0 additions & 6 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ var utils = require('./utils');
/**
* Save timer references to avoid Sinon interfering (see GH-237).
*/

/* eslint-disable no-unused-vars, no-native-reassign */
var Date = global.Date;
var setTimeout = global.setTimeout;
var setInterval = global.setInterval;
var clearTimeout = global.clearTimeout;
var clearInterval = global.clearInterval;
/* eslint-enable no-unused-vars, no-native-reassign */

var toString = Object.prototype.toString;

module.exports = Runnable;
Expand Down
14 changes: 6 additions & 8 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,14 @@ Runner.prototype.fail = function(test, err) {
}

this.emit('fail', test, err);
if (this.suite.bail()) {
this.emit('end');
}
};

/**
* Fail the given `hook` with `err`.
*
* Hook failures work in the following pattern:
* - If bail, then exit
* - If bail, run corresponding `after each` and `after` hooks,
* then exit
* - Failed `before` hook skips all tests in a suite and subsuites,
* but jumps to corresponding `after` hook
* - Failed `before each` hook skips remaining tests in a
Expand Down Expand Up @@ -494,7 +492,7 @@ Runner.prototype.runTests = function(suite, fn) {
function next(err, errSuite) {
// if we bail after first err
if (self.failures && suite._bail) {
return fn();
tests = [];
}

if (self._abort) {
Expand Down Expand Up @@ -710,9 +708,9 @@ Runner.prototype.uncaught = function(err) {
debug(
'uncaught exception %s',
err ===
function() {
return this;
}.call(err)
function() {
return this;
}.call(err)
? err.message || err
: err
);
Expand Down
2 changes: 2 additions & 0 deletions lib/stats-collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* @property {number} duration - number of msecs that testing took.
*/

var Date = global.Date;

/**
* Provides stats such as test duration, number of tests passed / failed etc., by listening for events emitted by `runner`.
*
Expand Down
3 changes: 1 addition & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ exports.files = function(dir, ext, ret) {

var re = new RegExp('\\.(' + ext.join('|') + ')$');

fs
.readdirSync(dir)
fs.readdirSync(dir)
.filter(ignored)
.forEach(function(path) {
path = join(dir, path);
Expand Down
Loading

0 comments on commit 8736b46

Please sign in to comment.