bcoe / bcoe/c8

c8 CLI doesn't work properly when executed in a sub-directory of the project

Open
#498 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.1k
Forks
99
PR merge metrics
No merged PRs in 30d

Description

* **Version**: 8.0.1
* **Platform**: Ubuntu 20.04 + Node.js 16.20.2

Consider the following project:

#### src/index.ts
```ts
export const foo = (bar: number) => {
return bar + 1;
};
```

#### test/index.ts
```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
```sh
$ 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/`)
```sh
$ 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:

```json
{
"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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.