- Version: 8.0.1
- Platform: Ubuntu 20.04 + Node.js 16.20.2
Consider the following project:
src/index.ts
export const foo = (bar: number) => {
return bar + 1;
};
test/index.ts
import assert from "assert";
import {foo} from "../src";
assert(foo(5) === 6);
Depending on where c8 is executed, the result is quite different:
Executed from the root of the project
$ c8 ts-node test/index.ts
=============================== Coverage summary ===============================
Statements : 100% ( 3/3 )
Branches : 100% ( 1/1 )
Functions : 100% ( 1/1 )
Lines : 100% ( 3/3 )
================================================================================
Executed from the place where the test file is (i.e. test/)
$ cd test/
$ c8 ts-node index.ts
=============================== Coverage summary ===============================
Statements : Unknown% ( 0/0 )
Branches : Unknown% ( 0/0 )
Functions : Unknown% ( 0/0 )
Lines : Unknown% ( 0/0 )
================================================================================
For information - and maybe it can help - here is the .nycrc.json that I use:
{
"all": true,
"lines": 100,
"branches": 100,
"functions": 100,
"extension": [
".ts"
],
"include": [
"src"
],
"exclude": [],
"reporter": [
"text-summary",
"html"
]
}
Let me also add that nyc works perfectly regardless of where it is executed - i.e. replace c8 with nyc in the showcased shell commands and the report is perfect in both case. We educated all our developers too execute coverage as soon as possible and on local tests, and unfortunately c8 not supporting this pattern means that we can't migrate to it from nyc.
Hopefully this is solvable.
Consider the following project:
src/index.ts
test/index.ts
Depending on where
c8is executed, the result is quite different:Executed from the root of the project
Executed from the place where the test file is (i.e.
test/)For information - and maybe it can help - here is the
.nycrc.jsonthat I use:{ "all": true, "lines": 100, "branches": 100, "functions": 100, "extension": [ ".ts" ], "include": [ "src" ], "exclude": [], "reporter": [ "text-summary", "html" ] }Let me also add that
nycworks perfectly regardless of where it is executed - i.e. replacec8withnycin the showcased shell commands and the report is perfect in both case. We educated all our developers too execute coverage as soon as possible and on local tests, and unfortunatelyc8not supporting this pattern means that we can't migrate to it fromnyc.Hopefully this is solvable.