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

Better Formatting of Large JSON Objects in expected/actual Reports #419

Closed
inadarei opened this issue Jan 2, 2018 · 3 comments
Closed

Comments

@inadarei
Copy link
Contributor

inadarei commented Jan 2, 2018

Couple Issues with the current formatting:

  1. The threshold set implicitly or explicitly may be insufficient, in which case the mis-matched value could be swallowed by an un-expanded portion of {object} literal.
  2. Even when the threshold is set high-enough, the output is a single-line string that is quite messy and unreadable

Case in point:

---
    operator: deepEqual
    expected: |-
      { 'h:link': [ { template: { contentType: 'application/x-www-form-urlencoded', fields: { orderNumber: [Object], productCode: [Object], quantity: [Object] } }, uri: 'http://api.x.io/orders/42/items', label: 'Add Item', action: 'append' } ] }
    actual: |-
      { 'h:link': [ { template: { contentType: 'application/x-www-form-urlencoded', fields: { orderNumber: [Object], productCode: [Object], quantity: [Object] } }, uri: 'http://api.x.io/orders/42/items', label: 'Add Item', action: 'append' } ] }
    at: Test.test (/Users/irakli/Dropbox/Projects/node/kokua/test/unit/siren-reverse.js:77:5)
    stack: |-
      Error: Converted properly

can be auto-formatted more legibly as:

operator: deepEqual
    expected: |-
      {
  "h:link": [
    {
      "template": {
        "contentType": "application/x-www-form-urlencoded",
        "fields": {
          "orderNumber": {"type": "hidden", "default": "42"},
          "productCode": {"type": "text"},
          "quantity": {"type": "number", "label": "quantity"}
        }
      },
      "uri": "http://api.x.io/orders/42/items",
      "label": "Add Item",
      "action": "append"
    }
  ]
}
    actual: |-
      {
  "h:link": [
    {
      "template": {
        "contentType": "application/x-www-form-urlencoded",
        "fields": {
          "orderNumber": {"type": "hidden", "default": "42"},
          "productCode": {"type": "text"},
          "quantity": {"type": "number", "label": "Quantity"}
        }
      },
      "uri": "http://api.x.io/orders/42/items",
      "label": "Add Item",
      "action": "append"
    }
  ]
}
@ljharb
Copy link
Collaborator

ljharb commented Jan 15, 2018

This is partially addressed with #420.

@inadarei
Copy link
Contributor Author

inadarei commented Jan 21, 2018

I agree. Now that #420 has been merged, I was able to implement the rest with https://github.com/inadarei/tap-better-diff (tap-nirvana on NPM).

I believe implementing the formatting in a separate reporter is a better approach since everybody has their own preferences for how object should or should not be formatted and taking all of that into account in Tape itself will probably unreasonably increase the size of Tape.

I will submit a PR to add Tap Nirvana to the list of the known reporters, on the README, if that is OK?

@ljharb
Copy link
Collaborator

ljharb commented Jan 21, 2018

Sounds good.

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

No branches or pull requests

2 participants