Mocha "before all" hooks run before each test when running from Test Explorer #1604
Description
Expected Behavior
When running Mocha tests from the VS2017 Test Explorer window, any "before all" hooks should be run once for the entire session (and any state created by the hooks should persist across all tests). Likewise, any "after all" hooks should only run once all tests are complete.
Actual Behavior
Firstly, global hooks are not discovered automatically unless the file describing the hooks is require
d by all test files. Secondly, any global "before all" and "after all" hooks end up running once per test as opposed to once per session. In my project, I am using a global "before all" hook to call Gulp and compile my TypeScript files before testing. When running from the command line, Gulp runs once before the testing session and then all the tests run. When running from NTVS' Test Explorer adapter, however, Gulp runs before each describe
d test, causing the duration of each test to be upwards of 20 seconds as opposed to the milliseconds they take on the command line.
- NTVS Version: 1.3.50417.1
- Visual Studio Version: VS2017 Version 15.2 (26430.6)
- Node.js Version: 7.7.1
Steps to Reproduce
- Set up a test file which
describe
s at least two sample tests - Set up a global hooks file alongside the test file which defines a global
before
hook - Run
mocha
from the command line to observe that the hook runs once followed by both tests (proper behavior) - Run all tests from the Visual Studio Test Explorer to observe first that the two tests run without the hook being run at all
- Have the test file
require
the hook file - Run all tests again from the Visual Studio Test Explorer and observe that the hook is now run twice, once before each test
Activity