Skip to content
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

Ignore hint does not mark lines and statements of uncovered files #217

Closed
AriPerkkio opened this issue Jul 5, 2023 · 0 comments · Fixed by #218
Closed

Ignore hint does not mark lines and statements of uncovered files #217

AriPerkkio opened this issue Jul 5, 2023 · 0 comments · Fixed by #218

Comments

@AriPerkkio
Copy link
Contributor

When uncovered file contains ignore hints, the statements and lines are not marked as 100. Branches and functions are correctly marked as covered.

Reproduction

Minimal, without test runner

Save as repro.mjs and run as node repro.mjs. See how branches and functions are covered but statements are not.

import v8ToIstanbul from "v8-to-istanbul";
import { writeFileSync } from "node:fs";

const source = `
/* c8 ignore next 3 */
module.exports = function sum(a, b) {
  return a + b;
};
`.trim();

writeFileSync("test-file.js", source, "utf-8");

const converter = v8ToIstanbul("./test-file.js", 0, { source });
await converter.load();

converter.applyCoverage([
  {
    functionName: "(empty-report)",
    ranges: [
      {
        startOffset: 0,
        endOffset: source.length,
        count: 0,
      },
    ],
    isBlockCoverage: true,
  },
]);

const coverageMap = converter.toIstanbul();
const [fileCoverage] = Object.values(coverageMap);
const { b, f, s } = fileCoverage;

console.log({ b, f, s });

/*
$ node coverage-test.mjs
{
  b: { '0': [ 1 ] },
  f: { '0': 1 },
  s: { '0': 0, '1': 0, '2': 0, '3': 0 }
}
*/

With c8

c8-repro
├── index.js
├── package.json
└── temp.js
// index.js
console.log("Hello world");
// temp.js
/* c8 ignore next 3 */
module.exports = function sum(a, b) {
  return a + b;
};
{
  "name": "c8-repro",
  "scripts": {
    "c8": "c8"
  },
  "dependencies": {
    "c8": "^8.0.0"
  }
}
$ pnpm run c8 --all node index.js 

> c8 "--all" "node" "index.js"

Hello world
----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |      20 |      100 |     100 |      20 |                   
 index.js |     100 |      100 |     100 |     100 |                   
 temp.js  |       0 |      100 |     100 |       0 | 1-4               
----------|---------|----------|---------|---------|-------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant