diff --git a/.github/stale.yml b/.github/stale.yml index a42cbd8f1a..3229c8966b 100644 --- a/.github/stale.yml +++ b/.github/stale.yml @@ -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 diff --git a/README.md b/README.md index 58897e3a44..4f83b2a320 100644 --- a/README.md +++ b/README.md @@ -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/). diff --git a/lib/context.js b/lib/context.js index 073643b8b6..f5a80118c0 100644 --- a/lib/context.js +++ b/lib/context.js @@ -29,7 +29,7 @@ Context.prototype.runnable = function (runnable) { }; /** - * Set test timeout `ms`. + * Set or get test timeout `ms`. * * @api private * @param {number} ms @@ -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; }; @@ -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 diff --git a/lib/mocha.js b/lib/mocha.js index d2261c4d26..5d2ab9ac89 100644 --- a/lib/mocha.js +++ b/lib/mocha.js @@ -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} diff --git a/lib/ms.js b/lib/ms.js index 9590856052..2fdcaf3242 100644 --- a/lib/ms.js +++ b/lib/ms.js @@ -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); }; /** @@ -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'; } @@ -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'; -} diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 4ca5bdce5b..0ebc5e7db3 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -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; @@ -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); } } @@ -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'); @@ -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); } @@ -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); } @@ -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, '') - .replace(/\r/g, '') - .replace(/\n/g, '\n'); -} - /** * Color lines for `str`, using the color `name`. * diff --git a/lib/runnable.js b/lib/runnable.js index 946f278341..694d4f59c2 100644 --- a/lib/runnable.js +++ b/lib/runnable.js @@ -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') { @@ -144,7 +144,7 @@ Runnable.prototype.isPending = function () { }; /** - * Set number of retries. + * Set or get number of retries. * * @api private */ @@ -156,7 +156,7 @@ Runnable.prototype.retries = function (n) { }; /** - * Get current retry + * Set or get current retry * * @api private */ @@ -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 diff --git a/lib/suite.js b/lib/suite.js index f5dca4cfa5..bb103dbaec 100644 --- a/lib/suite.js +++ b/lib/suite.js @@ -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 @@ -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 @@ -130,7 +130,7 @@ Suite.prototype.retries = function (n) { }; /** - * Set timeout to `enabled`. + * Set or get timeout to `enabled`. * * @api private * @param {boolean} enabled @@ -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 @@ -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 diff --git a/test/browser/array.spec.js b/test/browser/array.spec.js index edf66ac458..b831f61717 100644 --- a/test/browser/array.spec.js +++ b/test/browser/array.spec.js @@ -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); diff --git a/test/browser/index.html b/test/browser/index.html index d8b7cc9f72..26dc8722a2 100644 --- a/test/browser/index.html +++ b/test/browser/index.html @@ -12,8 +12,8 @@ } - - + + - +