From 2303c669ef1b47fef7cf86f5ef486d537033d443 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 9 Oct 2017 20:12:57 +0200 Subject: [PATCH 1/7] normalize getters and setters (fixes #3058) --- lib/context.js | 12 +++++++++--- lib/runnable.js | 10 +++++----- lib/suite.js | 10 +++++----- test/unit/context.spec.js | 12 ++++++++++++ 4 files changed, 31 insertions(+), 13 deletions(-) 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/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/unit/context.spec.js b/test/unit/context.spec.js index 75a85f6c19..6703324495 100644 --- a/test/unit/context.spec.js +++ b/test/unit/context.spec.js @@ -73,6 +73,18 @@ describe('methods', function () { }); }); + describe('slow()', function () { + it('should return the slow', function () { + expect(this.slow()).to.equal(75); + }); + }); + + describe('enableTimeouts()', function () { + it('should return the enableTimeouts', function () { + expect(this.enableTimeouts()).to.equal(true); + }); + }); + describe('retries', function () { it('should return the number of retries', function () { expect(this.retries()).to.equal(-1); From 1bb6b3977a482c144a61d68ea2e499b22a7db01b Mon Sep 17 00:00:00 2001 From: 38elements <38elements@users.noreply.github.com> Date: Fri, 27 Oct 2017 10:15:35 +0900 Subject: [PATCH 2/7] Remove unused variables (#3061) * Remove unused variables * Change errorDiff() * Remove escapeInvisibles() --- lib/reporters/base.js | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index 9243ec42e6..8b68a3d51d 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -185,7 +185,6 @@ exports.list = function (failures) { var index = message ? stack.indexOf(message) : -1; var actual = err.actual; var expected = err.expected; - var escape = true; if (index === -1) { msg = message; @@ -202,7 +201,6 @@ exports.list = function (failures) { } // explicitly show diff if (err.showDiff !== false && sameType(actual, expected) && expected !== undefined) { - escape = false; if (!(utils.isString(actual) && utils.isString(expected))) { err.actual = actual = utils.stringify(actual); err.expected = expected = utils.stringify(expected); @@ -213,9 +211,9 @@ exports.list = function (failures) { 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); } } @@ -366,11 +364,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'); @@ -400,15 +397,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); } @@ -440,14 +433,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); } @@ -458,19 +447,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`. * From 8a8331fd9a4db61994b76591a85bff706afd2f10 Mon Sep 17 00:00:00 2001 From: "David M. Lee" Date: Tue, 31 Oct 2017 22:02:34 -0500 Subject: [PATCH 3/7] Update README.md Fixed indentation of bullets with GFM. --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) 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/). From 526ffc165511853c0283859f60a7683793baddea Mon Sep 17 00:00:00 2001 From: Pat Finnigan Date: Thu, 23 Nov 2017 19:35:46 -0800 Subject: [PATCH 4/7] add cache comment add comment advising deletion from require cache if mocha is invoked programmatically multiple times --- lib/mocha.js | 8 ++++++++ 1 file changed, 8 insertions(+) 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} From f26643bb9d8596c4b1e8c125ff3a6ce59f92dbec Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Mon, 4 Dec 2017 22:15:34 -0800 Subject: [PATCH 5/7] add "good-first-issue" to stalebot exemption list [ci skip] Signed-off-by: Christopher Hiller --- .github/stale.yml | 1 + 1 file changed, 1 insertion(+) 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 From b954f69a5f541e688c393e2a3787617778d94a8d Mon Sep 17 00:00:00 2001 From: Eugene Tiutiunnyk Date: Wed, 5 Jul 2017 11:41:04 -0700 Subject: [PATCH 6/7] Fix spec paths in test HTML files * Finish the work started at 9bd9389c58e81b10bef9f4b2e5a54b77a026d2d0 * Add mention that error (introduced in e12ff8f7b634fc2ba4715fd0b68758030773e4dc) is expected. --- test/browser/array.spec.js | 2 +- test/browser/index.html | 4 ++-- test/browser/large.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) 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 @@ } - - + + - +