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

Tests: remove t.plan in favour of t.end #27

Open
michaelfig opened this issue Jul 24, 2019 · 5 comments
Open

Tests: remove t.plan in favour of t.end #27

michaelfig opened this issue Jul 24, 2019 · 5 comments

Comments

@michaelfig
Copy link
Member

This repo should not use t.plan(NNN). It is a burden to maintain and doesn't gain anything over t.end().

For robustness (allowing subsequent test cases to run after one fails with an exception), the preferred pattern for test cases is:

test('description', t => {
  try {
    // [Test assertions go here.]
  } catch (e) {
    // [Fail the test case if there is an unexpected exception.]
    t.assert(false, e);
  } finally {
    // [Mark this test case as finished.]
    t.end();
  }
});
@erights
Copy link
Member

erights commented Jul 24, 2019

Won't test itself deal with the thrown error? If so, I'd prefer to omit the try/catch

@michaelfig
Copy link
Member Author

No, it doesn't deal with thrown errors. It just aborts the whole test suite with a stack trace.

@michaelfig
Copy link
Member Author

I'm asking for advice from the tape-promise authors in jprichardson/tape-promise#19

@warner
Copy link
Member

warner commented Jul 26, 2019

When trying to get a test to pass for the first time, I think I might actually prefer if the whole test suite aborts. If it doesn't do that, I find it difficult to scroll back through all the subsequent tests to find the one that failed (piping everything into a pager doesn't usually work for me, because some stuff goes to stdout and some to stderr, and then I also lose all the coloring that tape and/or our frontends are providing). Also, tape doesn't print the filename of the tests it is running, so it's often a slow process to deduce which test is failing without a stack trace to work from.

(of course none of this is relevant to removing t.plan, that's obviously the right thing to do regardless)

@michaelfig
Copy link
Member Author

michaelfig commented Aug 15, 2019

The pattern I've been using that reports exceptions properly is to make the new test as:

// Just run this test until you're ready to remove `.only` and run the whole suite.
test.only('description', t => {
  try {
    // [Test assertions go here.]
  } catch (e) {
    // [Fail the test case and write the stack trace.]
    t.isNot(e, e, 'unexpected exception');
  } finally {
    // [Mark this test case as finished.]
    t.end();
  }
});

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

3 participants