mocha icon indicating copy to clipboard operation
mocha copied to clipboard

run global setup before test files load; closes #4508

Open boneskull opened this issue 4 years ago • 8 comments

BREAKING CHANGE

Mocha#run() was orchestrating if and when to run global setup/teardown fixtures, but Mocha#run() must be called after test files have been loaded. This is a problem, because:

  1. --delay may expect something created in a fixture to be accessible, but it won't be
  2. Any future support for async suites is similarly negatively impacted
  3. It was inconsistent between "watch" and "single run" mode; "watch" mode already has this behavior!

This change causes setup fixtures to run before any test files have been loaded. In Node.js, this happens in lib/cli/run-helpers.

  • Added two functions to Mocha; Mocha#globalSetupEnabled() and Mocha#globalTeardownEnabled() which both return booleans
  • Correct order of operations is asserted in test/integration/global-fixtures.spec.js
  • Removed low-value (and newly broken) unit tests where Mocha#run called runGlobalSetup/runGlobalTeardown
  • Add a note to browser-entry.js about global fixtures

This is breaking because:

  1. Browser users now must run setup/teardown fixtures manually.
  2. Somebody's test harness might expect test files to be loaded (and suites run) before global setup fixtures execute.

We should probably merge this, even though I'm loathe to break it--the original design will cause major headaches in future development. My bad!

Closes #4508

boneskull avatar Nov 13 '20 21:11 boneskull

Coverage Status

Coverage increased (+0.02%) to 94.138% when pulling 6bf7da79d5f9377334dfdf9ba9ea49035bbc3cd7 on boneskull/issue/4508-global-fixtures into c6856babc32b8556302a697429114d917dc70427 on master.

coveralls avatar Nov 13 '20 21:11 coveralls

@boneskull Is there any chance of a merge in the near future? This issue is really a pain point for us.

witrin avatar Nov 01 '21 12:11 witrin

@juergba Could you take a look into this? It's still a pain

greguintow avatar Feb 11 '22 12:02 greguintow

What is the status of this one? It would be nice if it gets prioritized

mariobm avatar Apr 26 '22 11:04 mariobm

Can you please commit this

justin-is-a-builder avatar Jul 27 '22 15:07 justin-is-a-builder

@tj

justin-is-a-builder avatar Jul 28 '22 15:07 justin-is-a-builder

@boneskull

justin-is-a-builder avatar Jul 29 '22 17:07 justin-is-a-builder

So glad to see this PR being resurrected 🎉 this bug is a pain in the ass 😄 I understand that maintenance-crew need to take a look at this and approve/improve but if there is something I could help with to push this forward then I can try ;)

mdrobny avatar Mar 27 '24 07:03 mdrobny