I'm trying to create a task that runs code coverage for a specific folder in my project (test-coverage-sub-folder). I already have it set for the entire project (test-coverage).
In my package.json I've added these two tasks:
{
"test-coverage": "jest unitTests/ --collectCoverage=true --coverage --collectCoverageFrom=./mainFolder/ui/**/*.js --coverageReporters=text-summary",
"test-coverage-sub-folder": "jest unitTests/subFolder/ --collectCoverage=true --coverage --collectCoverageFrom=./mainFolder/ui/**/*.js --coverageReporters=text-summary --config subFolder.jest.config.js",
}
subFolder.jest.config.js
module.exports = {
verbose: true,
testRegex: "(/jestTests/.*|(\\.|/)(test|spec))\\.js?$",
moduleFileExtensions: [ "js", "jsx", "json", "node", "ts", "tsx", ],
modulePathIgnorePatterns: [
"unitTests/helpers/"
],
setupFiles: [
"<rootDir>/unitTests/helpers/mock.js"
],
testEnvironment: "jsdom",
coverageDirectory: "./../../../jest-coverage",
collectCoverage: false,
forceCoverageMatch: ["unitTests/subFolder/**/*.js"],
coverageThreshold: {
global: {
statements: 80,
branches: 80,
functions: 80,
lines: 80
}
}
};
I tried using forceCoverageMatch but it didn't work unless I'm not using it right? When I run the task it works, it runs only the tests from the subFolder but it calculates coverage based on all files in the project and I want it to calculate coverage only based on the files from subFolder.