twada / power-assert-renderers

[DEPRECATED] this module is reorganized into https://github.com/twada/power-assert-runtime
MIT License
2 stars 1 forks source link

Objects are difficult to differentiate. #1

Open dylang opened 8 years ago

dylang commented 8 years ago

I'm trying power-assert thanks to the recent addition to AVA in https://github.com/sindresorhus/ava/pull/46.

The examples show some simple values like true, foo, and look really nice, but I'm finding in reality my asserts are on much more complex objects and the output format is making it more difficult to visually parse the difference.

Example, deeply nested

This is not helpful.

screen shot 2015-10-24 at 5 18 35 pm

Example, large object

Helpful, but not usable.

screen shot 2015-10-24 at 5 18 50 pm

Example, JSON.stringify

Not usable, and I wasn't expecting all of the quotes to be \"-escaped because they aren't escaped in the original string.

screen shot 2015-10-24 at 5 34 13 pm

Suggestion

Highlight the differences in objects with a package like difflet.

difflet_colors

Or like this difflet_object_comments

twada commented 8 years ago

@dylang Thank you for your suggestion. And sorry for my late response.

I once designed power-assert to be testing framework agnostic (Mocha, QUnit, testem, Karma, ...) and runtime agnostic (node, browser), so I couldn't select nice object-diff libraries that depend on ANSI term colors (Browsers! especially IE8...).

However with AVA, which is much more opinionated, power-assert reporting could be more focused and informative. Your suggestion makes me think about contextual and richer power-assert output. Thanks!

dylang commented 8 years ago

Thanks @twada, and don't worry, your response timing great. I understand we all have busy lifes and I really appreciate all of the time you have spent on your open source projects.

With regards to running in the browser, there are libraries like https://github.com/simov/ansi-webkit to help keep it consistent.

alubbe commented 8 years ago

hey @twada. I just wanted to add my 2 cents - this feature would really nice to have. I've just been bitten by 4 failing tests in AVA after some refactoring and the diff was one string somewhere 5 levels deep, so I had to resort to console.log(JSON.stringify()) and comparing the output in another tool :(

twada commented 8 years ago

@alubbe Thank you for your opinion.

Improvement in AVA's reporting architecture will be land when AVA gets ready for Babel6. When it lands, I'm going to improve power-assert output, since I can assume powerful ANSI terms and a lot of nice diff libraries.

So sorry for inconvenience for now. This issue will be fixed soon.

alubbe commented 8 years ago

No, thank you for working on this!

capaj commented 8 years ago

This issue will be fixed soon.

So this was a bold statement. So I would love to help fix this-it should not be so hard-

My assumptions: all we have to do is check whether one of the strings/objects is longer than let's say 50-80 chars. If it is, we make a diff and print it into the console instead of the current compare text. Right @twada ?

twada commented 8 years ago

@capaj Yes. You are right.

Would you give me the same comment here? Since this project is moved to power-assert-runtime project.