Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

465
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda