tapjs / tap-parser

parse the test anything protocol
121 stars 35 forks source link

TAP complete event (FinalResults object) yields data that is basically empty and I don't know why #48

Closed ORESoftware closed 7 years ago

ORESoftware commented 7 years ago

I get this console output from my program using tap-parser:


ok 1 a   
ok 2 b
ok 3 c
ok 4 d

TAP complete data: FinalResults {
  ok: true,
  count: 0,
  pass: 0,
  fail: 0,
  bailout: false,
  todo: 0,
  skip: 0,
  plan: 
   FinalPlan {
     start: 1,
     end: 0,
     skipAll: true,
     skipReason: 'no tests found',
     comment: 'no tests found' },
  failures: [] }

however, several 'assert ok' events went through this same parser...I assume that the parser itself is what keeps track of the number of pass/fails, otherwise I don't know why the parser complete event would report the accumulated data...here's my code:

//npm
const parser = require('tap-parser');
const events = require('suman-events');

//project
const resultBroadcaster = global.resultBroadcaster = (global.resultBroadcaster || new EE());

module.exports = function getParser () {

  const p = parser();

  p.on('complete', function(data){
    resultBroadcaster.emit(events.TAP_COMPLETE, data);
  });

  p.on('assert', function (testpoint) {

    resultBroadcaster.emit(events.TEST_CASE_END, testpoint);

    if (testpoint.skip) {
      resultBroadcaster.emit(events.TEST_CASE_SKIPPED, testpoint);
    }
    else if (testpoint.todo) {
      resultBroadcaster.emit(events.TEST_CASE_STUBBED, testpoint);
    }
    else if (testpoint.ok) {
      resultBroadcaster.emit(events.TEST_CASE_PASS, testpoint);
    }
    else {
      resultBroadcaster.emit(events.TEST_CASE_FAIL, testpoint);
    }
  });

  return p;

};

for this parser()instance, several testpoint.ok events have taken place. Any idea why the pass count would be 0?

if it's not clear, I can try to clarify, but not sure how to make it clearer ATM. I am probably misusing the lib, just not sure how.

ORESoftware commented 7 years ago

as an aside, sorry for the dumb TAP questions -

is the output from the 'complete' event (aka the FinalResults object) ever intended to be input for another process? Or is that just for human consumption?

isaacs commented 7 years ago

With that input, I get a complete results object with plenty of interesting data. It reports that there were 4 passes, and 1 fail for "missing plan".

$ cat <<END | tap-parser
ok 1 a
ok 2 b
ok 3 c
ok 4 d
END
[ [ 'assert', Result { ok: true, id: 1, name: 'a' } ],
  [ 'assert', Result { ok: true, id: 2, name: 'b' } ],
  [ 'assert', Result { ok: true, id: 3, name: 'c' } ],
  [ 'assert', Result { ok: true, id: 4, name: 'd' } ],
  [ 'comment', '# test count(4) != plan(null)\n' ],
  [ 'comment', '# failed 1 of 4 tests\n' ],
  [ 'complete',
    FinalResults {
      ok: false,
      count: 4,
      pass: 4,
      fail: 1,
      bailout: false,
      todo: 0,
      skip: 0,
      plan:
       FinalPlan {
         start: null,
         end: null,
         skipAll: false,
         skipReason: '',
         comment: '' },
      failures: [ { tapError: 'no plan' } ] } ] ]

(Same effect using the parser stream programmatically, just showing using the cli for clarity.)