Skip to content

Commit

Permalink
Merge branch 'master' into issue/4054
Browse files Browse the repository at this point in the history
  • Loading branch information
khg0712 committed Dec 29, 2019
2 parents c67cd37 + 1412dc8 commit 015e4df
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 19 deletions.
4 changes: 3 additions & 1 deletion bin/mocha
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Expand Up @@ -1911,7 +1911,7 @@ 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
Expand Down
20 changes: 15 additions & 5 deletions lib/reporters/base.js
Expand Up @@ -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)) {
Expand All @@ -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;
}
});

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/reporters/xunit.js
Expand Up @@ -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',
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fixtures/options/slow-test.fixture.js
Expand Up @@ -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);
});
});
15 changes: 15 additions & 0 deletions test/integration/options/timeout.spec.js
Expand Up @@ -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();
});
});
});
36 changes: 36 additions & 0 deletions test/reporters/xunit.spec.js
Expand Up @@ -350,6 +350,42 @@ describe('XUnit reporter', function() {
'</failure></testcase>';
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() {
Expand Down

0 comments on commit 015e4df

Please sign in to comment.