Skip to content

[FeatureRequest] Allow jest to be ran without watch mode. #6284

Closed
@ricokahler

Description

@ricokahler

It seems like the only way to get jest to run in without watch mode is to run it with --coverage or set the environment variable to CI=true. Running npm test -- --watch=false (and similar) does not work.

My use case for this feature is debugging within VS Code through react scripts.

The following launch configuration was given in the create-react-app docs

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug CRA Tests",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
      "args": [
        "test",
        "--runInBand",
        "--no-cache"
      ],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}

This somewhat works but it does not break at breakpoints because (I think) react-scripts is runs jest in watch mode. Adding "env": { "CI": "true" }, allows breakpoints to work again because it disables watch mode.

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Create react app debugging",
      "type": "node",
      "request": "launch",
      "env": { "CI": "true" }, // this makes breakpoints work 
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
      "args": ["test", "--runInBand", "--no-cache"],
      "cwd": "${workspaceRoot}",
      "protocol": "inspector",
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
  ]
}

I'm fine with this workaround but I'd happier with a --watch=false, --no-watch, --single, or similar flag.

Thanks for the amazing tool and I apologize if I missed anything!

Somewhat related issues:

#784
#1137

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions