testdouble / teenytest

A very simple, zero-config test runner for Node.js
MIT License
96 stars 14 forks source link

Large assertions are truncated #42

Closed garybernhardt closed 5 years ago

garybernhardt commented 5 years ago

If you assert very large objects against each other, the stringified versions shown at the terminal are truncated. So there's no way to actually see what was being asserted other than instrumenting the code with console.log etc.

Here's an example with all identifiers anonymized. Search it for "..." to see where the truncation is happening. The actual difference between these two values isn't visible in this error message; it's somewhere after the "...".

# Failures:
#
#   1 - "default integration testname" - test #1 in `build/myfile/myfile.test.js`
#
#     AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal:
#
#     {
#       cs: [
#         {
#           ls: [
#             {
#               as: [],
#               ds: [
#                 'd1',
#                 'd2'
#               ],
#               name: 'l1',
#               ss: [
#                 {
#                   as: [
#                     'r'
#                   ],
#                   i: '1 + 1',
#                   kind: 'c',
#                   o: [
#                     '2'
#                   ]
#                 },
#                 {
#                   as: [],
#                   i: '2',
#                   kind: 'r...
#
#     should equal
#
#     {
#       cs: [
#         {
#           ls: [
#             {
#               as: [],
#               ds: [
#                 'd1',
#                 'd2'
#               ],
#               name: 'l1',
#               ss: [
#                 {
#                   as: [
#                     'r'
#                   ],
#                   i: '1 + 1',
#                   kind: 'c',
#                   o: [
#                     '2'
#                   ]
#                 },
#                 {
#                   as: [],
#                   i: '2',
#                   kind: 'r...
#         at Object.testname (/Users/grb/proj/myproj/build/myfile/myfile.test.js:9:20)
#         at /Users/grb/proj/myproj/node_modules/teenytest/lib/plugins/callbackify.js:14:21
#         at runX (/Users/grb/proj/myproj/node_modules/teenytest/lib/plugins/wrap.js:22:7)
#         at Object.userFunction [as wrap] (/Users/grb/proj/myproj/node_modules/teenytest/plugins/uncaught-exception.js:16:9)
#         at callable (/Users/grb/proj/myproj/node_modules/teenytest/lib/plugins/wrap.js:29:24)
#         at runX (/Users/grb/proj/myproj/node_modules/teenytest/lib/plugins/wrap.js:22:7)
#         at Object.userFunction [as wrap] (/Users/grb/proj/myproj/node_modules/teenytest/plugins/results.js:10:9)
#         at callable (/Users/grb/proj/myproj/node_modules/teenytest/lib/plugins/wrap.js:29:24)
#         at runX (/Users/grb/proj/myproj/node_modules/teenytest/lib/plugins/wrap.js:22:7)
#         at Object.userFunction [as wrap] (/Users/grb/proj/myproj/node_modules/teenytest/plugins/tap13/index.js:16:9)
garybernhardt commented 5 years ago

I think that Node's assert module might be the one doing this? If so then this can be closed.

searls commented 5 years ago

Yes, I suspect that's the case. I'm pretty motivated to find a standalone assertion module that does deep equality checking in with a visually-appealing diffing format. I don't have one.

garybernhardt commented 5 years ago

I switched to power-assert half an hour ago and it's been nice so far. It's doing evil by looking at the AST, which I don't like. But the diffs are nice.

searls commented 5 years ago

Yes, good, power-assert is the only one I've had success with that's any good at all at this. How do you have it configured, if you don't mind sharing?

Also, does it add any slowness on passing tests? (My hope is that a great assertion library would only introduce slowness when producing good failure output)

garybernhardt commented 5 years ago

I didn't realize it was configurable; I just switched my import from assert to power-assert and it seemed fine. It adds 72 ms of startup latency. I don't know whether it slows the tests themselves down.

searls commented 5 years ago

I believe this was a Node assert thing. I'm not able to reproduce it when using other assertion errors.