turbo icon indicating copy to clipboard operation
turbo copied to clipboard

[turborepo] Jest tests failing when run in parallel

Open lemiesz opened this issue 2 years ago • 3 comments

What version of Turborepo are you using?

1.5.6

What package manager are you using / does the bug impact?

npm

What operating system are you using?

Linux

Describe the Bug

After installing turbo repo, it seems that my jest tests either fail to run or occasionally time out. Completely nuking my workspace and jest cache seems to resolve this issue temporarily. However im not sure exactly what is happening.

Im running all my test suites in parallell, is there potentially some flag I am forgetting to set in jest that would make doing this unsafe?

Expected Behavior

I expect my parallelized test runner to result in the same test output as running them in serial.

To Reproduce

Cant really show this since its in a private repo. In summary I am running 4 tests suites in paralllel. They run fine before I introduced turbo repo... after running turbo repo they seem to fail non-deterministically. Also, different people now get different errors depending on what machine they run it on.

Mostly seeing errors where tests are timing out.

my turbo.json

{
    "$schema": "https://turborepo.org/schema.json",
    "pipeline": {
        "build": {
            "dependsOn": ["^build"],
            "outputs": ["build/**"],
            "inputs": ["./**"]
        },
        "test": {
            "dependsOn": [],
            "outputs": ["coverage/**"],
            "inputs": ["src/**/*.test.{ts,tsx}"]
        },
        "lint": {
            "outputs": [],
            "inputs": ["src/**"]
        },
        "build-storybook": {
            "dependsOn": ["build"],
            "outputs": [
                "storybook-static/**"
            ]
        },
        "full": {
            "dependsOn": ["build", "test", "lint", "build-storybook"]
        }
    },
    "globalDependencies": ["./craco/**", ".eslintrc", ".babelrc", "./**/.env", "./**/.env.local"]
}

Reproduction Repo

No response

lemiesz avatar Nov 03 '22 20:11 lemiesz

is there potentially some flag I am forgetting to set in jest that would make doing this unsafe?

Try --concurrency=1 for turborepo, or --runInBand flag for Jest. Wild guess would be that Jest running each 4 test suites in parallel is getting in the way of itself?

mehulkar avatar Nov 03 '22 21:11 mehulkar

Jest is recommending only running --runInBand for debuging though? Are there any other consequences of this?

lemiesz avatar Nov 03 '22 23:11 lemiesz

runInBand opts out of Jest's parallelization. The consequence is that your test suite may not run as fast. I am suggesting trying it out for the purpose of debugging and understanding the problem you're running into!

mehulkar avatar Nov 08 '22 08:11 mehulkar

Also experiencing this, with almost the same situation as @lemiesz.

norman-ags avatar May 30 '23 09:05 norman-ags

Closing due to inactivity. Additionally, this sounds like an issue with parallelization of Jest, if I'm guessing.

Please open a fresh issue with a reproduction if you're still interested!

anthonyshew avatar Feb 05 '24 05:02 anthonyshew