every other testing suite that i've come across in my career (including, since it's a peer-ish library to mocha, jest) will consistently report results for all tests on each run - more specifically, it will show a test failure (or error, which is distinct from a "failure", depending on the framework) for each test in the suite(s) you're trying to execute, regardless of whether that failure occurred in a setup phase or in the test itself. mocha, however, appears to roll test setup failures that occur in before/beforeEach hooks into a single "failure", effectively swallowing counts of all the tests that were sidelined by the setup failure. this makes it rather frustrating to compare outputs between runs, understand the number of tests impacted by that setup failure at a glance, and can make reporting metrics from test runs somewhat meaningless due to the variance in the number of tests actually being reported on.
additionally, it seems that a failure in beforeEach will just circuit-break the execution of that setup function entirely, instead of retrying for subsequent tests, which honestly contravenes the name and intent of the function in the context of software testing conventions.
before or beforeEach hook, introduce an intentional failure in the hook.beforebeforeEachnpm test--reporter options don't appear to have any affect on thisExpected behavior:
N tests (regardless of how they're nested in subsuites) should report on the outcome of N tests, even if there is a failure in a before or beforeEach hook.Actual behavior: [What actually happens]
before or beforeEach hook will only report a single failure.Reproduces how often: 100% - it seems to be by design..? so perhaps this should be a feature request instead?
mocha --version: 8.0.1node node_modules/.bin/mocha --version: 8.0.1node --version: v12.18.1osX Catalina 10.15.5x64zsh 5.7.1 (x86_64-apple-darwin19.0)If before or beforeEach fails, would you expect the tests to be _run_ or would you just expect them to be _reported_?
Some notes:
Assuming you just want tests _reported_ if their hooks fail, this could be implemented in a non-breaking, opt-in manner: Mocha's runner could emit new events. Third-party reporters could then output this additional information.
before/beforeEach stacktrack/error once is totally fine and reasonable, but reporting the actual tests downstream of that error as "failed" (or "blocked", or whatever other term to indicate they couldn't even start execution, though it should be distinct from "skipped" imo) would be a pleasant improvement in specificity.also, i definitely understand that changing this sort of functionality (and specifically, making it the new default) could totally hose a lot of people's projects / CI/CD, but as you also mention above, making the feature an opt-in switch on the runner would be a really nice and relatively non-disruptive way to do this.
thanks for your detailed response!
Most helpful comment
Some notes:
Assuming you just want tests _reported_ if their hooks fail, this could be implemented in a non-breaking, opt-in manner: Mocha's runner could emit new events. Third-party reporters could then output this additional information.