Skip to content

🚀 Feature: Detect and report on invalid test pass/fail/pending state #3223

Open
@boneskull

Description

If an task created by a test would throw an exception (or rejection) and this test has already passed or failed, then Mocha's output gets wonky (using spec reporter, for example):

  • the test name may repeat multiple times, with different results for each
  • we can't just limit it, because suppression thereof means errors can't easily be cross-referenced by number
  • the total pass/fail/pending count will be larger than the total number of tests executed, because a test will have been reported to be in multiple states
  • multiple errors may be output for a single test

Here are two ideas to mitigate this:

  1. Decouple any exception a test causes after it has completed from the test itself, for reporting purposes. Such errors would simply not count towards statistics, but would display nevertheless. The test, then, would not necessarily fail (unless it did originally), but the test run would fail.
    This could be significantly disruptive to the reporting system. Simply swapping a reporter out for another should not change the results!

  2. Determine, by way of async hooks or otherwise, when a test is truly "complete". Don't record the test result until there are no further tasks in the queue.
    Difficult. May slow down some tests significantly. Would need to cancel the timeout when done() is called (or whatever); might want to record the delta between when the test finishes and when the test's tasks complete. Consuming async hooks / zones / realms etc. could either be great (eliminate many edge and corner cases) or terrible (increased complexity and black magic).

There's no end to problems from these types of errors. They shatter Mocha's assumptions about the current state of things; Mocha is trying to run tests serially, after all. Test B should never seem to fail because of something Test A did; and even so, we should know that it was Test A's fault.


Here's a philosophical question:

Can Mocha rely on the user to tell Mocha when a test completes, and how it completed?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: usabilityconcerning user experience or interfacestatus: accepting prsMocha can use your help with this one!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions