Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

464
Views
How to force unit tests coverage for a specific folder in Jest

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!