question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jest not finding any tests

See original GitHub issue

Do you want to request a feature or report a bug?

Bug report.

What is the current behavior?

I’m converting one of my projects to TypeScript here: https://github.com/milesj/optimal Running yarn run jest will not find and run any tests, no matter what variation of testMatch and testRegex that Itry. That being said, it’s correctly finding my jest.config.js, as denoted when using --debug, as seen below.

{
  "configs": [
    {
      "automock": false,
      "browser": false,
      "cache": true,
      "cacheDirectory": "/var/folders/x1/q5gdh6d14h3fkxhgxx75k41h0000gn/T/jest_dx",
      "clearMocks": false,
      "coveragePathIgnorePatterns": [
        "/node_modules/",
        "/lib/",
        "/esm/"
      ],
      "detectLeaks": false,
      "forceCoverageMatch": [],
      "globals": {
        "__DEV__": true,
        "ts-jest": {
          "useBabelrc": true
        }
      },
      "haste": {
        "providesModuleNodeModules": []
      },
      "moduleDirectories": [
        "node_modules"
      ],
      "moduleFileExtensions": [
        ".ts",
        ".tsx",
        ".js",
        ".jsx",
        ".json"
      ],
      "moduleNameMapper": {},
      "modulePathIgnorePatterns": [],
      "name": "656565fb122fb27c21e0885f8d7856db",
      "resetMocks": false,
      "resetModules": false,
      "restoreMocks": false,
      "rootDir": "/Users/Miles/Sites/optimal",
      "roots": [
        "/Users/Miles/Sites/optimal/src",
        "/Users/Miles/Sites/optimal/tests"
      ],
      "runner": "jest-runner",
      "setupFiles": [
        "/Users/Miles/Sites/optimal/node_modules/regenerator-runtime/runtime.js"
      ],
      "setupTestFrameworkScriptFile": null,
      "snapshotSerializers": [],
      "testEnvironment": "jest-environment-jsdom",
      "testEnvironmentOptions": {},
      "testLocationInResults": false,
      "testMatch": [],
      "testPathIgnorePatterns": [
        "/node_modules/"
      ],
      "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
      "testRunner": "/Users/Miles/Sites/optimal/node_modules/jest-jasmine2/build/index.js",
      "testURL": "about:blank",
      "timers": "real",
      "transform": [
        [
          "^.+\\.jsx?$",
          "/Users/Miles/Sites/optimal/node_modules/babel-jest/build/index.js"
        ],
        [
          "^.+\\.tsx?$",
          "/Users/Miles/Sites/optimal/node_modules/ts-jest/index.js"
        ]
      ],
      "transformIgnorePatterns": [
        "/node_modules/"
      ],
      "watchPathIgnorePatterns": []
    }
  ],
  "globalConfig": {
    "bail": false,
    "changedFilesWithAncestor": false,
    "coverageDirectory": "/Users/Miles/Sites/optimal/coverage",
    "coverageReporters": [
      "lcov"
    ],
    "detectLeaks": false,
    "expand": false,
    "globalSetup": null,
    "globalTeardown": null,
    "listTests": false,
    "logHeapUsage": true,
    "maxWorkers": 7,
    "noStackTrace": false,
    "nonFlagArgs": [],
    "notify": false,
    "notifyMode": "always",
    "passWithNoTests": false,
    "rootDir": "/Users/Miles/Sites/optimal",
    "runTestsByPath": false,
    "testFailureExitCode": 1,
    "testPathPattern": "",
    "testResultsProcessor": null,
    "updateSnapshot": "new",
    "useStderr": false,
    "verbose": false,
    "watch": false,
    "watchman": true
  },
  "version": "22.4.2"
}
No tests found
No files found in /Users/Miles/Sites/optimal.
Make sure Jest's configuration does not exclude this directory.
To set up Jest, make sure a package.json file exists.
Jest Documentation: facebook.github.io/jest/docs/configuration.html
Pattern:  - 0 matches

What is the expected behavior?

It finds and runs my tests.

Please provide your exact Jest configuration

My Jest configuration is automatically built with Beemo, but looks like the following.

module.exports = {
  "coverageDirectory": "./coverage",
  "coveragePathIgnorePatterns": [
    "/node_modules/",
    "/lib/",
    "/esm/"
  ],
  "coverageReporters": [
    "lcov"
  ],
  "globals": {
    "__DEV__": true,
    "ts-jest": {
      "useBabelrc": true
    }
  },
  "moduleFileExtensions": [
    ".ts",
    ".tsx",
    ".js",
    ".jsx",
    ".json"
  ],
  "rootDir": "/Users/Miles/Sites/optimal",
  "roots": [
    "./src",
    "./tests"
  ],
  "setupFiles": [],
  "setupTestFrameworkScriptFile": null,
  "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
  "transform": {
    "^.+\\.jsx?$": "babel-jest",
    "^.+\\.tsx?$": "ts-jest"
  },
  "verbose": false
};

Run npx envinfo --preset jest in your project directory and paste the results here

System: OS: macOS High Sierra 10.13.3 CPU: x64 Intel® Core™ i7-4870HQ CPU @ 2.50GHz Binaries: Node: 9.8.0 Yarn: 1.5.1 npm: 5.1.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

4reactions
milesjcommented, Mar 21, 2018

Turns out the problem was that my moduleFileExtensions had a preceeding period. Perhaps Jest should check for that.

0reactions
github-actions[bot]commented, May 11, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest No Tests found - Stack Overflow
No tests found In /usr/src/app says that Jest is looking for tests in /usr/src/app , and testPathIgnorePatterns: /node_modules/,/src,src says ...
Read more >
jest cannot find tests when projects are defined in configuration
Basically I got a bunch of files for my Electron app, some of them require a node environment, and some of them jsdom,...
Read more >
Troubleshooting - Jest
Troubleshooting. Uh oh, something went wrong? Use this guide to resolve issues with Jest. Tests are Failing and You Don't Know Why​.
Read more >
wrong test pattern when running single Jest test, 'no tests found'
No tests found. In C:\WebstormProjects\untitled4 4 files checked. testMatch: **/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x) - 1 match
Read more >
Jest — Filenames without test or spec | by Damian Myerscough
I was recently writing some unit tests with the Jest framework for a ... glob pattern always returns the message “No tests found,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found