jest icon indicating copy to clipboard operation
jest copied to clipboard

collectCoverageFrom didn't work in react components

Open z2014 opened this issue 5 years ago • 7 comments

🐛 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

z2014 avatar Sep 25 '19 11:09 z2014

Can you try on the latest version of Jest? Also please try to form the issue a bit clearer, because I have troubles understanding :<

thymikee avatar Sep 25 '19 11:09 thymikee

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

z2014 avatar Sep 26 '19 08:09 z2014

I have the same issue, have you found a solution?

vcheeney avatar Feb 11 '20 15:02 vcheeney

@vcheeney not yet

z2014 avatar Feb 12 '20 12:02 z2014

@z2014 - I guess your regex is not working correctly not sure with your code. but I am able to ignore files using below code .

collectCoverageFrom: ['<rootDir>/src//*.{js,jsx,ts,tsx}', '!<rootDir>/src//*css.ts'],

try add in collectCoverageFrom: ['<rootDir>/src/**/*util.js'],

SunilSalve avatar Mar 25 '20 13:03 SunilSalve

@SunilSalve ['/src//*.{js,jsx,ts,tsx}', '!/src//*css.ts'] is css.ts right ? can you provide a complete code, thanks

z2014 avatar Mar 25 '20 13:03 z2014

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. 🤷🏻‍♂️

stoplion avatar Aug 05 '22 21:08 stoplion

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] avatar Aug 05 '23 21:08 github-actions[bot]

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] avatar Sep 04 '23 21:09 github-actions[bot]

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.

github-actions[bot] avatar Oct 05 '23 00:10 github-actions[bot]