jestjs / jest

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

Jest crashes by running tests located in the /node_modules folder #8674

Closed yzevm closed 2 years ago

yzevm commented 5 years ago

Hi, thanks for amazing testing tool :+1:

🐛 Bug Report

I have a microservice and sdk for it, I would like to reuse tests in sdk for e2e tests in microservice (mocks will be removed).

Running npm run test:e2e I expect to launch server (in rootDir/dist) and start running tests (rootDir/node_modules/sdk/*)

Error message

 FAIL  node_modules/sdk/req.test.ts
  ● Test suite failed to run

    The name `source-map` was looked up in the Haste module map. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform. The platform is generic (no extension). You must delete or blacklist files until there remains only one of these:

      * `/home/egor/Desktop/github/forks/typeorm-mock-unit-testing-example/node_modules/@babel/core/node_modules/source-map/package.json` (package)
      * `/home/egor/Desktop/github/forks/typeorm-mock-unit-testing-example/node_modules/@babel/generator/node_modules/source-map/package.json` (package)
      * `/home/egor/Desktop/github/forks/typeorm-mock-unit-testing-example/node_modules/snapdragon/node_modules/source-map/package.json` (package)
      * `/home/egor/Desktop/github/forks/typeorm-mock-unit-testing-example/node_modules/source-map/package.json` (package)

      at ModuleMap._assertNoDuplicates (node_modules/jest-haste-map/build/ModuleMap.js:280:11)

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

package.json script

"test:e2e": "rimraf build && tsc && jest -c jest.e2e.config.js --forceExit --detectOpenHandles",

jest.config.js

module.exports = {
  verbose: true,
  rootDir: '.',
  preset: 'ts-jest',
  globalSetup: './build/test/e2e/callSetup.js',
  testMatch: ['<rootDir>/node_modules/sdk/req.test.ts'],
  moduleFileExtensions: [
    'ts',
    'js',
    'json'
  ],
  testEnvironment: 'node',
  haste: {
    providesModuleNodeModules: ['.*']
  },
  testPathIgnorePatterns: [],
}

Reproduce

Repo to reproduce

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i5-6400 CPU @ 2.70GHz
  Binaries:
    Node: 11.5.0 - ~/.nvm/versions/node/v11.5.0/bin/node
    Yarn: 1.16.0 - ~/.nvm/versions/node/v11.5.0/bin/yarn
    npm: 6.9.0 - ~/.nvm/versions/node/v11.5.0/bin/npm
  npmPackages:
    jest: 24.8.0 => 24.8.0 
github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 14 days.

github-actions[bot] commented 2 years ago

This issue was closed because it has been stalled for 7 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] commented 2 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.