Joey Yi Zhao
Joey Yi Zhao

Reputation: 42520

How to configure `jest-html-reporter` in jest nodejs

I use jest to run unit tests in my nodejs project. When I run yarn test the test cases are running but the report is not generated.

"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"
  }

I also tried to put the configuration in the jest.config.js file but it doesn't work either. What else do I need to configure?

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

Upvotes: 1

Views: 6401

Answers (1)

Deepti K
Deepti K

Reputation: 599

Try adding the below snippet in package.json just above jest config:

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

Upvotes: 4

Related Questions