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.

Generating report error - cannot convert undefined or null to object

See original GitHub issue

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 use ArtiomTr/jest-coverage-report-action for the annotations.

     - name: Jest coverage report
        uses: ArtiomTr/jest-coverage-report-action@v2.0.4
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          coverage-file: ./temp-coverage-results/current/jest.results.json
          base-coverage-file: ./temp-coverage-results/target/jest.results.json
          threshold: 80
          skip-step: all
          annotations: failed-tests

With v2.0.4 it keeps failing with TypeError: Cannot convert undefined or null to object and I am not sure how to debug it.

CleanShot 2022-03-04 at 13 46 25


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?! @ArtiomTr

_Originally posted by @raspo in https://github.com/ArtiomTr/jest-coverage-report-action/issues/242#issuecomment-1059559731_

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
nowyDEVcommented, Sep 28, 2022

This simple script does the job

./scripts/save-coverage-file.js

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);
});

package.json

{
  "scripts": {
    "test:coverage": "vitest run --coverage",
    "test:coverage:ci": "npm run test:coverage -- --outputFile ./coverage/report.json && ./scripts/save-test-coverage.js",
  }
}
1reaction
raspocommented, Apr 13, 2022

Makes sense 👌 Personally, I got confused by the name of the two properties: base-coverage-file and coverage-file, thinking that just providing the coverage file should be ok. We may wanna rename them to something that conveys the idea that this is the full json test report file (like base-json-test-report or base-json-output-file) … although it’s probably not a good idea as it will require a breaking change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot convert undefined or null to object - Stack Overflow
This error is caused when you call a function that expects an Object as its argument, but pass undefined or null instead, like...
Read more >
Object.keys(null) possible - cannot convert undefined or ...
@nhtbao101 I'm pretty sure it's completely unrelated - this issue is about some server code, and you see an error in the browser....
Read more >
Cannot convert undefined or null to object
Hello, I have a vacation flow created some times ago; in the last iteration I added an update action where I update a...
Read more >
cannot convert undefined or null to object(inline editing ...
We checked your reported query based on your provided sample and you are getting the console error “Cannot convert undefined or null to...
Read more >
Cannot convert undefined or null to object : r/learnjavascript
Your code throws the error because before fetch completes, location is undefined, but you are telling react to iterate over it, which can't...
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