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.

collectCoverageFrom didn't work in react components

See original GitHub issue

🐛 Bug Report

when i set jest config in package.json like this

"jest": {
        "verbose": true,
        "collectCoverage": true,
        "globals": {},
        "testEnvironment": "jest-environment-jsdom-global",
        "moduleFileExtensions": [
            "js",
            "jsx",
            "json"
        ],
        "moduleNameMapper": {
            "^@/(.*)$": "<rootDir>/src/$1",
            "\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
        },
        "transform": {
            "^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
            "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileTransformer.js"
        },
        "transformIgnorePatterns": [
            "<rootDir>/node_modules/"
        ],
        "setupFiles": [
            "jest-canvas-mock"
        ],
        "testMatch": [
            "<rootDir>/**/*.(test|spec).js"
        ],
        "coverageDirectory": "<rootDir>/test/unit/coverage",
        "collectCoverageFrom": [
            "<rootDir>/**/util.js"
        ],
        "coveragePathIgnorePatterns": [
            "<rootDir>/node_modules/",
            "<rootDir>/test",
            "<rootDir>/tasks",
            "<rootDir>/config"
        ]
    },

when i run yarn run jest, i get this

To Reproduce

屏幕快照 2019-09-25 下午7 15 29

Expected behavior

is should only collect util.js , but it collect react components, i set react components test

it('renders correctly', () => {
        expect(toJson(wrapper)).toMatchSnapshot();
    });

is this impact collectCoverageFrom

Link to repl or repo (highly encouraged)

sorry,i can’t provided it

envinfo

System:
    OS: macOS High Sierra 10.13.4
    CPU: x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
  Binaries:
    Node: 10.15.3
    Yarn: 1.16.0
    npm: 6.4.1
  npmPackages:
    jest:
      wanted: ^23.2.0
      installed: 23.6.0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
z2014commented, Sep 26, 2019

i have update jest 24.9.0 version, it also has this problem.

the problem is collectCoverageFrom didn’t work. i set jest config collectCoverageFrom: ['<rootDir>/**/util.js'] so i want to collect Coverage the files named ‘util.js’ , but it collect all the files

0reactions
stoplioncommented, Aug 5, 2022

collectCoverageFrom still doesn’t collect coverage for React components? I’m trying it with "src/**/*.{ts,tsx}" and it indeed doesn’t cover React components. 🤷🏻‍♂️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest collectCoverageFrom and coverageThreshold not working
This means when I run npm t jest must show me error about global coverage does not 100%. But I don't see any...
Read more >
Jest collectCoverageFrom and coverageThreshold not ...
Coding example for the question Jest collectCoverageFrom and coverageThreshold not working-Reactjs.
Read more >
Configuring Jest
collectCoverageFrom [array]​. Default: undefined. An array of glob patterns indicating a set of files for which coverage information should be collected. If a ......
Read more >
React unit test and code coverage with Jest and Istanbul
Configuring Jest to run React Tests ... Step 2: Bring in npm dependencies: ... Step 4: Write your component: // File location: app/components/App.js...
Read more >
Configuring Code Coverage for TypeScript Files in Jest
In this lesson I demonstrate using the collectCoverageFrom ... a Utility File for Rendering Redux Connected React Components in Tests.
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