Skip to content

Mocha "before all" hooks run before each test when running from Test Explorer #1604

Open
@ArcanoxDragon

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 required 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 described 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
  1. Set up a test file which describes at least two sample tests
  2. Set up a global hooks file alongside the test file which defines a global before hook
  3. Run mocha from the command line to observe that the hook runs once followed by both tests (proper behavior)
  4. Run all tests from the Visual Studio Test Explorer to observe first that the two tests run without the hook being run at all
  5. Have the test file require the hook file
  6. Run all tests again from the Visual Studio Test Explorer and observe that the hook is now run twice, once before each test

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions