jestjs / jest

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

Use specified istabul-reports reporter got module not found #11145

Closed zslucky closed 1 year ago

zslucky commented 3 years ago

🐛 Bug Report

const jest = require('@jest/core');
jest
  .runCLI(
    {
      config: JSON.stringify(config),
      passWithNoTests: true,
      reporters: ['cobertura'], 
    },
    [pkgRoot],
  )
ModuleNotFoundError: Could not resolve a module for a custom reporter.
  Module name: cobertura
    at /Users/lucky/Workspace/bybit-brain/node_modules/jest-config/build/normalize.js:561:15
    at Array.map (<anonymous>)
    at normalizeReporters (/Users/lucky/Workspace/bybit-brain/node_modules/jest-config/build/normalize.js:540:33)
    at normalize (/Users/lucky/Workspace/bybit-brain/node_modules/jest-config/build/normalize.js:636:5)
    at readConfig (/Users/lucky/Workspace/bybit-brain/node_modules/jest-config/build/index.js:224:68)
    at readConfigs (/Users/lucky/Workspace/bybit-brain/node_modules/jest-config/build/index.js:406:32)
    at Object.runCLI (/Users/lucky/Workspace/bybit-brain/node_modules/@jest/core/build/cli/index.js:231:29)
    at Object.<anonymous> (/Users/lucky/Workspace/bybit-brain/tool-chain/by-bundler/bin/test.js:17:4)
    at Module._compile (internal/modules/cjs/loader.js:1015:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10) {
  code: 'MODULE_NOT_FOUND',
  hint: undefined,
  requireStack: undefined,
  siblingWithSimilarExtensionFound: undefined,
  moduleName: undefined,

I'm not sure, looks like the normalizeReporters function in normalize.js doesn't get the correct path from package istanbul-reports, it only treat reporter as normal package.

if (reporterPath !== DEFAULT_REPORTER_LABEL) {
      const reporter = Resolver.findNodeModule(reporterPath, {
        basedir: options.rootDir,
      });
      if (!reporter) {
        throw new Resolver.ModuleNotFoundError(
          `Could not resolve a module for a custom reporter.\n` +
            `  Module name: ${reporterPath}`,
        );
      }
      normalizedReporterConfig[0] = reporter;
    }

To Reproduce

Just use the above code.

Expected behavior

istanbul-reports reporter can work correctly.

Link to repl or repo (highly encouraged)

Just use the above code.

envinfo

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
  Binaries:
    Node: 12.19.1 - ~/.nvm/versions/node/v12.19.1/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.19.1/bin/npm
"@jest/core": "^26.6.3"
github-actions[bot] commented 1 year 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 30 days.

github-actions[bot] commented 1 year ago

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

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