Skip to content
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

Exposes generation of diffs from base reporter #3213

Merged
merged 3 commits into from Mar 6, 2018

Conversation

harrysarson
Copy link
Contributor

Second attempt at solution for #3011, improves on PR #3201.

PR based on suggestion by @segrey in #3201 (comment). Exposed function generateDiff(expected, actual) as a static member of Base.

The value of Base.inlineDiffs is used to determine the form of the diff.

Alternate Designs

#3201

Why should this be in core?

Allows IDE's to produce nice output when integrated with mocha.

Benefits

See #3011.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 90.027% when pulling d5e5328 on HarrySarson:seperate-diff2 into 2e7e4c0 on mochajs:master.

@segrey
Copy link
Contributor

segrey commented Jan 19, 2018

Looks good to me. @harrysarson thanks!

@coveralls
Copy link

coveralls commented Jan 19, 2018

Coverage Status

Coverage increased (+0.05%) to 90.032% when pulling f90a3ce on HarrySarson:seperate-diff2 into c4ef568 on mochajs:master.

@segrey
Copy link
Contributor

segrey commented Jan 22, 2018

I'll update IntelliJ reporter once the PR is merged.

Copy link
Member

@boneskull boneskull left a comment

Choose a reason for hiding this comment

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

This looks good, thanks @harrysarson. I just have a couple nitpicks.

@segrey To make sure I'm not missing something, can you clarify what you meant about err.details back in #3201?

var generateDiff = exports.generateDiff = function (actual, expected) {
if (exports.inlineDiffs) {
return inlineDiff(actual, expected);
} else {
Copy link
Member

Choose a reason for hiding this comment

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

this else is not necessary

* The diff will be either inline or unified dependant on the value
* of `Base.inlineDiff`.
*
* @api private
Copy link
Member

Choose a reason for hiding this comment

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

I think the intent is that this is a public function, so you can remove this, right?

* of `Base.inlineDiff`.
*
* @api private
* @param {String} actual
Copy link
Member

Choose a reason for hiding this comment

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

lowercase string

var oldInlineDiffs = Base.inlineDiffs;
Base.inlineDiffs = false;

var output = Base.generateDiff(actual, expected);
Copy link
Member

Choose a reason for hiding this comment

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

please do the patching in a beforeEach of the suite and restore in afterEach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When doing the patching, should I be setting the value of Base.inlineDiffs in the beforeEach?

@boneskull boneskull added semver-patch implementation requires increase of "patch" version number; "bug fixes" type: cleanup a refactor labels Feb 8, 2018
@boneskull
Copy link
Member

@harrysarson Thanks for this!! in the future, please just reuse your PRs and force-push changes--it's kind of difficult to track the conversation otherwise

@segrey
Copy link
Contributor

segrey commented Feb 8, 2018

@boneskull Regarding err.details, I meant to enhance standard err object that is passed to reporters in runner.on('fail', function (test, err) {}). The idea is to have some common properties that are calculated by mocha already and might be interested for reporters:

As a benefit, mocha will have a mechanism to easily change how these values are calculated, e.g. supply diffs provided by assertion libraries without changes in reporters.

@harrysarson
Copy link
Contributor Author

I have hopefully made all the requested changes :)

@harrysarson Thanks for this!! in the future, please just reuse your PRs and force-push changes--it's kind of difficult to track the conversation otherwise

Ah yeah, I will in future.

@harrysarson
Copy link
Contributor Author

harrysarson commented Feb 9, 2018

Test failure is due to linting of markdown. Would be resolved by #3236

Now fixed

@harrysarson
Copy link
Contributor Author

harrysarson commented Feb 24, 2018

@boneskull can this be merged or is more work needed, I think I have resolved all the required changes :)

@boneskull
Copy link
Member

@segrey Got it. So it looks like this PR is the first step to get there.

@boneskull boneskull merged commit 8df5727 into mochajs:master Mar 6, 2018
@boneskull
Copy link
Member

blah, meant to squash.

@boneskull boneskull added this to the v5.0.3 milestone Mar 6, 2018
@harrysarson harrysarson deleted the seperate-diff2 branch March 6, 2018 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes" type: cleanup a refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants