Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull authored Dec 7, 2017
2 parents 760b4db + 709a09e commit 24b65e8
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 127 deletions.
1 change: 1 addition & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ exemptLabels:
- reporter
- common-mistake
- developer-experience
- good-first-issue
# Label to use when marking an issue as stale
staleLabel: stale
# Comment to post when marking an issue as stale. Set to `false` to disable
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@
*Thank you* :kissing_heart: to all of you interested in helping. These are Mocha's immediate needs:

1. Increase test coverage on Node.js and browser
- Increase integration coverage for all reporters
- `html` reporter must be tested in browser
- ~~Basic console reporters (*not* `nyan`, `landing`, etc.) must be tested in **both** browser and Node.js contexts; PhantomJS can consume all console reporters~~
- ~~Filesystem-based reporters must be tested in Node.js context~~
- **UPDATE - May 24 2017**: Thanks to [community contributions](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#mag-coverage), the coverage on most reporters has increased dramatically! The `html` reporter is still in [dire need of coverage](https://coveralls.io/builds/11674428/source?filename=lib%2Freporters%2Fhtml.js).
- Increase coverage against all interfaces (`exports` in particular). Ideally this becomes a "matrix" where we repeat sets of integration tests across all interfaces.
- Refactor non-Node.js-specific tests to allow them to run in a browser context. Node.js-specific tests include those which *require* the CLI or filesystem. Most everything else is fair game.
- Increase integration coverage for all reporters
- `html` reporter must be tested in browser
- ~~Basic console reporters (*not* `nyan`, `landing`, etc.) must be tested in **both** browser and Node.js contexts; PhantomJS can consume all console reporters~~
- ~~Filesystem-based reporters must be tested in Node.js context~~
- **UPDATE - May 24 2017**: Thanks to [community contributions](https://github.com/mochajs/mocha/blob/master/CHANGELOG.md#mag-coverage), the coverage on most reporters has increased dramatically! The `html` reporter is still in [dire need of coverage](https://coveralls.io/builds/11674428/source?filename=lib%2Freporters%2Fhtml.js).
- Increase coverage against all interfaces (`exports` in particular). Ideally this becomes a "matrix" where we repeat sets of integration tests across all interfaces.
- Refactor non-Node.js-specific tests to allow them to run in a browser context. Node.js-specific tests include those which *require* the CLI or filesystem. Most everything else is fair game.
2. Review current open pull requests
- We need individuals familiar with Mocha's codebase. Got questions? Ask them in [our chat room](https://gitter.im/mochajs/mocha).
- Pull requests **must** have supporting tests. The only exceptions are pure cosmetic or non-functional changes.
- Pull request contributors must sign [the CLA](https://cla.js.foundation/mochajs/mocha).
- We need individuals familiar with Mocha's codebase. Got questions? Ask them in [our chat room](https://gitter.im/mochajs/mocha).
- Pull requests **must** have supporting tests. The only exceptions are pure cosmetic or non-functional changes.
- Pull request contributors must sign [the CLA](https://cla.js.foundation/mochajs/mocha).
3. Close old, inactive issues and pull requests
- ~~A bot should do this. We need a bot. Got a bot?~~ We now use GitHub's own [probot-stale](https://www.npmjs.com/package/probot-stale).
- ~~A bot should do this. We need a bot. Got a bot?~~ We now use GitHub's own [probot-stale](https://www.npmjs.com/package/probot-stale).
4. Triage issues
- If we run into "critical" bugs, they need fixing.
- "Critical" means Mocha is broken w/o workarounds for a *large percentage* of users
- Otherwise: respond to issues, close new dupe issues, confirm bugs, ask for more info, etc.
- If we run into "critical" bugs, they need fixing.
- "Critical" means Mocha is broken w/o workarounds for a *large percentage* of users
- Otherwise: respond to issues, close new dupe issues, confirm bugs, ask for more info, etc.

Once we gain ground on the above items, we can work together formalize our contribution guidelines and governance. For further info & ideas, please see our [projects](https://github.com/mochajs/mocha/projects/).

Expand Down
12 changes: 9 additions & 3 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Context.prototype.runnable = function (runnable) {
};

/**
* Set test timeout `ms`.
* Set or get test timeout `ms`.
*
* @api private
* @param {number} ms
Expand All @@ -51,18 +51,24 @@ Context.prototype.timeout = function (ms) {
* @return {Context} self
*/
Context.prototype.enableTimeouts = function (enabled) {
if (!arguments.length) {
return this.runnable().enableTimeouts();
}
this.runnable().enableTimeouts(enabled);
return this;
};

/**
* Set test slowness threshold `ms`.
* Set or get test slowness threshold `ms`.
*
* @api private
* @param {number} ms
* @return {Context} self
*/
Context.prototype.slow = function (ms) {
if (!arguments.length) {
return this.runnable().slow();
}
this.runnable().slow(ms);
return this;
};
Expand All @@ -78,7 +84,7 @@ Context.prototype.skip = function () {
};

/**
* Allow a number of retries on failed tests
* Set or get a number of allowed retries on failed tests
*
* @api private
* @param {number} n
Expand Down
8 changes: 8 additions & 0 deletions lib/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,14 @@ Mocha.prototype.forbidPending = function () {
/**
* Run tests and invoke `fn()` when complete.
*
* Note that `loadFiles` relies on Node's `require` to execute
* the test interface functions and will be subject to the
* cache - if the files are already in the `require` cache,
* they will effectively be skipped. Therefore, to run tests
* multiple times or to run tests in files that are already
* in the `require` cache, make sure to clear them from the
* cache first in whichever manner best suits your needs.
*
* @api public
* @param {Function} fn
* @return {Runner}
Expand Down
48 changes: 4 additions & 44 deletions lib/ms.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,15 @@ var y = d * 365.25;
/**
* Parse or format the given `val`.
*
* Options:
*
* - `long` verbose formatting [false]
*
* @api public
* @param {string|number} val
* @param {Object} options
* @return {string|number}
*/
module.exports = function (val, options) {
options = options || {};
module.exports = function (val) {
if (typeof val === 'string') {
return parse(val);
}
// https://github.com/mochajs/mocha/pull/1035
return options['long'] ? longFormat(val) : shortFormat(val);
return format(val);
};

/**
Expand Down Expand Up @@ -74,13 +67,13 @@ function parse (str) {
}

/**
* Short format for `ms`.
* Format for `ms`.
*
* @api private
* @param {number} ms
* @return {string}
*/
function shortFormat (ms) {
function format (ms) {
if (ms >= d) {
return Math.round(ms / d) + 'd';
}
Expand All @@ -95,36 +88,3 @@ function shortFormat (ms) {
}
return ms + 'ms';
}

/**
* Long format for `ms`.
*
* @api private
* @param {number} ms
* @return {string}
*/
function longFormat (ms) {
return plural(ms, d, 'day') ||
plural(ms, h, 'hour') ||
plural(ms, m, 'minute') ||
plural(ms, s, 'second') ||
ms + ' ms';
}

/**
* Pluralization helper.
*
* @api private
* @param {number} ms
* @param {number} n
* @param {string} name
*/
function plural (ms, n, name) {
if (ms < n) {
return;
}
if (ms < n * 1.5) {
return Math.floor(ms / n) + ' ' + name;
}
return Math.ceil(ms / n) + ' ' + name + 's';
}
38 changes: 7 additions & 31 deletions lib/reporters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ exports.list = function (failures) {
}
var stack = err.stack || message;
var index = message ? stack.indexOf(message) : -1;
var escape = true;

if (index === -1) {
msg = message;
Expand All @@ -212,15 +211,14 @@ exports.list = function (failures) {
// explicitly show diff
if (showDiff(err)) {
stringifyDiffObjs(err);
escape = false;
fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
var match = message.match(/^([^:]+): expected/);
msg = '\n ' + color('error message', match ? match[1] : msg);

if (exports.inlineDiffs) {
msg += inlineDiff(err, escape);
msg += inlineDiff(err);
} else {
msg += unifiedDiff(err, escape);
msg += unifiedDiff(err);
}
}

Expand Down Expand Up @@ -374,11 +372,10 @@ function pad (str, len) {
*
* @api private
* @param {Error} err with actual/expected
* @param {boolean} escape
* @return {string} Diff
*/
function inlineDiff (err, escape) {
var msg = errorDiff(err, 'WordsWithSpace', escape);
function inlineDiff (err) {
var msg = errorDiff(err);

// linenos
var lines = msg.split('\n');
Expand Down Expand Up @@ -408,15 +405,11 @@ function inlineDiff (err, escape) {
*
* @api private
* @param {Error} err with actual/expected
* @param {boolean} escape
* @return {string} The diff.
*/
function unifiedDiff (err, escape) {
function unifiedDiff (err) {
var indent = ' ';
function cleanUp (line) {
if (escape) {
line = escapeInvisibles(line);
}
if (line[0] === '+') {
return indent + colorLines('diff added', line);
}
Expand Down Expand Up @@ -448,14 +441,10 @@ function unifiedDiff (err, escape) {
*
* @api private
* @param {Error} err
* @param {string} type
* @param {boolean} escape
* @return {string}
*/
function errorDiff (err, type, escape) {
var actual = escape ? escapeInvisibles(err.actual) : err.actual;
var expected = escape ? escapeInvisibles(err.expected) : err.expected;
return diff['diff' + type](actual, expected).map(function (str) {
function errorDiff (err) {
return diff.diffWordsWithSpace(err.actual, err.expected).map(function (str) {
if (str.added) {
return colorLines('diff added', str.value);
}
Expand All @@ -466,19 +455,6 @@ function errorDiff (err, type, escape) {
}).join('');
}

/**
* Returns a string with all invisible characters in plain text
*
* @api private
* @param {string} line
* @return {string}
*/
function escapeInvisibles (line) {
return line.replace(/\t/g, '<tab>')
.replace(/\r/g, '<CR>')
.replace(/\n/g, '<LF>\n');
}

/**
* Color lines for `str`, using the color `name`.
*
Expand Down
10 changes: 5 additions & 5 deletions lib/runnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ Runnable.prototype.timeout = function (ms) {
};

/**
* Set & get slow `ms`.
* Set or get slow `ms`.
*
* @api private
* @param {number|string} ms
* @return {Runnable|number} ms or Runnable instance.
*/
Runnable.prototype.slow = function (ms) {
if (typeof ms === 'undefined') {
if (!arguments.length || typeof ms === 'undefined') {
return this._slow;
}
if (typeof ms === 'string') {
Expand Down Expand Up @@ -144,7 +144,7 @@ Runnable.prototype.isPending = function () {
};

/**
* Set number of retries.
* Set or get number of retries.
*
* @api private
*/
Expand All @@ -156,7 +156,7 @@ Runnable.prototype.retries = function (n) {
};

/**
* Get current retry
* Set or get current retry
*
* @api private
*/
Expand Down Expand Up @@ -242,7 +242,7 @@ Runnable.prototype.resetTimeout = function () {
};

/**
* Whitelist a list of globals for this test run.
* Set or get a list of whitelisted globals for this test run.
*
* @api private
* @param {string[]} globals
Expand Down
10 changes: 5 additions & 5 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Suite.prototype.clone = function () {
};

/**
* Set timeout `ms` or short-hand such as "2s".
* Set or get timeout `ms` or short-hand such as "2s".
*
* @api private
* @param {number|string} ms
Expand All @@ -114,7 +114,7 @@ Suite.prototype.timeout = function (ms) {
};

/**
* Set number of times to retry a failed test.
* Set or get number of times to retry a failed test.
*
* @api private
* @param {number|string} n
Expand All @@ -130,7 +130,7 @@ Suite.prototype.retries = function (n) {
};

/**
* Set timeout to `enabled`.
* Set or get timeout to `enabled`.
*
* @api private
* @param {boolean} enabled
Expand All @@ -146,7 +146,7 @@ Suite.prototype.enableTimeouts = function (enabled) {
};

/**
* Set slow `ms` or short-hand such as "2s".
* Set or get slow `ms` or short-hand such as "2s".
*
* @api private
* @param {number|string} ms
Expand All @@ -165,7 +165,7 @@ Suite.prototype.slow = function (ms) {
};

/**
* Sets whether to bail after first error.
* Set or get whether to bail after first error.
*
* @api private
* @param {boolean} bail
Expand Down
2 changes: 1 addition & 1 deletion test/browser/array.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Array', function () {

describe('Array', function () {
describe('#pop()', function () {
it('should remove and return the last value', function () {
it('should remove and return the last value with expected error', function () {
var arr = [1, 2, 3];
assert(arr.pop() === 3);
assert(arr.pop() === 2);
Expand Down
4 changes: 2 additions & 2 deletions test/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
}
</script>
<script src="array.spec.js"></script>
<script src="../acceptance/duration.spec.js"></script>
<script src="../acceptance/timeout.spec.js"></script>
<script src="../unit/duration.spec.js"></script>
<script src="../unit/timeout.spec.js"></script>
<script src="multiple-done.spec.js"></script>
<script>
onload = function(){
Expand Down
2 changes: 1 addition & 1 deletion test/browser/large.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if (!expr) throw new Error(msg || 'failed');
}
</script>
<script src="large.js"></script>
<script src="large.spec.js"></script>
<script>
onload = function(){
mocha.run();
Expand Down
Loading

0 comments on commit 24b65e8

Please sign in to comment.