Skip to content

Configurable max diff size - #4799

Merged
juergba merged 2 commits into
mochajs:masterfrom
norla:configurable-max-diff-size
Feb 15, 2022
Merged

juergba merged 2 commits into
mochajs:masterfrom
norla:configurable-max-diff-size

Conversation

@norla

@norla norla commented Dec 15, 2021 •

Copy link
Copy Markdown
Contributor

Description of the Change

Fixes #4767

Mocha truncates large diffs before displaying a readable unified/inline comparison.
This means that they are not displayed at all for larger strings in many cases, which causes confusion.
This PR makes the limit for when diffs should be truncated configurable (via "--reporter-option maxDiffSize=number"), so that projects that have large diffs can still get the outout they expect.

The default limit for generating diffs is also increased from 2048 to 8192 character, so that fewer people will run into this situation to begin with.

Also fixes bug causing the message about text being truncated to disappear.

Alternate Designs

Why should this be in core?

Fix for things already in core :)

Benefits

Configurable limit ensures that each project can configure the cropping of strings before shoving diff according to their own needs.

Possible Drawbacks

One more config flag to consider/document etc.

Applicable issues

#4767

@nopeless

Copy link
Copy Markdown

Personally never ran into this issue, but I can see myself running into this in the future 👍

@sz-piotr

Copy link
Copy Markdown

I have run into this multiple times, would really appreciate this getting more attention.

@juergba

juergba commented Feb 5, 2022

Copy link
Copy Markdown
Contributor

@norla thank you for this PR.

I'm not convinced of appending an additional option for this parameter.
Nevertheless we already have a reporter specific option reporter-option which could be enhanced for this case. We already use it for writing test results to a file.

Usage:

  • CLI: --reporter-option diffSize=4048
  • config files: 'reporter-option': ['diffSize=4048']

@norla

norla commented Feb 8, 2022

Copy link
Copy Markdown
Contributor Author

@juergba makes sense, didn't know about reporter options until now :)
The PR is updated accordingly, I named the option "maxDiffSize".

Another thing I just thought of:
The default value 2048 seems very conservative, maybe it can be increased to something like 8192 or 16384 instead?
I think that would prevent a lot of people from having to fiddle with "maxDiffSize" in the first place.

@norla
norla force-pushed the configurable-max-diff-size branch from 1a88373 to 7704e22 Compare February 8, 2022 07:48
@juergba

juergba commented Feb 8, 2022

Copy link
Copy Markdown
Contributor

@norla thank you, I will have a look this week.

@coveralls

coveralls commented Feb 8, 2022 •

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.01%) to 94.444% when pulling 40bac95 on norla:configurable-max-diff-size into 509938d on mochajs:master.

Comment thread docs/index.md Resolved
Comment thread lib/mocha.js Resolved
Comment thread lib/reporters/base.js Resolved
Comment thread lib/reporters/base.js Resolved
@juergba juergba added area: reporters involving a specific reporter semver-patch implementation requires increase of "patch" version number; "bug fixes" labels Feb 11, 2022
@juergba juergba added this to the next milestone Feb 11, 2022

@drGeoBN drGeoBN left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@juergba

juergba commented Feb 11, 2022

Copy link
Copy Markdown
Contributor

@norla please don't push commit by commit, our resources on the CI servers e.g. netlify are limited.
Test locally, then push occasionally.

@juergba

juergba commented Feb 11, 2022 •

Copy link
Copy Markdown
Contributor

@norla thank you so far. I will do some testing tomorrow.
Evtl. I can find a way to simplify this Number.isNaN check a little bit.

You could update this issue description (reporter-option / maxDiffSize, 2048=> 8192, fix message) and squash your commits.
Then lets see what the test coverage is telling.

Edit: ... and rebase to master.

Comment thread lib/reporters/base.js Resolved
Comment thread lib/reporters/base.js Resolved
Comment thread lib/reporters/base.js Resolved
Comment thread test/reporters/base.spec.js Resolved
@norla

norla commented Feb 12, 2022 via email •

Copy link
Copy Markdown
Contributor Author

@norla

norla commented Feb 13, 2022

Copy link
Copy Markdown
Contributor Author

I've fixed your comments. A bit unsure about the extra test but hopefully it should be enough. Let me know otherwise.
Still need to rebase and squash, though. Tomorrow :)

@juergba

juergba commented Feb 14, 2022

Copy link
Copy Markdown
Contributor

@norla thank you very much! Please rebase/squash and mention the --reporter-option maxDiffsize=number information in your issue description. I'm planning to release this fix next weekend.

@norla
norla force-pushed the configurable-max-diff-size branch from a1b68cd to e7b6b86 Compare February 15, 2022 07:34
@juergba
juergba merged commit 11c4560 into mochajs:master Feb 15, 2022
KuznetsovRoman pushed a commit to gemini-testing/mocha that referenced this pull request Sep 6, 2022
lennonnikolas pushed a commit to lennonnikolas/mocha that referenced this pull request Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: reporters involving a specific reporter semver-patch implementation requires increase of "patch" version number; "bug fixes"

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Diffs over 2048 characters are truncated even when there is no performance problem

6 participants