I’m using
"jest": "^29.5.0",
"jest-fetch-mock": "^3.0.3",
"jest-sonar-reporter": "^2.0.0",
Following is my jest.config.js:
module.exports = {
automock: false,
clearMocks: true,
collectCoverage: true,
coverageDirectory: "<rootDir>/Test/Reports",
coveragePathIgnorePatterns: ["/node_modules/", "/Test/Unit/"],
coverageReporters: ["text", ["lcovonly", { projectRoot: "." }]],
testEnvironment: "node",
testResultsProcessor: "<rootDir>/Test/node_modules/jest-sonar-reporter",
testEnvironmentOptions: {
browsers: ["chrome", "firefox", "safari"],
url: "http://localhost",
},
moduleNameMapper: {
"\.(css|less|sass|scss)$": "<rootDir>/Test/__mocks__/styleMock.js",
"\.(gif|ttf|eot|png|svg)$": "<rootDir>/Test/__mocks__/fileMock.js",
"^react$": "<rootDir>/Test/node_modules/react",
"^react-dom$": "<rootDir>/Test/node_modules/react-dom",
},
rootDir: "../",
roots: ["<rootDir>"],
setupFiles: ["<rootDir>/Test/node_modules/mock-local-storage"],
setupFilesAfterEnv: [
"<rootDir>/Test/Unit/setupJest.js",
"<rootDir>/Test/node_modules/mock-local-storage",
],
transform: {
"^.+\.(js|jsx|mjs)$": "<rootDir>/Test/jest-transformer.js",
},
verbose: true,
watchman: true,
};
The coverage summary table and lcov.info file generated shows that new lines, comment lines, initialized variables, destructured props and non-existing lines are uncovered (example: file with 500 total lines, report says line 700-800 is uncovered).