-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mocha failing when error message too big #3675
Comments
Please retry this but use the built in Sent with GitHawk |
With current master(6b5a785), $ time mocha rr.js
1) Test failing
0 passing (106ms)
1 failing
1) Test failing:
AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
+ expected - actual ... Lines skipped
real 1m58.016s
user 2m2.341s
sys 0m0.649s With const assert = require('assert');
const _ = require('lodash');
it('Test failing', function () {
const longArray = _.times(10000, function (i) {
return {a : i}
})
const shortArray = []
assert.deepStrictEqual(longArray, shortArray);
}); real 1m56.692s
user 2m1.052s
sys 0m0.571s |
If it just takes a long time, is that necessarily a "confirmed bug"? |
Because it doesn't take so long without mocha. |
This could very well be related to #3686 |
@furstenheim Try running mocha again with |
@cyjake Just tried mocha 5.2.0 (latest) with |
@boneskull I've reproduced this issue locally and done a superficial study of the reason. It is blocked at |
When run in Node without Mocha, the AssertionError output appears very fast and is even shortened, see "Lines skipped". When run in Mocha there is an additional part, which is not shortened and takes very long. The information content is the same in both parts. I will investigate, maybe we can just skip it. Or do Browsers need that second part?
|
The first part is read from The second part is made by Mocha and has to be shortened somehow. Running Mocha with |
Mocha is using jsdiff for creating a diff-patch out off For now I propose to just shorten the two strings to be compared before creating the diff-patch. var generateDiff = (exports.generateDiff = function(actual, expected) {
var diffSize = 4096;
if (actual.length > diffSize) {
actual = actual.substring(0, diffSize) + ' ... Lines skipped';
}
if (expected.length > diffSize) {
expected = expected.substring(0, diffSize) + ' ... Lines skipped';
}
return exports.inlineDiffs
? inlineDiff(actual, expected)
: unifiedDiff(actual, expected);
}); @furstenheim Do you have time to patch |
@juergba checked. That change does the trick |
Does upgrading our 'jsdiff' dependency make any difference (before making changes to Mocha)? |
No, doesn't make any difference. |
I think it is not JSdiff fault because.. lib/reporters/base.js var msg = diff.createPatch('string', actual, expected);
var lines = msg.split('\n').splice(5); this code spent a lot of time in test code and then result so I think it is relevant to diff.createPatch performance in first But..I think it is wrong. it is only late in mocha! not the jsdiff fault! I tested same code in only jsdiff const diff = require('diff')
const _ = require('lodash')
let actual = _.times(10000, function (i) {
return {a : i}
})
let expected = []
actual = JSON.stringify(actual)
expected = JSON.stringify(expected)
var msg = diff.createPatch('string', actual, expected)
console.log(msg)
var lines = msg.split('\n').splice(5);
console.log(lines) the result is.. so fast.. but mocha in diff is 3.5 version and my tested diff version is 4.0 version I will check 4.0 version in mocha Actually almost I found it!! lib > patch > create.js > structuredPatch
and then.. it said like this in mocha
but..!!!
very clear in mocha stringify logic is wrong! and now i will figure it out! |
@juergba 1. I logged to real err.actual and write file to message.txt//in reporters/base.js
fs.writeFileSync('./message.txt', err.actual);
msg += generateDiff(err.actual, err.expected);
// indent stack trace
stack = stack.replace(/^/gm, ' ');
// indented test title
var testTitle = '';
test.titlePath().forEach(function(str, index) {
if (index !== 0) {
... 2. and testing jsDiffconst diff = require('diff')
const _ = require('lodash')
const fs = require('fs')
const expected = '[]'
const actual = fs.readFileSync('./message.txt').toString();
console.log(actual)
var msg = diff.createPatch('string', actual, expected)
console.log(msg) but jsdiff can't handle like.. |
I just ran into this issue due to large and difficult to diff const assert = require('assert');
const zlib = require('zlib');
it('produces a large/slow diff', () => {
assert.deepStrictEqual(new zlib.Gzip(), new zlib.Inflate());
}); I killed mocha after 10 minutes. Inspector showed the following stack trace:
with
Apparently Google's You may also want to consider limiting the size of the input to diff. Finding a minimal diff of 2 highly-dissimilar multi-MB strings is probably not a good use of time/compute/output screen space, even with a fast algorithm. It could also be an easy interim fix until diff alternatives are evaluated. |
I would like to see this move forward, as we are still getting issues relating to it. |
it has issues from top to bottom -- from the stringification code to the diffing of those canonical results... yuk. |
Description
Mocha never ends with big error messages
Steps to Reproduce
Then execute
yarn mocha test --exit
, the test will execute it will be marked as failure, but the summary will never appear and the process will not exit.If on contrary one writes:
The test fails and it displays an error in the summary. Error is logged without any problem.
Expected behavior: [What you expect to happen]
Mocha should be able to exit the process even if the error is overly long. Maybe the message could be reduced?
Actual behavior: [What actually happens]
The process hangs forever
Reproduces how often: [What percentage of the time does it reproduce?]
Always
Versions
Mocha 5.1.1
mocha --version
andnode node_modules/.bin/mocha --version
:node --version
:v8.11.2
Ubuntu
bash
The text was updated successfully, but these errors were encountered: