Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only ignore root /node_modules/ #1995

Closed
julien-f opened this issue Oct 25, 2016 · 17 comments
Closed

Only ignore root /node_modules/ #1995

julien-f opened this issue Oct 25, 2016 · 17 comments

Comments

@julien-f
Copy link

Do you want to request a feature or report a bug? feature (or help to configure ;) )

What is the current behavior?

All node_modules/ directories are ignored.

What is the expected behavior?

I would like to ignore only the root node_modules/ directory.

My project organization:

src/
├── node_modules
│   └── local packages (imported via absolute paths)
└── code (imported via relative paths)

The ideas is to build generic-ish modules in src/node_modules.

If a local packages become useful on its own I can publish it in its own package without having to change my code.

It is IMHO the best solution to achieve this kind of behavior by exploiting the locality rule of modules resolution, without having to use a hack like NODE_PATH (which is discouraged).

Run Jest again with --debug and provide the full configuration it prints. Please mention your node and npm version and operating system.

node version = 6.9.1
npm version = 3.10.8
operating system = Debian Stretch
jest version = 16.0.2
test framework = jasmine2
config = {
  "rootDir": "/my-project",
  "name": "-my-project",
  "setupFiles": [
    "/my-project/node_modules/babel-polyfill/lib/index.js"
  ],
  "testRunner": "/my-project/node_modules/jest-jasmine2/build/index.js",
  "scriptPreprocessor": "/my-project/node_modules/babel-jest/build/index.js",
  "usesBabelJest": true,
  "automock": false,
  "bail": false,
  "browser": false,
  "cacheDirectory": "/tmp/jest",
  "clearMocks": false,
  "coveragePathIgnorePatterns": [
    "/node_modules/"
  ],
  "coverageReporters": [
    "json",
    "text",
    "lcov",
    "clover"
  ],
  "globals": {},
  "haste": {
    "providesModuleNodeModules": []
  },
  "mocksPattern": "__mocks__",
  "moduleDirectories": [
    "node_modules"
  ],
  "moduleFileExtensions": [
    "js",
    "json",
    "jsx",
    "node"
  ],
  "moduleNameMapper": {},
  "modulePathIgnorePatterns": [],
  "noStackTrace": false,
  "notify": false,
  "preset": null,
  "preprocessorIgnorePatterns": [
    "/node_modules/"
  ],
  "resetModules": false,
  "testEnvironment": "jest-environment-jsdom",
  "testPathDirs": [
    "/my-project"
  ],
  "testPathIgnorePatterns": [
    "/node_modules/"
  ],
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.jsx?$",
  "testURL": "about:blank",
  "timers": "real",
  "useStderr": false,
  "verbose": null,
  "watch": false,
  "cache": true,
  "watchman": true,
  "testcheckOptions": {
    "times": 100,
    "maxSize": 200
  }
}
No tests found
  21 files checked.
  testPathDirs: /my-project - 21 matches
  testRegex: (/__tests__/.*|\.(test|spec))\.jsx?$ - 0 matches
  testPathIgnorePatterns: /node_modules/ - 21 matches
@julien-f
Copy link
Author

I tried setting testPathIgnorePatterns to an empty array in package.json but I also got 21 matches…

@cpojer
Copy link
Member

cpojer commented Oct 26, 2016

I recommend using lerna: https://github.com/lerna/lerna

You should be able to set testPathIgnorePatterns to ['<rootDir>/node_modules'] to exclude only the top level folder.

@cpojer cpojer closed this as completed Oct 26, 2016
@julien-f
Copy link
Author

I recommend using lerna: https://github.com/lerna/lerna

I will be if I could keep this simple setup for now without add a dependency it would be nice :)

You should be able to set testPathIgnorePatterns to ['/node_modules'] to exclude only the top level folder.

Does not seem to work :/
Maybe I'm doing something wrong… You can take a look at my code there: https://github.com/vatesfr/xo-server/tree/architecture-rework

@cpojer
Copy link
Member

cpojer commented Oct 26, 2016

I tried using this branch and a getting this:

 FAIL  dist/decorators.spec.js
  ● Test suite failed to run

    Cannot find module 'must' from 'decorators.spec.js'

      at Resolver.resolveModule (../jest/packages/jest-resolve/build/index.js:150:17)
      at Object.<anonymous> (dist/decorators.spec.js:27:13)

 FAIL  dist/job-executor.spec.js
  ● Test suite failed to run

    Cannot find module 'leche' from 'job-executor.spec.js'

      at Resolver.resolveModule (../jest/packages/jest-resolve/build/index.js:150:17)
      at Object.<anonymous> (dist/job-executor.spec.js:3:14)

 FAIL  dist/math.spec.js
  ● Test suite failed to run

    Cannot find module 'chai' from 'math.spec.js'

      at Resolver.resolveModule (../jest/packages/jest-resolve/build/index.js:150:17)
      at Object.<anonymous> (dist/math.spec.js:3:13)

 FAIL  dist/utils.spec.js
  ● Test suite failed to run

    Cannot find module 'must' from 'utils.spec.js'

      at Resolver.resolveModule (../jest/packages/jest-resolve/build/index.js:150:17)
      at Object.<anonymous> (dist/utils.spec.js:23:13)

Test Suites: 4 failed, 4 total
Tests:       0 total
Snapshots:   0 total
Time:        1.407s
Ran all test suites.

doesn't seem like this is related? I can't find these modules anywhere in the tree.

@julien-f
Copy link
Author

These files come from the next-release branch, you probably have to remove dist/ :)

@cpojer
Copy link
Member

cpojer commented Oct 26, 2016

Can you provide a repro that I can npm install that shows which problem you are running into?

@julien-f
Copy link
Author

git clone -b architecture-rework https://github.com/vatesfr/xo-server.git
cd xo-server
npm install
npm test

@julien-f
Copy link
Author

Can you reproduce?

@cpojer
Copy link
Member

cpojer commented Oct 26, 2016

Thanks. You are right, we actually filter out files in node_modules folders way before doing any work. This happens here: https://github.com/cpojer/jest/blob/master/packages/jest-haste-map/src/index.js#L302 – this option is currently private but if you'd like to send a PR that adds "retainAllFiles" to the "haste" config field and is threaded through to jest-haste-map accordingly, I'm happy to support this. It's basically adding the option here: https://github.com/cpojer/jest/blob/master/packages/jest-runtime/src/index.js#L225 – check out the contributing guide on how to get set-up!

Otherwise I'd keep suggesting lerna. It's unlikely I'll be able to spend any time working on the fix myself :(

@julien-f
Copy link
Author

Thanks for your time, I'll see what I can do :)

@ivan7237d
Copy link

ivan7237d commented Aug 22, 2017

It seems that

"testPathIgnorePatterns": [
  "<rootDir>/node_modules/"
]

has no effect — tests in any node_modules subdirectory aren't found, or am I overlooking something? If indeed all node_modules are ignored despite the setting, shouldn't this issue be reopened?

UPD: fixed the package.json snippet.

@mnichols
Copy link

I just hit this too. Lerna is out of the question (there are lighterweight ways too achieve monorepo) and I've not been able to work around the opinionated filtering of node_modules either.

@ivan7237d
Copy link

@mnichols I ended up having a node_modules_tests directory next to node_modules — not very good but the lesser evil.

@jsdevel
Copy link

jsdevel commented Mar 18, 2018

This really sucks. Just spent hours wondering why my tests weren't getting picked up. Used every possible combination of ignore pattern options etc.

@jorbascrumps
Copy link

Very disappointed about this. I was going to get Jest going in a legacy application that heavily uses app/node_modules when I came across this limitation.

@rickhanlonii
Copy link
Member

@Iamchristopher we're happy to review a PR that does this #1995 (comment)

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants