-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generating report error - cannot convert undefined or null to object #244
Comments
Related: #242 (comment)
|
This appears to be fixed with the latest version |
@coelhucas what's your config? were you using version 2.0.5? |
I have also started to see this error on another repo I have been working on.
@ArtiomTr I'd be happy to help debug this, is there a branch or version of this action I can use that can help understand where exactly it is breaking? ideally one that isn't minimized? I think we should re-open this issue, btw. |
Update: The type error I posted above seem to occur here:
jsonReport.coverageMap resulting in undefined )
There are two ways to generate a JSON code coverage report with Jest:
With option Me and @lockettks were clearly using What do you suggest we should do @ArtiomTr ? I could very easily add a silly check like: Should the action trigger an error when the format of the json report is not what it expects? |
Hello @raspo 👋, Flags, which are required for generating report are jest-coverage-report-action/src/utils/getTestCommand.ts Lines 23 to 31 in c33e891
As for the issue, yes, I think the action should throw errors when the report format doesn't match since the action will lose a lot of functionality if the rest of the fields are missing. About the debugging, I will create a separate issue on this. Action should generate source maps, to make errors more readable. |
Makes sense 👌 |
Yes, you're right, renaming options will require a breaking change, but I understand your indignation at the incomprehensibility of the option name. I will consider renaming it. |
I've been using this tool with jest reports but I'm converting to vitest. But I can't manage to get a json from vitest that contains the |
Hello @Crafoord 👋, I'm not familiar with |
This simple script does the job
const fs = require("fs");
/*
don't forget to update `coverage-file` input inside workflow when specifying path here
`test.yml`
with:
coverage-file: ./coverage/report.json
*/
const testReportFilename = process.cwd() + "/coverage/report.json";
const coverageReportFilename = process.cwd() + "/coverage/coverage-final.json";
const testReport = require(testReportFilename);
const coverageReport = require(coverageReportFilename);
testReport.coverageMap = coverageReport;
fs.writeFile(testReportFilename, JSON.stringify(testReport), (err) => {
if (err) {
console.error(err);
process.exit(1);
}
console.log("Coverage report appended to " + testReportFilename);
});
{
"scripts": {
"test:coverage": "vitest run --coverage",
"test:coverage:ci": "npm run test:coverage -- --outputFile ./coverage/report.json && ./scripts/save-test-coverage.js",
}
} |
I used a very similar solution to #244 (comment). It's pretty much same solution but a bit more verbose and I actually had to add
#!/usr/bin/env node
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fs = require('fs');
const reportFilename = 'report.json';
const coverageFinalFilename = 'coverage-final.json';
const cwd = process.cwd();
const reportJsonFilepath = `${cwd}/coverage/${reportFilename}`;
const coverageFinalFilepath = `${cwd}/coverage/${coverageFinalFilename}`;
let reportJsonFile;
let coverageFinalJsonFile;
if (fs.existsSync(reportJsonFilepath)) {
reportJsonFile = require(reportJsonFilepath);
}
if (fs.existsSync(coverageFinalFilepath)) {
coverageFinalJsonFile = require(coverageFinalFilepath);
}
console.log('Files exists?', { reportFilename: !!reportJsonFile, coverageFinalFilename: !!coverageFinalJsonFile });
if (reportJsonFile && coverageFinalJsonFile) {
if (!reportJsonFile.coverageMap) {
console.log(`Adding coverageMap property to ${reportFilename} based on ${coverageFinalFilename}`);
reportJsonFile.coverageMap = coverageFinalJsonFile;
fs.writeFileSync(reportJsonFilepath, JSON.stringify(reportJsonFile), (err) => {
if (err) {
console.error(err);
process.exit(1);
}
});
} else {
console.log(`coverageMap already exists in ${reportFilename}, not doing anything...`);
process.exit(0);
}
} else {
console.log('Not doing anything...');
process.exit(0);
}
"scripts": {
"test:coverage": "vitest run --coverage",
"test:coverage:ci": "vitest run --coverage --reporter=json --outputFile ./coverage/report.json && ./ci/save-coverage-file.js",
}, |
I am also having issues with the latest
v2.0.4
and I have a similar setup where I run jest and collect coverage in separate steps and then useArtiomTr/jest-coverage-report-action
for the annotations.With
v2.0.4
it keeps failing withTypeError: Cannot convert undefined or null to object
and I am not sure how to debug it.Out of curiosity I tried to use
ArtiomTr/jest-coverage-report-action@Debug-action
instead (mentioned in another conversation) and with that particular version it works perfectly every time: branch in not switching, reports are being collected, annotation with coverage diffs is generated, etc..I did some research but wasn't able to figure out where the
Debug-action
version comes from... is it based on an older version?! @ArtiomTrOriginally posted by @raspo in #242 (comment)
The text was updated successfully, but these errors were encountered: