9

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?

Andy Hansen
  • 313
  • 3
  • 8

5 Answers5

4

I am not 100% sure its the same issue. But what solved it for me was to get rid of watchman (I added it in on path for another project that used relay). Try to run with --no-watchman (or set watchman: false in jest config)

MatijaG
  • 818
  • 1
  • 9
  • 12
  • I found this problem running Jest 27.5.1 on Windows 11. There was no way to make Jest detect tests that were clearly in the expected folder. This setting has solved the problem. Thank you so much – amda Apr 20 '22 at 09:07
4

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",
  }
}
FrozenKiwi
  • 1,362
  • 13
  • 26
  • This worked for me. I added '--runTestsByPath' to the script entry in my package.json. "test": "jest --runTestsByPath --coverage". – Jason Hunt Jun 29 '21 at 13:28
1

For anyone attempting to find out how to fix this issue, this was a bug in Jest that was fixed in v22.

Changelog: https://github.com/facebook/jest/blob/master/CHANGELOG.md (PR #5054)

peonicles
  • 1,607
  • 2
  • 20
  • 28
1

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.

Stefan
  • 10,010
  • 7
  • 61
  • 117
  • Using double backslashes works fine... until your app needs to work cross-platform. On Linux this does not work at all. I can't seem to find a format which works on both. – Marc Feb 14 '20 at 16:29
0

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

Zach Valenta
  • 1,783
  • 1
  • 20
  • 35