Skip to content

Watch mode filename/test name filtering is not taken into account for coverage calculation with collectCoverageFrom set #7101

Closed
@duszans

Description

@duszans

🐛 Bug Report

When collectCoverageFrom is set, then in watch mode with filtering by filename or test name
turned on the filename/test name filtering isn't taken into account for coverage calculation.

The easiest solution seems to be that when in watch mode test filtering is turned on, then collectCoverageFrom should be ignored.

Thanks to that coverage could be calculated for all required files when running all tests, and when filtering the test it would be obvious that coverage is calculated only for these tests and what they import. Coverage info in watch mode with tests filter is useful, as when working on some tests it can be easily seen if we have certain coverage for the code we work on or not.

To Reproduce

jest --watch --coverage --collectCoverageFrom='src/**/*.js'

Detailed steps:

  1. Clone https://github.com/duszans/jest-watch-collectCoverageFrom-filtering-repro
  2. yarn (or use npm)
  3. yarn test:watch:withCoverageFrom
  4. press p in the menu
  5. type add-test as a pattern
  6. The coverage is calculated for all files based on collectCoverageFrom and filter pattern isn't taken into account

Expected behavior

In watch mode with collectCoverageFrom set the filename/test name filtering is taken into account for coverage calculation.

Link to repl or repo (highly encouraged)

https://github.com/duszans/jest-watch-collectCoverageFrom-filtering-repro

Run npx envinfo --preset jest

Paste the results here:

npx: installed 1 in 4.077s

  System:
    OS: Linux 4.4 Ubuntu 16.04.3 LTS (Xenial Xerus)
    CPU: x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  Binaries:
    Node: 8.9.4 - ~/.nvm/versions/node/v8.9.4/bin/node
    Yarn: 1.9.4 - ~/.yarn/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.9.4/bin/npm
  npmPackages:
    @types/jest: ^23.3.3 => 23.3.3
    jest: ^23.6.0 => 23.6.0

Screenshoots

With collectCoverageFrom

with collectcoveragefrom

Without collectCoverageFrom

without collectcoveragefrom

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions