Open ArcanoxDragon opened 7 years ago
Could you share an example test file? I recently worked on fixing a similar issue.
Remember that before()
hook runs before each test suite, and describe()
defines a test suite. Are you defining tests using it()
?
I'm setting up a sample project now...of course I can't get the Test Explorer to find any tests now, even though as far as I can tell, it's set up exactly the same as my real project.
Check to make sure that TestFramework for your test file is set to Mocha
and also that Mocha
package is installed locally.
Double checked those...it seems to be a completely separate issue with finding the NodeJsTools.targets file. I'm investigating now.
@ozyx check out my test repo here.
If you npm install
and then npm test
from the command line, you'll see that the tests run and pass just fine. If you try and run them from Test Explorer, however, you'll get an error that should
is not defined because the runner does not run the 0-hooks.js
file before running the tests as it should (and as Mocha does when running from the CLI).
Now, uncomment the first line of both 1-values.js
and 2-functions.js
so that each of those files requires the 0-hooks.js
file. Now the tests run and pass fine, but if you look at the Output of each test, the before()
and after()
global hooks run before each test (not even each suite, but each test).
When running from the CLI, they only run once per session, even though there are multiple suites (describes
) and tests (its
) in that session.
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 eachdescribe
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.Steps to Reproduce
describe
s at least two sample testsbefore
hookmocha
from the command line to observe that the hook runs once followed by both tests (proper behavior)require
the hook file