Skip to content

Running the dev script concurrently with the Jest test script causes Jest to re-run the tests on page compilation #32650

@sfiquet

Description

@sfiquet

What version of Next.js are you using?

12.0.4

What version of Node.js are you using?

14.18.2

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

Vercel

Describe the Bug

jest --watch re-runs the test suites every time the dev server compiles a page. This bug is present on both the babel and swc versions of the jest config.


I found out that the Jest watcher is watching the .next/ folder. It used to ignore dot files and folders but that behaviour was changed last year (jestjs/jest#10075). It is now necessary to specify the dot folder in watchPathIgnorePatterns. I created a PR with Jest to change the documentation: jestjs/jest#12161

Expected Behavior

I expect Jest in watch mode to only re-run the test suites when source files or test files have changed, not when the dev server writes to .next/.

To Reproduce

Step 1: Set up a project with any of the Jest configurations (Babel or Swc). The project needs to have several pages to be able to navigate between them.

Step 2: run yarn dev in a terminal. In another terminal, run yarn test. The scripts are standard:

  "scripts": {
    "dev": "next dev",
    "test": "jest --watch"
  }

Step 3: in the jest terminal, press A to run all tests.
My original case was to add a page and a related test file. But running all tests requires less work to show the same result.

Step 4: In the browser, navigate between pages.

Result:

  • Each time a page is compiled, you get something like this in the dev server terminal (expected):
wait  - compiling /about...
event - compiled successfully in 190 ms (221 modules)
  • At the same time, in the jest terminal, the test suites are re-rerun, in spite of there being no change to the source or test files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    TestingRelated to testing with Next.js.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions