tapjs/tap-parser

Feature: add 'extra' attribute to parsed output, for tests that have extra lines below them

af opened this issue · 6 comments

af commented

Currently if there are extra lines after an assertion, they are not present in the parsed output at all. For some applications this info (like the detailed error info that tape provides after a "not ok" line) is really useful, so it would be great if tap-parser included it in the parsed output by default (in addition to the 'extra' events).

The basic idea is that this TAP input:

TAP version 13
# beep
ok 1 should be equal
ok 2 should be equivalent
# boop
not ok 3 should be equal
     ---
    $extra_test_context
    ...
ok 4 (unnamed assert)

Would give this output:

{ ok: true,
  asserts: 
   [ { ok: true, number: 1, name: 'should be equal', extra: ''},
     { ok: true, number: 2, name: 'should be equivalent' , extra: ''},
     { ok: false, number: 3, name: 'should be equal' , extra: '   ---\n    $extra_test_context\n   ...'},
     { ok: true, number: 4, name: '(unnamed assert)', extra: ''} ],
  pass: 
   [ { ok: true, number: 1, name: 'should be equal', extra: '' },
     { ok: true, number: 2, name: 'should be equivalent', extra: '' },
     { ok: true, number: 4, name: '(unnamed assert)', extra: '' } ],
  fail: [
     { ok: false, number: 3, name: 'should be equal' , extra: '   ---\n    $extra_test_context\n   ...'},
  ],
  todo: [],
  errors: [],
  plan: { start: 1, end: 4 } }

Note the 'extra' attr in each parsed assertion object.

I've done some preliminary work on a patch for this, just want to verify that it would be accepted before completing it and updating the tests. Thanks!

What about the #beep and #boop lines?

af commented

@substack good point, I forgot that the comment events don't add anything
to the parsed output. They could be included in the 'extra' string if you
think that's the best approach.
On 2014-01-11 12:22 AM, "James Halliday" notifications@github.com wrote:

What about the #beep and #boop lines?


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-32090638
.

Comments aren't special in tap but many tap modules use them for test sections. I think it would be most consistent to include the comment lines into the extra sections. I'm kind of wavering on the need to do this however. Can you describe more about your use-case where the extra events are insufficient?

af commented

@substack Sorry for the radio silence, I didn't see the last part of your comment before working on the PR!

My use case is a basic test runner, where the output for errors (tracebacks etc) are very important for developer feedback. For this scenario it would be nice to have all of the output info available in the parser callback, rather than having to handle every assert/comment/extra event and reconstruct the parser output in app code.

My thinking was that lots of uses would benefit from not having to re-implement this code, but if you don't think it fits in tap-parser I can try wrapping it with another module instead.

af commented

@substack any further comment on this? If you don't want to merge it, no problem, just let me know so I can create a wrapper module with this functionality instead.

af commented

Doesn't seem like this patch is being considered, so I created a wrapper module that does the same thing instead.