From d4adfa6364dff21c37e8632c3bfc9288c9938f42 Mon Sep 17 00:00:00 2001 From: Juerg B <44573692+juergba@users.noreply.github.com> Date: Sun, 15 Dec 2019 10:26:39 +0100 Subject: [PATCH 1/4] Fix timeout handling with `--inspect-brk`/`--inspect` --- bin/mocha | 4 +++- .../fixtures/options/slow-test.fixture.js | 4 ++-- test/integration/options/timeout.spec.js | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/bin/mocha b/bin/mocha index 4b0ab8ff86..9c63463790 100755 --- a/bin/mocha +++ b/bin/mocha @@ -54,12 +54,14 @@ const trimV8Option = value => Object.keys(opts).forEach(opt => { if (isNodeFlag(opt)) { nodeArgs[trimV8Option(opt)] = opts[opt]; - disableTimeouts(opt); } else { mochaArgs[opt] = opts[opt]; } }); +// disable 'timeout' for debugFlags +Object.keys(nodeArgs).forEach(opt => disableTimeouts(opt)); + // Native debugger handling // see https://nodejs.org/api/debugger.html#debugger_debugger // look for 'inspect' or 'debug' that would launch this debugger, diff --git a/test/integration/fixtures/options/slow-test.fixture.js b/test/integration/fixtures/options/slow-test.fixture.js index f15cb6d9dd..952e656743 100644 --- a/test/integration/fixtures/options/slow-test.fixture.js +++ b/test/integration/fixtures/options/slow-test.fixture.js @@ -5,7 +5,7 @@ describe('a suite', function() { setTimeout(done, 500); }); - it('should succeed in 1.5s', function(done) { - setTimeout(done, 1500); + it('should succeed in 1.1s', function(done) { + setTimeout(done, 1100); }); }); diff --git a/test/integration/options/timeout.spec.js b/test/integration/options/timeout.spec.js index ac786da54d..4470c8b310 100644 --- a/test/integration/options/timeout.spec.js +++ b/test/integration/options/timeout.spec.js @@ -49,4 +49,19 @@ describe('--timeout', function() { done(); }); }); + + it('should disable timeout with --inspect', function(done) { + var fixture = 'options/slow-test'; + runMochaJSON(fixture, ['--inspect', '--timeout', '200'], function( + err, + res + ) { + if (err) { + done(err); + return; + } + expect(res, 'to have passed').and('to have passed test count', 2); + done(); + }); + }); }); From 25363e628af793841e2911f61b64b95bf8c6ebaf Mon Sep 17 00:00:00 2001 From: Saerom Bang Date: Sun, 15 Dec 2019 19:03:51 +0900 Subject: [PATCH 2/4] Changed docs index.md on Typescript and Babel link (#4129) --- docs/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 788dbf1e52..1da20d7263 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1883,14 +1883,14 @@ or the [source](https://github.com/mochajs/mocha/blob/master/lib/mocha.js). [connect-test-output]: https://github.com/senchalabs/connect/blob/90a725343c2945aaee637e799b1cd11e065b2bff/tests.md [emacs]: https://www.gnu.org/software/emacs/ [emacs-mocha.el]: https://github.com/scottaj/mocha.el -[example-babel]: https://github.com/mochajs/mocha-examples/tree/master/babel +[example-babel]: https://github.com/mochajs/mocha-examples/tree/master/packages/babel [example-connect-test]: https://github.com/senchalabs/connect/tree/master/test [example-express-test]: https://github.com/visionmedia/express/tree/master/test [example-mocha-test]: https://github.com/mochajs/mocha/tree/master/test [example-mocha-config]: https://github.com/mochajs/mocha/tree/master/example/config [example-superagent-test]: https://github.com/visionmedia/superagent/tree/master/test/node [example-third-party-reporter]: https://github.com/mochajs/mocha-examples/tree/master/third-party-reporter -[example-typescript]: https://github.com/mochajs/mocha-examples/tree/master/typescript +[example-typescript]: https://github.com/mochajs/mocha-examples/tree/master/packages/typescript [example-websocket.io-test]: https://github.com/LearnBoost/websocket.io/tree/master/test [expect.js]: https://github.com/LearnBoost/expect.js [expresso]: https://github.com/tj/expresso From d9f5079b3b26c61fec3329a902dea00ccc961f70 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Mon, 16 Dec 2019 08:00:02 +0000 Subject: [PATCH 3/4] Update node-environment-flags to 1.0.6 (#4118) node-environment-flags 1.0.5 and lower do not contain a LICENSE file which can make compliance difficult. --- package-lock.json | 12 ++++++------ package.json | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1893272bf4..83e2141110 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11374,18 +11374,18 @@ } }, "node-environment-flags": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.5.tgz", - "integrity": "sha512-VNYPRfGfmZLx0Ye20jWzHUjyTW/c+6Wq+iLhDzUI4XmhrDd9l/FozXV3F2xOaXjvp0co0+v1YSR3CMP6g+VvLQ==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/node-environment-flags/-/node-environment-flags-1.0.6.tgz", + "integrity": "sha512-5Evy2epuL+6TM0lCQGpFIj6KwiEsGh1SrHUhTbNX+sLbBtjidPZFAnVK9y5yU1+h//RitLbRHTIMyxQPtxMdHw==", "requires": { "object.getownpropertydescriptors": "^2.0.3", "semver": "^5.7.0" }, "dependencies": { "semver": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==" + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==" } } }, diff --git a/package.json b/package.json index 3135e39f89..378a91a8ba 100644 --- a/package.json +++ b/package.json @@ -537,7 +537,7 @@ "minimatch": "3.0.4", "mkdirp": "0.5.1", "ms": "2.1.1", - "node-environment-flags": "1.0.5", + "node-environment-flags": "1.0.6", "object.assign": "4.1.0", "strip-json-comments": "2.0.1", "supports-color": "6.0.0", From 1412dc80d87d0479f7f1d60202da2b33c90eb939 Mon Sep 17 00:00:00 2001 From: Rens Groothuijsen Date: Sun, 22 Dec 2019 16:21:35 +0100 Subject: [PATCH 4/4] XUnit reporter should handle exceptions during diff generation (#4068) --- lib/reporters/base.js | 20 +++++++++++++++----- lib/reporters/xunit.js | 6 +++--- test/reporters/xunit.spec.js | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/lib/reporters/base.js b/lib/reporters/base.js index e5ed0d4c61..ea259445e3 100644 --- a/lib/reporters/base.js +++ b/lib/reporters/base.js @@ -154,14 +154,14 @@ exports.cursor = { } }; -function showDiff(err) { +var showDiff = (exports.showDiff = function(err) { return ( err && err.showDiff !== false && sameType(err.actual, err.expected) && err.expected !== undefined ); -} +}); function stringifyDiffObjs(err) { if (!utils.isString(err.actual) || !utils.isString(err.expected)) { @@ -182,9 +182,19 @@ function stringifyDiffObjs(err) { * @return {string} Diff */ var generateDiff = (exports.generateDiff = function(actual, expected) { - return exports.inlineDiffs - ? inlineDiff(actual, expected) - : unifiedDiff(actual, expected); + try { + return exports.inlineDiffs + ? inlineDiff(actual, expected) + : unifiedDiff(actual, expected); + } catch (err) { + var msg = + '\n ' + + color('diff added', '+ expected') + + ' ' + + color('diff removed', '- actual: failed to generate Mocha diff') + + '\n'; + return msg; + } }); /** diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js index 6c9c937be8..da366cdaa1 100644 --- a/lib/reporters/xunit.js +++ b/lib/reporters/xunit.js @@ -163,9 +163,9 @@ XUnit.prototype.test = function(test) { if (test.state === STATE_FAILED) { var err = test.err; var diff = - Base.hideDiff || !err.actual || !err.expected - ? '' - : '\n' + Base.generateDiff(err.actual, err.expected); + !Base.hideDiff && Base.showDiff(err) + ? '\n' + Base.generateDiff(err.actual, err.expected) + : ''; this.write( tag( 'testcase', diff --git a/test/reporters/xunit.spec.js b/test/reporters/xunit.spec.js index 2d05312fae..736f9d1112 100644 --- a/test/reporters/xunit.spec.js +++ b/test/reporters/xunit.spec.js @@ -350,6 +350,42 @@ describe('XUnit reporter', function() { ''; expect(expectedWrite, 'to be', expectedTag); }); + + it('should handle non-string diff values', function() { + var runner = new EventEmitter(); + createStatsCollector(runner); + var xunit = new XUnit(runner); + + var expectedTest = { + state: STATE_FAILED, + title: expectedTitle, + parent: { + fullTitle: function() { + return expectedClassName; + } + }, + duration: 1000, + err: { + actual: 1, + expected: 2, + message: expectedMessage, + stack: expectedStack + } + }; + + sandbox.stub(xunit, 'write').callsFake(function(str) { + expectedWrite += str; + }); + + runner.emit(EVENT_TEST_FAIL, expectedTest, expectedTest.err); + runner.emit(EVENT_RUN_END); + sandbox.restore(); + + var expectedDiff = + '\n + expected - actual\n\n -1\n +2\n '; + + expect(expectedWrite, 'to contain', expectedDiff); + }); }); describe('on test pending', function() {