scottcorgan / tap-out

A different tap parser
MIT License
23 stars 28 forks source link

'assert' does not have error until next tick #8

Closed mattdesl closed 9 years ago

mattdesl commented 9 years ago

I've noticed the callback to assert is triggered too early. It has an error object, but the properties are all undefined until the next tick. Have you run into this before?

scottcorgan commented 9 years ago

Can you show me some code and maybe a screenshot?

mattdesl commented 9 years ago

here's a test:

test('handles error immediately', function (t) {

  t.plan(2);

  var mockTap = [
    "TAP version 13",
    "# is true",
    "ok 1 true value",
    "ok 2 true value",
    "not ok 3 strings match",
    "  ---",
    "    operator: equal",
    "    expected: 'you'",
    "    actual:   'me'",
    "    at: Test.<anonymous> (http://localhost:9966/index.js:8:5)",
    "  ...",
    "not ok 15 plan != count",
    "  ---",
    "    operator: fail",
    "    expected: 4",
    "    actual:   3",
    "  ...",
    "",
    "1..15",
  ];

  var p = parser();

  // works
  p.on('output', function (output) {
    t.deepEqual(output.fail[0].error.expected, 'you')
  })

  // does not work
  // p.on('assert', function (assert) {
  //   t.deepEqual(assert.error.expected, 'you')
  // });

  mockTap.forEach(function (line) {

    p.write(line + '\n');
  });
  p.end();
});

If you comment out that assertion you will get an error:

/projects/oss/tap-out/test/index.js:494
    t.deepEqual(assert.error.expected, 'you')
                            ^
TypeError: Cannot read property 'expected' of undefined
mattdesl commented 9 years ago

Hmm, thinking a bit more about this. Maybe it is the intended result, since by the time the parser reaches "assert" it still has no information about error. Maybe a solution would be:

Anyways, I'm going to render errors at the bottom of the console (after output) so this issue is no longer such a big deal. :smile:

scottcorgan commented 9 years ago

I'll still investigate on the best way to handle this. Feel free to submit a PR if you get anxious.

scottcorgan commented 9 years ago

I'll go ahead and close this and we can revisit if it causes more issues for you.

mattdesl commented 9 years ago

k :+1: