Jest: No tests found on Travis with Jest 22

Created on 19 Dec 2017  路  8Comments  路  Source: facebook/jest

Do you want to request a _feature_ or report a _bug_?

bug

What is the current behavior?

Everything works (all tests were found and passed) on the local machine, but Travis CI reports:

No tests found
No files found in /home/travis/build/postcss/postcss.
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

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

Not sure how to reproduce expect fork postcss/postcss and push something to force Travis CI for the local branch.

Maybe you can suggest checking something? I already tried removing gulp-jest to npm scripts, removing .babelrc from the project, run jest and jest test/*.test.js. The result was the same :(.

I got first issue just after dependencies update with new Jest 22.

What is the expected behavior?

Found tests on Travis CI.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

  "jest": {
    "testEnvironment": "node",
    "modulePathIgnorePatterns": [
      "build"
    ]
  }
$ node --version
v9.3.0

$ npm --version
5.5.1

$ nvm --version
0.33.8

No .babelrc in the project.

Confirmed Help Wanted

Most helpful comment

@ai this diff makes the tests run without warning:

diff --git i/package.json w/package.json
index 6a956b3..2a1cbe3 100644
--- i/package.json
+++ w/package.json
@@ -84,7 +84,7 @@
   "jest": {
     "testEnvironment": "node",
     "modulePathIgnorePatterns": [
-      "build"
+      "<rootDir>/build"
     ]
   },
   "eslintConfig": {

It effectively does what you want with cwd. I still wonder if it's a bug though - we should find tests covered by modulePathIgnorePatterns.

Aha, I found it is actually in the changelog, thanks.

Yeah, just marked it as breaking after somebody else had the same issue. We (at least I) didn't really think about --findRelatedTests when changing that behavior. I still think it's the correct change, though, it makes sense to return 1 when we can't find tests, I think 馃檪

All 8 comments

No files found in /home/travis/build/postcss/postcss. travis check out your project in a build directory. If you have postcss repo in a dir called build locally, you get the same error.

Is it because of Trusty you haven't seen it before? Might be a new bug in 22, it does seem somewhat odd that modulePathIgnorePatterns effects tests - we have a separate testPathIgnorePatterns...

Hm. Thanks for pointing to modulePathIgnorePatterns. I removed it and tests are passed.

Of course, right now I have

ap: @providesModule naming collision:
  Duplicate module name: postcss
  Paths: /home/travis/build/postcss/postcss/build/package.json collides with /home/travis/build/postcss/postcss/package.json

But it is not big deal.

Maybe process.cwd should be trimmed from path before modulePathIgnorePatterns check? So modulePathIgnorePatterns will be applied to the path inside the project.

I think it could a Jest 22 regression bug related to --findRelatedTests.
I execute jest command with pre-commit hook.
In Jest 21, the setup is okay.
After upgrade to Jest 22, it will complain if jest cannot find any related tests with committed files.

ozhou-pro:xxx zhouyujie$ yarn run jest --findRelatedTests ./jest.config.js
yarn run v1.3.2
$ /Users/zhouyujie/dev/xxx/yyy/node_modules/.bin/jest --findRelatedTests ./jest.config.js
No tests found
No files found in /Users/zhouyujie/dev/xxx/yyy.
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: ./jest.config.js - 0 matches
error Command failed with exit code 1.

It can be solved by adding "passWithNoTests" command line switch, anyway. But it's still a breaking change. Better to mention it in the changelog


Aha, I found it is actually in the changelog, thanks.

@ai this diff makes the tests run without warning:

diff --git i/package.json w/package.json
index 6a956b3..2a1cbe3 100644
--- i/package.json
+++ w/package.json
@@ -84,7 +84,7 @@
   "jest": {
     "testEnvironment": "node",
     "modulePathIgnorePatterns": [
-      "build"
+      "<rootDir>/build"
     ]
   },
   "eslintConfig": {

It effectively does what you want with cwd. I still wonder if it's a bug though - we should find tests covered by modulePathIgnorePatterns.

Aha, I found it is actually in the changelog, thanks.

Yeah, just marked it as breaking after somebody else had the same issue. We (at least I) didn't really think about --findRelatedTests when changing that behavior. I still think it's the correct change, though, it makes sense to return 1 when we can't find tests, I think 馃檪

Closing this as the fix was to use <rootDir>.

Wow, this was super subtle. I spent a few hours debugging this today. Travis wouldn't find any tests and always fail because I excluded the build directory. Why isn't it the default to only look below the root directory? I cannot think of any reason why you would want to exclude based on a directory above the root directory.

I agree we should not care about the path outside of rootDir. Potentially add it unless the path given is absolute.

Was this page helpful?
0 / 5 - 0 ratings