bcoe / bcoe/c8

Import of package.json causes package.json file to be included in coverage report and fail

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

Description

* **Version**: v12.10.0
* **Platform**: Windows 10 Pro version 1803

Was updating a package to change a `createRequire` style import of `package.json` into the now-supported direct `import` of the package file. In doing so, the `package.json` file is now showing up in coverage reports and failing on uncovered function.

**Original working code**

```
import { createRequire } from 'module';

const require = createRequire(import.meta.url);
const pkg = require('../package.json');
```

Here is code coverage output for this case:

```
🌈 SUMMARY RESULTS 🌈

Suites: 3 passed, 3 of 3 completed
Asserts: 50 passed, of 50
Time: 16s
----------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
package-composer | 100 | 100 | 100 | 100 | |
index.mjs | 100 | 100 | 100 | 100 | |
package-composer/bin | 100 | 100 | 100 | 100 | |
index.mjs | 100 | 100 | 100 | 100 | |
package-composer/lib | 100 | 100 | 100 | 100 | |
config.mjs | 100 | 100 | 100 | 100 | |
licenses.mjs | 100 | 100 | 100 | 100 | |
questions.mjs | 100 | 100 | 100 | 100 | |
utils.mjs | 100 | 100 | 100 | 100 | |
----------------------|----------|----------|----------|----------|-------------------|
info: Finished 'executeTests' after 21s
```

**Failing code**

```
import pkg from '../package.json';
```

and failing coverage output

```


🌈 SUMMARY RESULTS 🌈

Suites: 3 passed, 3 of 3 completed
Asserts: 50 passed, of 50
Time: 16s
----------------------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------------------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 97.22 | 100 | |
package-composer | 100 | 100 | 75 | 100 | |
index.mjs | 100 | 100 | 100 | 100 | |
package.json | 100 | 100 | 50 | 100 | |
package-composer/bin | 100 | 100 | 100 | 100 | |
index.mjs | 100 | 100 | 100 | 100 | |
package-composer/lib | 100 | 100 | 100 | 100 | |
config.mjs | 100 | 100 | 100 | 100 | |
licenses.mjs | 100 | 100 | 100 | 100 | |
questions.mjs | 100 | 100 | 100 | 100 | |
utils.mjs | 100 | 100 | 100 | 100 | |
----------------------|----------|----------|----------|----------|-------------------|
ERROR: Coverage for functions (97.22%) does not meet global threshold (100%)
```

Unfortunately, without any sort of way to ignore `package.json` file (via config or via ignore comment in JSON file), this pretty much prevents use of this newer JSON import feature in Node. if we want to meet 100% coverage.

I have not tested with other `import`ed JSON files.

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.