Search code examples
node.jsjestjspuppeteertesting-library

when using testing-library jest runs too many tests...not the ones I want


For some reason I can't seem to split out "cypress, puppeteer and jest unit tests" into separate commands:

package.json:

        "test:jest": "jest ./src",
        "e2e:pptr": "npm run dev & jest ./tests",
        "e2e:cypress": "npm run dev & cypress run",
        "e2e:cypress:browser": "npm run dev & cypress open",

...

    "jest": {
        "verbose": true,
        "testEnvironment": "jsdom",
        "transform": {
            "^.+\\.svelte$": [
                "svelte-jester",
                {
                    "preprocess": true
                }
            ],
            "^.+\\.js$": "babel-jest",
            "^.+\\.ts$": "ts-jest"
        },
        "moduleFileExtensions": [
            "js",
            "ts",
            "svelte"
        ],
        "setupFilesAfterEnv": [
            "@testing-library/jest-dom/extend-expect"
        ]
    }

WHen I run npm run test:jest it still runs all tests. including cypress and ./tests/*.spec.js files. Its suppposed to just run tests under ./src which are my unit tests.

puppeteer tests are in ./tests/*.spec.js and cypresss are under ./cypress/*


Solution

  • So I needed to add --rootDir <path> to limit it.

    "test:jest": "jest --rootDir ./src",