Open
Description
Prerequisites
- Checked that your issue hasn't already been filed by cross-referencing issues with the
faq
label - Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
- 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
node node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.
Description
When using global fixtures, mocha loads the test files before running mochaGlobalSetup
. This can cause issues when dependencies themselves load top-level configurations . But when --watch
is passed, it works as expected.
This behavior differs from the following statements in the documentation:
Work identically parallel mode, watch mode, and serial mode
Now, before Mocha loads and runs your tests, it will execute the above global setup fixture, starting a server for testing.
Steps to Reproduce
fixtures.js
exports.mochaGlobalSetup = function() {
console.log(`mochaGlobalSetup`);
}
test.js
console.log('Test file loaded')
it('runs', () => { })
Expected behavior:
Should run mochaGlobalSetup
before loading the test files in all cases.
Actual behavior: [What actually happens]
> npx mocha -r fixtures.js test.js
Test file loaded
mochaGlobalSetup
✓ runs
1 passing (3ms)
> npx mocha -r fixtures.js test.js --watch
mochaGlobalSetup
Test file loaded
✓ runs
1 passing (2ms)
ℹ [mocha] waiting for changes...
Reproduces how often: 100%
Versions
node --version
:Unknown command: mocha
node node_modules/.bin/mocha --version
:8.2.1
node --version
:v10.22.1
- Your operating system:
macOS Catalina 10.15.7 64bit
- Your shell (e.g., bash, zsh, PowerShell, cmd):
fish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment