jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.03k stars 6.43k forks source link

Jest not ignoring some patterns in collectCoverageFrom #8770

Closed deviprsd closed 1 year ago

deviprsd commented 5 years ago

🐛 Bug Report

Jest coverage didn't ignore some of !**/node_modules/** as mentioned in collectCoverageFrom Screenshot from 2019-08-01 02-07-11

To Reproduce

I'm using svelte with @testing-library/svelte. I'm not sure I can explain how to reproduce it.

Expected behavior

Should ignore the files in console in the screenshot, src/elements/node_modules/svelte/internal

Link to repl or repo (highly encouraged)

https://github.com/titans-inc/sveltemantic

Run npx envinfo --preset jest

System:
    OS: Linux 4.18 Ubuntu 18.04.2 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
  Binaries:
    Node: 10.16.0 - /usr/bin/node
    Yarn: 1.17.3 - /usr/bin/yarn
    npm: 6.10.2 - /usr/bin/npm
  npmPackages:
    jest: ^24.8.0 => 24.8.0 
jeysal commented 5 years ago

It might be because the src/** which comes later matches - have you tried configuring coveragePathIgnorePatterns

deviprsd commented 5 years ago

Yes, tried a regex but didn't work. I tried moving src moving up but that had no effect either.

I have disabled collectCoverageFrom for now, but when I had it enabled even though it was generating some coverage, codacy was always reporting 0%, which is weird.

Mark1626 commented 5 years ago

@deviprsd It look like it's because of the jest-transform-svelte transformer.

A look into the cache and I found inside the source-map. "sources":["node_modules/svelte/internal/index.mjs","src/lib/exclude.js","src/elements/step/Description.svelte"]

The transform is applied here

https://github.com/facebook/jest/blob/16f7385a115658687308bcb5119d7aec12efbe14/packages/jest-reporters/src/generateEmptyCoverage.ts#L34-L37

after matching collectCoverageFrom

https://github.com/facebook/jest/blob/16f7385a115658687308bcb5119d7aec12efbe14/packages/jest-reporters/src/coverage_reporter.ts#L125-L130

hence the generated node_modules/svelte/internal/index.mjs is sent to the coverage report

@jeysal Can you confirm this?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.