最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jestjs - jest-junit only works as a testResultsProcessor, not a reporter - Stack Overflow

programmeradmin1浏览0评论

The main documented way to use jest-junit in CI is

jest --ci --reporters=default --reporters=jest-junit

The Jest documentation adds double quotes:

jest --reporters="default" --reporters="jest-junit"

However, in either case I get this error:

nps is executing `test.ci` : jest --ci --reporters=default --reporters=jest-junit **/*.test.[jt]s
Error: Could not resolve a module for a custom reporter.
  Module name: tests/fail.test.ts
    at <project_root>/node_modules/jest-config/build/normalize.js:426:15
    at Array.map (<anonymous>)
    at normalizeReporters (<project_root>/node_modules/jest-config/build/normalize.js:409:20)
    at <project_root>/node_modules/jest-config/build/normalize.js:747:17
    at Array.reduce (<anonymous>)
    at normalize (<project_root>/node_modules/jest-config/build/normalize.js:608:14)
    at readConfig (<project_root>/node_modules/jest-config/build/index.js:160:74)
    at async readConfigs (<project_root>/node_modules/jest-config/build/index.js:424:26)
    at async runCLI (<project_root>/node_modules/@jest/core/build/cli/index.js:151:59)
    at async Object.run (<project_root>/node_modules/jest-cli/build/run.js:130:37)

It seems to be here in the jest-config source.

The deprecated

jest --ci --testResultsProcessor=jest-junit

does work, but I'd prefer to avoid it given

The support for testResultsProcessor is only kept for legacy reasons and might be removed in the future. You should therefore prefer to configure jest-junit as a reporter.

What can be the problem with the reporter usage?

Jest version is 29.7.0, and I've checked that there's no mismatch between jest-config, jest-cli, and jest. jest-junit is 16.0.0.

In package.json I have:

  "jest": {
    "clearMocks": true,
    "collectCoverageFrom": [
      "tests/**/*.{js,jsx,ts,tsx}"
    ],
    "coverageReporters": [
      "lcov"
    ],
    "resetModules": true,
    "resetMocks": true,
    "setupFiles": [
      "./tests/helper.ts"
    ],
    "testEnvironment": "node",
    "transform": {
      "^.+\\.[jt]sx?$": "babel-jest"
    }
  },

There's no jest.config.* file.

The main documented way to use jest-junit in CI is

jest --ci --reporters=default --reporters=jest-junit

The Jest documentation adds double quotes:

jest --reporters="default" --reporters="jest-junit"

However, in either case I get this error:

nps is executing `test.ci` : jest --ci --reporters=default --reporters=jest-junit **/*.test.[jt]s
Error: Could not resolve a module for a custom reporter.
  Module name: tests/fail.test.ts
    at <project_root>/node_modules/jest-config/build/normalize.js:426:15
    at Array.map (<anonymous>)
    at normalizeReporters (<project_root>/node_modules/jest-config/build/normalize.js:409:20)
    at <project_root>/node_modules/jest-config/build/normalize.js:747:17
    at Array.reduce (<anonymous>)
    at normalize (<project_root>/node_modules/jest-config/build/normalize.js:608:14)
    at readConfig (<project_root>/node_modules/jest-config/build/index.js:160:74)
    at async readConfigs (<project_root>/node_modules/jest-config/build/index.js:424:26)
    at async runCLI (<project_root>/node_modules/@jest/core/build/cli/index.js:151:59)
    at async Object.run (<project_root>/node_modules/jest-cli/build/run.js:130:37)

It seems to be here in the jest-config source.

The deprecated

jest --ci --testResultsProcessor=jest-junit

does work, but I'd prefer to avoid it given

The support for testResultsProcessor is only kept for legacy reasons and might be removed in the future. You should therefore prefer to configure jest-junit as a reporter.

What can be the problem with the reporter usage?

Jest version is 29.7.0, and I've checked that there's no mismatch between jest-config, jest-cli, and jest. jest-junit is 16.0.0.

In package.json I have:

  "jest": {
    "clearMocks": true,
    "collectCoverageFrom": [
      "tests/**/*.{js,jsx,ts,tsx}"
    ],
    "coverageReporters": [
      "lcov"
    ],
    "resetModules": true,
    "resetMocks": true,
    "setupFiles": [
      "./tests/helper.ts"
    ],
    "testEnvironment": "node",
    "transform": {
      "^.+\\.[jt]sx?$": "babel-jest"
    }
  },

There's no jest.config.* file.

Share Improve this question asked Jan 20 at 11:26 Alexey RomanovAlexey Romanov 171k37 gold badges324 silver badges505 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

The answer was just that without reporters,

jest --ci **/*.test.[jt]s

works fine. With them, I needed -- to separate the test file glob:

jest --ci --reporters=default --reporters=jest-junit -- **/*.test.[jt]s
发布评论

评论列表(0)

  1. 暂无评论