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

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

Closed
mattdesl opened this issue Jun 3, 2015 · 6 comments
Closed

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

mattdesl opened this issue Jun 3, 2015 · 6 comments

Comments

@mattdesl
Copy link
Collaborator

mattdesl commented Jun 3, 2015

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
Copy link
Owner

Can you show me some code and maybe a screenshot?

@mattdesl
Copy link
Collaborator Author

mattdesl commented Jun 3, 2015

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
Copy link
Collaborator Author

mattdesl commented Jun 3, 2015

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:

  • emit a different event when error has been parsed
  • do not send an empty error object to the event of 'assert' to avoid confusion

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. 😄

@scottcorgan
Copy link
Owner

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

@scottcorgan
Copy link
Owner

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

@mattdesl
Copy link
Collaborator Author

k 👍

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

No branches or pull requests

2 participants