Open webpolis opened 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
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"
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
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
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.
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]
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")
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"
]
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"],
};
Make sure you have
json-summary
in thecoverageReporters
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"
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/*']
Hi
I set it up exactly as explained in master's README but it fails with below error. Using Jest v26.0.1:
Thanks