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

🚀 Feature: Expose public API for accessing diffs #3011

Closed
4 tasks done
segrey opened this issue Sep 25, 2017 · 6 comments · May be fixed by Deckhandfirststar01/mocha#13
Closed
4 tasks done

🚀 Feature: Expose public API for accessing diffs #3011

segrey opened this issue Sep 25, 2017 · 6 comments · May be fixed by Deckhandfirststar01/mocha#13
Labels
area: reporters involving a specific reporter type: feature enhancement proposal

Comments

@segrey
Copy link
Contributor

segrey commented Sep 25, 2017

Prerequisites

  • Checked that your issue isn't already filed by cross referencing issues with the common mistake label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
    node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend avoiding the use of globally installed Mocha.

Description

Mocha prints nice diffs for failed assertions. It'd be great to show these diffs when running mocha tests in IDE.
Currently, IDE accesses err object directly to format error info: https://github.com/JetBrains/mocha-intellij/blob/3c40655fcb8e4b216586d19ab83cac8c3f98e4a9/lib/mochaIntellijReporter.js#L157-L176 and doesn't print diffs in console (only clicking "Click to see difference" opens a separate diff dialog).

What do you think about allowing IDE to show unified diffs for failed assertions? // cc @boneskull

A possible API might look this:

// lib/utils.js

exports.prettifyError = function (err) {
  return {
    msg: '<colored text with unified diff>',
    stack: '<colored tail of stack>'
  };
};

In this case, both list function from lib/reporters/base.js and IDE may use prettifyError.

Original issue in WebStorm's tracker: https://youtrack.jetbrains.com/issue/WEB-28905

@ScottFreeCode ScottFreeCode added type: feature enhancement proposal status: accepting prs Mocha can use your help with this one! area: reporters involving a specific reporter semver-minor implementation requires increase of "minor" version number; "features" labels Sep 26, 2017
@boneskull
Copy link
Member

@segrey sure, feel free to send a PR.

BTW, if you have any other suggestions for ways in which Mocha can better communicate with IDEs, I'm interested!

@AndrewSouthpaw
Copy link

AndrewSouthpaw commented Jan 13, 2018

So, I'd love to get this in place, and also I have no familiarity with contributing to mocha or the reporter. Anyone interested in pairing for a bit to provide context (@boneskull, @segrey) so I can get the ball rolling?

@boneskull boneskull removed the semver-minor implementation requires increase of "minor" version number; "features" label Jan 17, 2018
@boneskull
Copy link
Member

@segrey Can this be closed, or is it incomplete?

@outsideris
Copy link
Member

Can we close this?

@rugk
Copy link

rugk commented Aug 10, 2018

Maybe this can be closed when you implement #1348, which could make use of this API.

It's the same, not in an IDE, but in the HTML reporter of Mocha, which still misses diffs/such a major feature.

@JoshuaKGoldberg JoshuaKGoldberg removed the status: accepting prs Mocha can use your help with this one! label Dec 27, 2023
@JoshuaKGoldberg JoshuaKGoldberg changed the title Expose public API for accessing diffs 🚀 Feature: Expose public API for accessing diffs Dec 27, 2023
@JoshuaKGoldberg
Copy link
Member

Maybe this can be closed when you implement #1348, which could make use of this API.

Cool, that was merged! Also, IDEs should be able to use a reporter for this. Either JSON or their own custom one if they need.

Failing that, #1457 is an umbrella issue around adding in plugins that could enhance stuff like this. Linking to that issue to make sure this use case is accounted for.

Cheers all!

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 type: feature enhancement proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants