My LWC test is not displaying code coverage

I have configured jest for Lightning web component test. My tests are running and passing but code coverage not displaying into output. Following is package.json file: –

    {
      "name": "my-project",
      "version": "1.0.0",
      "description": "Some description",
      "main": "index.js",
      "scripts": {
        "test:unit": "lwc-jest --coverage",
        "test:unit:watch": "lwc-jest --watch",
        "test:unit:debug": "lwc-jest --debug"
      },
      "repository": {
        "type": "git",
        "url": "some url here"
      },
      "author": "",
      "license": "ISC",
      "homepage": "read me file link",
      "devDependencies": {
        "@salesforce/lwc-jest": "^0.5.1"
      },
      "jest" : {
        "collectCoverage" : true,
        "collectCoverageFrom" :[
          "**/*.test.js"
        ]
      }
    }

I used npm run test:unit command to run test. and following is my output:

enter image description here

Please suggest me where I am doing wrong. Thanks in advance.

Answer

I was able to resolve a similar problem by setting coverageProvider to “v8” in jest.config.js, like this:

const { jestConfig } = require('@salesforce/sfdx-lwc-jest/config');
module.exports = {
    ...jestConfig,
    // add any custom configurations here
    coverageProvider: "v8"
};

Attribution
Source : Link , Question Author : Sushant Srivastava , Answer Author : Curtis Porter

Leave a Comment