jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.05k stars 6.43k forks source link

Setup and teardown run in skipped suites and tests #5593

Closed eyelidlessness closed 6 years ago

eyelidlessness commented 6 years ago

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

Setup and teardown (before* and after*) is run for skipped suites (describe) and tests (it et al).

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

https://repl.it/repls/MuddyYellowgreenEngineer

What is the expected behavior?

Setup and teardown will not be run for tests that are skipped.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

As this is reproducible on repl.it, I'm not sure these will help narrow down the issue, but I'll provide them anyway to expedite the issue.

Config:

{
    "modulePaths": [
        "<rootDir>/dist"
    ],
    "setupTestFrameworkScriptFile": "<rootDir>/dist/testHelpers/integrationTestSetup.js",
    "testEnvironment": "node",
    "testMatch": [
        "**/providers/*/integrationTests/**/manifests.test.js"
    ],
    "verbose": true
}

Node: 8.6.0 NPM: 5.6.0 OS: OS X 10.11.6

eyelidlessness commented 6 years ago

I'd like to add a few notes on the impact this can have:

  1. The Jest docs specifically call out isolating tests to ensure there isn't an inter-test conflict. Presumably this would be the same for setup and teardown. (This is not the problem in my case, but it might cause problems for others following this advice.)

  2. Setup and teardown can cause side effects that do not impact the tests specifically, but are unexpected. In my case, I am (sadly but unavoidably) writing integration tests that cause irreversible side effects on an external service.

  3. This can cause long-running tests to run significantly longer than expected.

SimenB commented 6 years ago

Duplicate of #4820

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.