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

No diff in html report #1348

Closed
just-boris opened this issue Sep 8, 2014 · 33 comments
Closed

No diff in html report #1348

just-boris opened this issue Sep 8, 2014 · 33 comments
Labels
area: browser browser-specific area: reporters involving a specific reporter status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal

Comments

@just-boris
Copy link

I've created a simple test example using latest [email protected] and [email protected]

describe("a suite", function() {
    it("a spec", function() {
        expect(['a', 'b', 'c']).to.deep.equal(['a', 'x', 'c']);
    });
});

When I am running the test in console, it works good and I see a diff in output
But in browser I can't see a diff.
If need, there is a code of runner.html

<html>
<head>
  <meta charset="utf-8">
  <title>Mocha Tests</title>
  <link rel="stylesheet" href="node_modules/mocha/mocha.css" />
</head>
<body>
  <div id="mocha"></div>
  <script src="node_modules/chai/chai.js"></script>
  <script src="node_modules/mocha/mocha.js"></script>
  <script>mocha.setup('bdd')</script>
  <script>
    var expect = chai.expect;
    describe("a suite", function() {
      it("a spec", function() {
        expect(['a', 'b', 'c']).to.deep.equal(['a', 'x', 'c']);
      });
    });
    mocha.run();
  </script>
</body>
</html>
@boneskull boneskull added area: reporters involving a specific reporter Unconfirmed labels Sep 8, 2014
@NiGhTTraX
Copy link

I can confirm this.

image

@callmevlad
Copy link
Contributor

Try changing your chai truncation threshold to disable truncation, like so:

chai.config.truncateThreshold = 0;

@just-boris
Copy link
Author

@callmevlad It helped me, but not solves issue at all.
In console report I see a nice difference between expected and actual result
image
But in html version I see just two values without any hints

@geowarin
Copy link

I have the same problem with the tdd ui.
It seems that Assertions are uncaught errors and therefore do not generate the diff...

@dasilvacontin
Copy link
Contributor

Wait. Uncaught errors? That's not the same problem as the one mentioned above, right?

@CRogers
Copy link

CRogers commented Mar 13, 2015

I too have this issue. It'd be great to get the diffs in the browser version.

@keithamus
Copy link
Contributor

chai.config.truncateThreshold = 0; simply tells chai to render more of the inspected values - it is not a diff, however. Diffing output is handled through the test runner (mocha) not the assertion lib.

The actual problem here is that the HTML reporter literally doesn't show diffs.

The code of how the HTML reporter constructs the failure HTML is between L158-188. It does not check if the error has a diff, and so does not render one. It needs something along the lines of the Base Reporters diff logic (which it does upon summary); around L193-215.

Has the HTML reporter ever shown diffs for anyone?

@lydell
Copy link

lydell commented Aug 15, 2015

No, the HTML reporter has never shown diffs. I requested this in #1071, which was recently closed in favour of letting the assertion library do it. So this is actually a duplicate.

@keithamus
Copy link
Contributor

@lydell I'm not sure it'd make much sense for an assertion library to do diffs, because of the variety of output formats that'd be needed. Mocha's reporters can send coloured escape codes for terminal, and HTML tags for HTML reporting - because a mocha reporter is context aware, assertion libraries are not.

@oveddan
Copy link
Contributor

oveddan commented Oct 8, 2015

+1

I reported this issue in karma-mocha

In this bit of code:
https://github.com/mochajs/mocha/blob/58e94445beb722372589cbd2a0372bf741e7f0b7/lib/reporters/html.js#L168

The error object can have an expected actual properties with this data. The html runner right now is not leveraging that in its report.

The base runner currently is leveraging it

I can work on adding this to the html reporter.

@vvo
Copy link

vvo commented Oct 14, 2015

I can work on adding this to the html reporter.

Yes do!

@oveddan
Copy link
Contributor

oveddan commented Oct 20, 2015

Ok, I'll work on it!

@ponelat
Copy link

ponelat commented Oct 20, 2015

+1

@tnrich
Copy link

tnrich commented Oct 26, 2015

+1 Any workaround for this currently?

@ponelat
Copy link

ponelat commented Oct 26, 2015

I'm using modern-diff to generate little diffs that look like...

dif({a: 1, b: 2, c: 3}, {b: 22, c: 3, d: 4})
/*
[
  ['-', ['a'], 1],
  ['r', ['b'], 2, 22],
  ['+', ['d'], 4]
]
*/

and my own little chai.expect helper for the error message.
Perhaps it'll help you in the mean-time 😄

@keithamus
Copy link
Contributor

In the meantime - if you're using chai - you can set chai.config.truncateThreshold = 0 which disables chai's inspector truncating objects for the error messages. Be warned: this is not a diff, it just shows you every property on an object and so can be pretty messy.

@dead-claudia
Copy link

I'm running into the same problem.

@boneskull
Copy link
Contributor

Diffing has been an issue for a long time. I would like to leverage a third-party lib (or libs) for this.

Requirements:

  1. colors; console and CSS (could necessitate some ansi-to-css converter)
  2. human-readable output
  3. type-based: intuitive diffs for numbers, strings, objects, functions, Dates, Buffers.
  4. proper handling of strict equality comparisons (though that may be something we would still need to implement); if two objects are otherwise equivalent but are different objects, this should be apparent.

nice to have:

  1. option for machine-readable output (which it looks like modern-diff is doing)
  2. option for GNU diff-style output.

I'm welcome to suggestions for modules that would fulfill the requirements. If nothing exists, maybe we should write one with Mocha in mind?

@dead-claudia
Copy link

@boneskull Multiple things on npm that might catch your eye. They simply create a machine-readable diff, which walking the two objects to format it wouldn't be that hard to do (although not quite trivial).

@lydell
Copy link

lydell commented Nov 1, 2015

unexpected. js has really nice string and object diffs. Don't know how that's implemented, though. Hopefully in a modular way :)

@oveddan
Copy link
Contributor

oveddan commented Nov 14, 2015

@boneskull there are currently no tests on the html reporter. I'm thinking of adding some. Would you be ok with jsdom being added to the dev dependencies for use in testing the generated html?

@amir-arad
Copy link

👍

@HamsterCoder
Copy link

I came from this issue and it's title describes precisely my problem. Using karma/mocha/chai with deepEqual I get the following output in console:

✖ supports predefined proxy PhantomJS 2.1.1 (Linux 0.0.0) expected { Object (url, headers, ...) } to deeply equal { Object (url, headers, ...) }

@valentin-radulescu-hs
Copy link

👍

@ScottFreeCode ScottFreeCode added area: browser browser-specific type: feature enhancement proposal labels Sep 22, 2017
@boneskull boneskull added the status: accepting prs Mocha can use your help with this one! label Oct 18, 2017
@boneskull
Copy link
Contributor

actually I'm going to kill this because it's not really actionable aside from the continuing lack of tests of the html reporter. if we want better / different diffs, someone should propose something concrete.

@rugk
Copy link

rugk commented Aug 10, 2018

Here is "something concrete":

Do make this:

looks this:

In the browser too. Not only in the console.

How can one be more concrete? It's a missing feature, it's very obvious what "concrete thing" is requested here.


Also I'd say this is the biggest feature Mocha is missing. Not being able to render diffs is a major drawback!

And don't know what you mean by "continuing lack of tests of the html reporter". All reports of this issue likely will test the HTML reporter. And if you don't want to maintain it, remove it, but do not pretend to support it.

@boneskull
Copy link
Contributor

This is what I mean:

  1. The HTML reporter has no code coverage
  2. There have been a couple abortive attempts to do it with our existing testing environment, but we really need functional, Selenium-style tests
  3. Functional tests will require a new toolchain to script a browser
  4. We won't change the HTML reporter until we have coverage
  5. We won't be removing the HTML reporter 😄

"Concrete" refers to the diff implementation itself, which likely won't transfer cleanly from the console to the browser. I was hoping for "let's use module X, because it fulfills all of the requirements," or a proposal to create a module which does.

@rugk It's clear you're frustrated by this missing feature. But please take care not to make condescending comments or place demands on volunteer contributors to this project.

@rugk
Copy link

rugk commented Aug 11, 2018

We won't be removing the HTML reporter smile

Great to hear, but then you may need to add these stuff still missing in that reporter.

I was hoping for "let's use module X, because it fulfills all of the requirements," or a proposal to create a module which does.

We don't even have a list of requirements, but aside from this lib, which already has been mentioned, but does not provide HTML support as it seems, there are a lot libraries:

I'd say diff2html looks promising and up-to-date (it's also easily to embed in a browser), but generally one may also have a look at what GitLab/GitHub/etc. use. They all have this implemented.


@boneskull It's clear you see some missing other stuff about the reporter and more important6 things to do. However, please acknowledge this issue here is valid and unsolved, and as such re-open it. I see no reason why it should be closed. You may mark it as "blocked" indicating no one should/can work on this, but acknowledge the general idea that this is missing.
Then, #3071 is the issue this is blocking, is it?
But actually a PR is already open in #3102.

@brian-lagerman
Copy link
Contributor

I'd say diff2html looks promising

A little bit of a sidebar as it's not the default html reporter, but we just pushed out a beta of our new mocha reporter and we integrated diff2html into it. We tore diff2html apart a bit, so that area still needs some clean up, but I'd be interested in what people think. The 'Diff comparison' suite has a couple samples in it.

@brucou
Copy link

brucou commented Jun 13, 2021

Any news on this? This is closed, but it is still a very valuable feature.

@nicbou
Copy link

nicbou commented Jan 21, 2022

@boneskull, why close this issue? The requirements are fairly clear, fairly popular (see multiple related tickets linked here), and certainly not met. 7 years later people are still coming here to request it.

For those who find this in the distant future, chai.config.truncateThreshold = 0 will fix the issue for chai users.

@brucou
Copy link

brucou commented Jan 21, 2022

true story

@cesarvarela
Copy link

image

(If someone comes here from Cypress, try using nested.include instead. It tells you the property that's different, and after that you can change it back to deep.equal)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: browser browser-specific area: reporters involving a specific reporter status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Projects
None yet
Development

No branches or pull requests