Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

468
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda