jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.27k stars 6.46k forks source link

Jest not finding any tests #5829

Closed milesj closed 6 years ago

milesj commented 6 years ago

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(R) Core(TM) i7-4870HQ CPU @ 2.50GHz Binaries: Node: 9.8.0 Yarn: 1.5.1 npm: 5.1.0

milesj commented 6 years ago

I got it to work briefly using moduleFileExtensions: ['.js', '.jsx', '.json', '.ts', '.tsx'],, but then it stopped working again. This seems really weird.

milesj commented 6 years ago

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

SimenB commented 6 years ago

That should definitely be in the docs! Mind sending a PR for it?

sidkareem commented 4 years ago

im having the same issue.im actually doing the udemy course and currently working on testing..

No tests found No files found in C:\Users\sidka\nodejs\node_modules\redux-adv-burger--01-async-action-ingredients. 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: /NavigationItems/ - 0 matches

Active Filters: filename /NavigationItems/ › Press c to clear filters.

Watch Usage › Press a to run all tests. › Press o to only run tests related to changed files. › Press p to filter by a filename regex pattern. › Press t to filter by a test name regex pattern. › Press q to quit watch mode. › Press Enter to trigger a test run. ..what do i do?

this is package.json file.. { "name": "react-complete-guide", "version": "0.1.0", "private": true, "dependencies": { "autoprefixer": "7.1.2", "axios": "^0.16.2", "babel-core": "6.25.0", "babel-eslint": "7.2.3", "babel-jest": "20.0.3", "babel-loader": "7.1.1", "babel-preset-react-app": "^3.0.2", "babel-runtime": "6.26.0", "case-sensitive-paths-webpack-plugin": "2.1.1", "chalk": "1.1.3", "css-loader": "0.28.4", "dotenv": "4.0.0", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.4", "eslint": "4.4.1", "eslint-config-react-app": "^2.0.0", "eslint-loader": "1.9.0", "eslint-plugin-flowtype": "2.35.0", "eslint-plugin-import": "2.7.0", "eslint-plugin-jsx-a11y": "5.1.1", "eslint-plugin-react": "7.1.0", "extract-text-webpack-plugin": "3.0.0", "file-loader": "0.11.2", "fs-extra": "3.0.1", "html-webpack-plugin": "2.29.0", "jest": "20.0.4", "object-assign": "4.1.1", "postcss-flexbugs-fixes": "3.2.0", "postcss-loader": "2.0.6", "promise": "8.0.1", "prop-types": "^15.6.0", "r": "0.0.5", "react": "^16.0.0", "react-dev-utils": "^4.0.1", "react-dom": "^16.0.0", "react-redux": "^5.0.6", "react-router-dom": "^4.2.2", "react-test-renderer": "^16.13.1", "redux": "^3.7.2", "redux-thunk": "^2.2.0", "style-loader": "0.18.2", "sw-precache-webpack-plugin": "0.11.4", "url-loader": "0.5.9", "webpack": "3.5.1", "webpack-dev-server": "2.7.1", "webpack-manifest-plugin": "1.2.1", "whatwg-fetch": "2.0.3" }, "scripts": { "start": "node scripts/start.js", "build": "node scripts/build.js", "test": "node scripts/test.js --env=jsdom" }, "jest": { "collectCoverageFrom": [ "src//.{js,jsx}" ], "setupFiles": [ "/config/polyfills.js" ], "testMatch": [ "/src//tests//.js?(x)", "/src//?(.)(spec|test).js?(x)" ], "testEnvironment": "node", "testURL": "http://localhost", "transform": { "^.+\.(js|jsx)$": "/node_modules/babel-jest", "^.+\.css$": "/config/jest/cssTransform.js", "^(?!.\.(js|jsx|css|json)$)": "/config/jest/fileTransform.js" }, "transformIgnorePatterns": [ "[/\\]node_modules[/\\].+\.(js|jsx)$" ], "moduleNameMapper": { "^react-native$": "react-native-web" }, "moduleFileExtensions": [ "web.js", "js", "json", "web.jsx", "jsx", "node" ] }, "babel": { "presets": [ "react-app" ] }, "eslintConfig": { "extends": "react-app" } }

github-actions[bot] commented 3 years ago

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.