Home

collectCoverageFrom

collectCoverageFrom is a configuration option used by JavaScript testing tools such as Jest to determine which source files should be included when generating test coverage reports. It defines the set of files from which code coverage data will be collected, allowing developers to focus on relevant parts of the codebase.

The option accepts an array of glob patterns. Patterns can include wildcards and can be negated with

collectCoverageFrom works in tandem with collectCoverage and coverage-related settings such as coverageDirectory and coverageReporters. When collectCoverage

Typical use cases include focusing coverage on publishable source code in a library, or excluding configuration

a
leading
exclamation
mark
to
exclude
files.
Patterns
are
evaluated
relative
to
the
project
root.
Common
usage
includes
including
all
source
files
while
excluding
tests,
mocks,
or
build
artifacts,
for
example:
["src/**/*.{js,ts,jsx,tsx}",
"!src/**/*.test.{ts,tsx}",
"!src/**/__tests__/**"].
is
enabled,
only
files
matched
by
collectCoverageFrom
contribute
to
the
reported
coverage.
If
a
file
is
not
matched,
or
is
explicitly
excluded,
it
will
not
appear
in
coverage
results.
To
further
refine
results,
you
can
also
use
coveragePathIgnorePatterns
to
hide
specific
paths
from
coverage
reporting
entirely.
and
utility
files
from
coverage
statistics.
Care
should
be
taken
to
ensure
patterns
accurately
reflect
desired
files
to
avoid
misleading
coverage
metrics.