phenomnomnominal / betterer

betterer makes it easier to make incremental improvements to your codebase
MIT License
579 stars 38 forks source link

coverage() function does not work #1157

Open piotrwalczak1 opened 1 year ago

piotrwalczak1 commented 1 year ago

Describe the bug In spite of the fact that coverage file report is created using jest configuration, when running test for coverage from the docs it says:

Could not read coverage summary at readCoverageSummary
...
 at async BettererWorkerRunΩ.run

To Reproduce betterer.ts

import { coverage } from "@betterer/coverage";

export default {
  "increase per-file test coverage": () => coverage(),
};

Expected behavior Test should execute without errors

*Screenshots** If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

Additional context jest config:

module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  testMatch: ["**/**/*test*.ts"],
  testPathIgnorePatterns: ["/node_modules/", "/coverage"],
  moduleFileExtensions: ["ts", "tsx", "js", "json"],
  verbose: true,
  transform: {
    "^.+\\.tsx?$": "ts-jest",
  },
  collectCoverage: true,
  collectCoverageFrom: ["**/lib/**/*.ts"],
  coveragePathIgnorePatterns: [
    "/node_modules/",
    "\\.d\\.ts$", // Ignore .d.ts files
  ],
};
phenomnomnominal commented 2 weeks ago

Very sorry for not getting back to this, but on the off change you see it, just want to check:

1) Have you set the Jest coverageDirectory for the output? 2) Have you tried passing the actual output directory to the coverage test?

import { coverage } from "@betterer/coverage";

export default {
  "increase per-file test coverage": () => coverage('./my-reports-folder/my-report.json')
};

It defaults to './coverage/coverage-summary.json'. as you can see here.

Either way, thanks for reporting an issue, the docs here clearly need some more details!