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

Highlight complex object diff #32

Closed
hatched opened this issue Sep 8, 2015 · 11 comments
Closed

Highlight complex object diff #32

hatched opened this issue Sep 8, 2015 · 11 comments

Comments

@hatched
Copy link

hatched commented Sep 8, 2015

It would be great if the reporter would highlight the diff in a complex object instead of just dumping both the expected and actual to the console. I'm using karma-jasmine because karma-mocha doesn't show the stacktrace on error and using chai 'assert' assertions.

Using:

  • karma 0.13.9
  • karma-chai-sinon 0.1.5
  • karma-jasmine 0.3.6
  • karma-mocha-reporter 1.1.1
@4kochi
Copy link
Collaborator

4kochi commented Sep 8, 2015

I guess this is a duplicate of #26 ? I am short on time right now but i will try to have a look if this can be done with the reporter.

@hatched
Copy link
Author

hatched commented Sep 8, 2015

I spent a bit of time this morning tracing down where this information is coming from. It appears that the issue is in jasmine-core not emitting the proper information on an exception.

https://github.com/jasmine/jasmine/blob/master/lib/jasmine-core/jasmine.js#L1468

I'm not at all familiar with how jasmine-core operates but it appears that karma-jasmine may be able to supply configuration values to support adding the actual and expected. At that point the data should become available to the reporter to show a pretty diff.

@4kochi
Copy link
Collaborator

4kochi commented Sep 9, 2015

Thanks for looking into this. I will use this as starting point.

@rosston
Copy link

rosston commented Feb 18, 2016

I've looked a bit into getting nice diffs in Karma, and it seems like the reporter is really at the mercy of the test framework/assertion library to provide the necessary data to provide the diff.

That said, karma-mocha recently added support for passing assertion errors through to the reporter (karma-runner/karma-mocha#85). As far as I can tell, Chai is the only assertion library that would provide enough information on the errors to show a diff of expected/actual. Would it make sense to add support to this reporter for only one possible setup (i.e., karma-mocha + chai)?

@4kochi
Copy link
Collaborator

4kochi commented Feb 18, 2016

Hey @rosston ,

thanks for the informations. I will have a look. To get started quickly it would be nice if you could send be a spec file with mocha tests. Because i only use karma-jasmine. That would be really helpful.

@rosston
Copy link

rosston commented Feb 18, 2016

Certainly, I can put up an example spec. Would it be helpful to have a full example repo with mocha node tests too? Mocha on node seems to be the gold standard for expected/actual diffs.

@4kochi
Copy link
Collaborator

4kochi commented Feb 18, 2016

I guess an example spec is enough. Or is the logic the same in mocha for node.js and browser tests?

@rosston
Copy link

rosston commented Feb 18, 2016

Mocha only shows diffs when run in node. In the browser, it uses a different (HTML) reporter, which doesn't support diffs. See mochajs/mocha#1348 (comment)

@rosston
Copy link

rosston commented Feb 18, 2016

@4kochi Here's an example repo: https://github.com/rosston/mocha-diff-example. test/test.js contains the example spec. Let me know if there's anything else I can do to help.

@4kochi 4kochi closed this as completed in ee73dfa Feb 19, 2016
@4kochi
Copy link
Collaborator

4kochi commented Feb 19, 2016

Thanks for your help @ALL. Released as v1.2.0

@rosston
Copy link

rosston commented Feb 19, 2016

😂 Yes! This has made my week. Thank you, @4kochi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants