如何在jest节点js中配置'jest-html-reporter'

yv5phkfx  于 2022-12-28  发布在  Jest
关注(0)|答案(1)|浏览(191)

我使用jest在我的nodejs项目中运行单元测试,当我运行yarn test时,测试用例正在运行,但是没有生成报告。

"scripts": {
    "test": "yarn run test:dev tests",
    "test:dev": "jest --config jest.config.js"
  },
  "dependencies": {
    "jest": "^22.4.4",
    "lodash": "^4.17.10",
    "mongodb": "^3.1.0-beta4",
    "test-utils": "^1.1.1"
  },
  "devDependencies": {
    "jest-html-reporter": "^2.3.0"
  },
  "jest": {
    "testResultsProcessor": "./node_modules/jest-html-reporter",
    "pageTitle": "Test Report",
    "outputPath": "./test-report.html"
  }

我也试着把配置放在jest.config.js文件中,但也不起作用。我还需要配置什么?

module.exports = {
  "globalSetup": "<rootDir>/src/globalSetup.js",
  "globalTeardown": "<rootDir>/src/globalTeardown.js",
  "testResultsProcessor": "./node_modules/jest-html-reporter"
}
5kgi1eie

5kgi1eie1#

尝试在package.jsonjest配置的上方添加以下代码片段:

{
  // ...
  "jest-html-reporter": {
    "pageTitle": "Unit Tests",
    "outputPath": "./test-report.html",
    "includeFailureMsg": true
  }
}

相关问题