question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug with babel-jest when coverage mode is on

See original GitHub issue

šŸ› Bug Report

Jest returns an error when babel ignore some directory and --coverage mode is enabled:

babel-jest: Babel ignores server/init/index.js - make sure to include the file in Jest’s transformIgnorePatterns as well.

Adding this directory in transformIgnorePatterns - do not help. When we disable coverage all is working properly.

To Reproduce

Steps to reproduce the behavior: OS: Windows 10 babel-jest: 24.7.1 jest: 24.6.0

.babelrc { ... "only": [ "client/", "test/" ] ... }

jest-config.js { ... "transform": { "^.+\\.jsx?$": "babel-jest" }, "transformIgnorePatterns": [ "/server/", "/node_modules/" ], ... }

command jest test/ --coverage --verbose

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:5

github_iconTop GitHub Comments

4reactions
shanedgcommented, Jan 26, 2020

Using coveragePathIgnorePatterns isn’t an option if you want the coverage report to include all tests, not just those that were transformed.

There’s some kind of conflict between transform and transformIgnorePatterns when coverage is used. @ni1son, the pattern "^.+\\.jsx?$" is very permissive and matches all js/x files it finds. I would expect that adding directories to transformIgnorePatterns like you have would be sufficient. It actually seems to work fine without the coverage flag, but I ran into the same problem when I wanted to use coverage.

Workaround I found is to use a more specific pattern in transform so that I don’t need to use transformIgnorePatterns at all:

config/jest.config.js

rootDir: '..',
roots: [
  '<rootDir>/config',
  '<rootDir>/scripts',
  '<rootDir>/src',
],
transform: {
  // Only transform files in src/!
  // Only this directory is built/transpiled by Babel.
  '\\/src\\/.+\\.[t|j]sx?$': '<rootDir>/config/babelJest.js',
}

config/babel.config.js

only: [
  '../src',
]

You can ignore most of the details, the relevant part is the specification of \\/src\\/ in '\\/src\\/.+\\.[t|j]sx?$', since that’s the only directory I actually want transformed. The files and tests in config/ and in scripts/ are just run straight by Node.

4reactions
spktklrcommented, Sep 12, 2019

Try adding coveragePathIgnorePatterns.

source: https://github.com/facebook/jest/blob/master/docs/Configuration.md

Read more comments on GitHub >

github_iconTop Results From Across the Web

No code coverage in Babel Jest - Stack Overflow
Finally got answer. It was a bug in Babel. See how to fix this issue there : https://github.com/facebook/jest/issues/632.
Read more >
babel ignores - make sure to include the file in jest's ... - You.com
Bug Report. Jest returns an error when babel ignore some directory and --coverage mode is enabled: babel-jest: Babel ignores server/init/index.js - makeĀ ...
Read more >
babel-jest | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
CodeCoverage/Firefly - MozillaWiki
Coverage Data - Identify coverage gaps; Bugs Data - Identify the number ... fixed in the file to its coverage numbers in various...
Read more >
flow-coverage-report - npm Package Health Analysis - Snyk
Learn more about flow-coverage-report: package health score, popularity, ... new --strict-coverage option to enforce a more strict coverage reporting mode.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found