pamepeixinho / jest-coverage-badges

Create jest coverage badges (from all jest types)
MIT License
103 stars 177 forks source link

ENOENT: No such file coverage-summary.json #17

Open webpolis opened 4 years ago

webpolis commented 4 years ago

Hi

I set it up exactly as explained in master's README but it fails with below error. Using Jest v26.0.1:

Error: ENOENT: no such file or directory, open './coverage/coverage-summary.json'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pidman@1.1.7 test:badges: `npm run test:coverage && jest-coverage-badges`
npm ERR! Exit status 1

Thanks

babacarcissedia commented 4 years ago

I tried running npm run test:coverage && jest-coverage-badges --input ./coverage/coverage-final.json but got

Snapshots:   0 total
Time:        9.934s, estimated 14s
Ran all test suites.
/home/bcdbuddy/myfol/workspaces/github/node-paps/node_modules/jest-coverage-badges/cli.js:53
    throw new Error('malformed coverage report');
    ^

Error: malformed coverage report
    at getBadge (/home/bcdbuddy/myfol/workspaces/github/node-paps/node_modules/jest-coverage-badges/cli.js:53:11)
    at /home/bcdbuddy/myfol/workspaces/github/node-paps/node_modules/jest-coverage-badges/cli.js:81:15
    at Array.forEach (<anonymous>)
    at /home/bcdbuddy/myfol/workspaces/github/node-paps/node_modules/jest-coverage-badges/cli.js:103:14
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:61:3)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

So it seems like a version problem

vinayakshenoy91 commented 4 years ago

Hi

I set it up exactly as explained in master's README but it fails with below error. Using Jest v26.0.1:

Error: ENOENT: no such file or directory, open './coverage/coverage-summary.json'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pidman@1.1.7 test:badges: `npm run test:coverage && jest-coverage-badges`
npm ERR! Exit status 1

Thanks

There are couple of things to be added: Make sue you have the jest command added under your package json script:

   "test": "jest",
    "test:coverage": "npm test -- --coverage",
    "test:badges": "npm run test:coverage  && jest-coverage-badges 

Also make sure you have all the jest output files going into coverage folder. For that you need to added the below config in jest.config.js: coverageDirectory: "coverage"

webpolis commented 4 years ago

Thanks.

But is the same. It keeps returning the same error. Now, in a new blank project.

My jest.config:

module.exports = {
  preset: "ts-jest",
  testEnvironment: "jsdom",
  transform: {
    ".(ts|tsx)": "ts-jest",
  },
  moduleFileExtensions: ["ts", "tsx", "js", "json"],
  coverageDirectory: "coverage",
};

My package.json scripts:

    "test:badges": "npm run test:coverage  && jest-coverage-badges",
    "test:coverage": "npm test -- --coverage",

Coverage runs great, it just fail when I use this tool.

Results:

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |     100 |        0 |     100 |     100 |                   
 index.ts |     100 |        0 |     100 |     100 | 54-90             
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       10 passed, 10 total
Snapshots:   0 total
Time:        2.337 s
Ran all test suites matching /src\//i.
/home/nico/dev/projects/percyst/node_modules/jest-coverage-badges/cli.js:99
    throw err;
    ^

Error: ENOENT: no such file or directory, open './coverage/coverage-summary.json'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! percyst@0.1.0 test:badges: `npm run test:coverage  && jest-coverage-badges`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the percyst@0.1.0 test:badges script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/nico/.npm/_logs/2020-05-18T23_48_17_778Z-debug.log

Regards

gabrielsiedler commented 4 years ago

Make sure you have json-summary in the coverageReporters configuration:

"jest": {
  "coverageReporters": [
    "json-summary", 
    "text",
    "lcov"
  ]
}

this reporter is responsible for generating the coverage-summary.json file

webpolis commented 4 years ago

Thanks, but that's also there. As someone mentioned here, it's a version issue. Currently, this package is outdated in relation with its dependencies.

hollandjake commented 3 years ago

I had this issue. FIX was to ensure you dont have a jest.config.js file this will be override the package.json. Optionally you can add the configs into the jest.config.js

[Running on jest 26.6.0]

elgsantos commented 3 years ago

I had this issue on windows, for me the solution was to remove the quotes from input and output: jest --coverage && jest-coverage-badges --input coverage/coverage-summary.json --output __badges__

( "jest": "^26.6.3", "jest-coverage-badges": "^1.1.2")

ghost commented 3 years ago

For those who are still experiencing this issue, if you got a specific jest.config.js in your project, make sure to set the json value in coverageReporters option exactly as indicated by @gabrielsiedler on his example, so:

coverageReporters: [
    "json-summary", <- Not "json" but "json-summary": this is important!
    "text",
    "lcov",
    "clover"
  ]
RicardoGomesRocha commented 3 years ago

@hollandjake and @elgsantos (here and here).

So, @pamepeixinho I think this issue can be closed.

ciriousjoker commented 2 years ago

Can be closed imo.

Basically, copy coverageReporter from package.json into jest.config.js:

/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  // here:
  coverageReporters: ["json-summary", "text", "lcov"],
};
jrichardsz commented 1 year ago

Make sure you have json-summary in the coverageReporters configuration:

"jest": {
  "coverageReporters": [
    "json-summary", 
    "text",
    "lcov"
  ]
}

this reporter is responsible for generating the coverage-summary.json file

Worked for me, thanks!!

"jest": "^27.3.1",
"jest-badge-generator": "^1.1.5"
francoatmega commented 8 months ago

For me worked when I add some files an directories to ingore, remember to check this too. Worked when I fixed the paths to ignore like this:

coveragePathIgnorePatterns: ['/node_modules/', 'src/infra/db/*']