How to fix Jest "No Tests Found" on windows 10?

Viewed 5618

I am trying to use Jest on my windows 10 desktop computer, but it keeps telling me that there are no tests found. On my windows 10 laptop, it works just fine. Here is the output I am getting on my desktop:

C:\app> jest
No tests found
In C:\app
   25163 files checked.
   testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 743 matches
   testPathIgnorePatterns: \\node_modules\\ - 25163 matches
Pattern: "" - 0 matches

In my package.json file, my jest config looks like this:

"jest": {
  "collectCoverageFrom": [
    "app/**/*.{js,jsx}",
    "!app/**/*.test.{js,jsx}",
    "!app/*/RbGenerated*/*.{js,jsx}",
    "!app/app.js"
  ],
  "coverageThreshold": {
    "global": {
      "statements": 98,
      "branches": 91,
      "functions": 98,
      "lines": 98
    }
  },
  "moduleDirectories": [
    "node_modules",
    "app",
    "common"
  ],
  "moduleNameMapper": {
    ".*\\.(css|less|styl|scss|sass)$": "<rootDir>/internals/mocks/cssModule.js",
    ".*\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/internals/mocks/image.js"
  },
  "setupTestFrameworkScriptFile": "<rootDir>/internals/testing/test-bundler.js"
}

I am using node 8.1.4 and jest v20.0.4 Any ideas on how to get jest to locate my tests?

5 Answers

Seeing this issue with Jest 24.8.0. It seems if you add --runTestsByPath it will correctly handle forward/backspaces,

There is a discussion of the issue https://github.com/microsoft/vscode-recipes/issues/205#issuecomment-533645097, with the following suggested VSCode debug configuration

{
  "type": "node",
  "request": "launch",
  "name": "Jest Current File",
  "program": "${workspaceFolder}/node_modules/.bin/jest",
  "args": [
   "--runTestsByPath",   // This ensures the next line is treated as a path
   "${relativeFile}",    // This path may contain backslashes on windows
    "--config",
    "jest.config.js"
  ],
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "disableOptimisticBPs": true,
  "windows": {
    "program": "${workspaceFolder}/node_modules/jest/bin/jest",
  }
}

If I run the console command

jest test/components/checkBox/treezCheckBox.test.js

the tests in that file are found and executed.

If I instead run the console command

jest test\components\checkBox\treezCheckBox.test.js

I get the error

No tests found, exiting with code 1
Run with `--passWithNoTests` to exit with code 0
In D:\treezjs
  814 files checked.
  testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 44 matches
  testPathIgnorePatterns: \\node_modules\\ - 814 matches
  testRegex:  - 0 matches
Pattern: test\components\checkBox\treezCheckBox.test.js - 0 matches

=> It seems to be important if forward or backward slashes are used.

Using doubled backward slashes works:

jest test\\components\\checkBox\\treezCheckBox.test.js

If you use a vscode launch configuration with a file path variable ${file}, the resulting system command unfortunately contains single "\" as separator.

Also see discussion and linked issues at https://github.com/Microsoft/vscode/issues/40256 (Last statement is outdated; ${relativeFile} also uses "\".)

Work around: Use a debug extension (e.g. Daddy Jest) instead of a custom launch configuration.

I have removed -- --watch from package.json where I wrote "test" : "jest -- --watch"

Related