Skip to content

Commit e754a22

Browse files
committed
feat: allow passing --from filename, closes #1
1 parent c77af4f commit e754a22

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,13 @@ npx check-coverage main.js
1111
npx only-covered foo.js bar.js
1212
```
1313

14+
## only-covered
15+
16+
By default `only-covered` script reads `.nyc_output/out.json` file from the current working directory. You can specify a different file using `--from` parameter
17+
18+
```shell
19+
only-covered --from examples/exclude-files/coverage/coverage-final.json main.js
20+
```
21+
1422
[ci image]: https://github.com/bahmutov/check-code-coverage/workflows/ci/badge.svg?branch=master
1523
[ci url]: https://github.com/bahmutov/check-code-coverage/actions

bin/check-coverage.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
// @ts-check
23
const { join } = require('path')
34

45
const filename = process.argv[2]

bin/only-covered.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
#!/usr/bin/env node
2-
const { join } = require('path')
2+
// @ts-check
3+
const { join, resolve } = require('path')
34
const _ = require('lodash')
5+
const arg = require('arg')
46

5-
const filenames = process.argv.slice(2)
7+
const args = arg({
8+
'--from': String, // input filename, by default ".nyc_output/out.json"
9+
})
10+
11+
const filenames = args._
612
if (!filenames.length) {
713
console.error('Usage: node %s <file name 1> <file name 2>', __filename)
814
process.exit(1)
@@ -11,7 +17,10 @@ if (!filenames.length) {
1117
const shouldBeCovered = filepath =>
1218
filenames.some(name => filepath.endsWith(name))
1319

14-
const coverageFilename = join(process.cwd(), '.nyc_output', 'out.json')
20+
const fromFilename = args['--from'] || join('.nyc_output', 'out.json')
21+
const coverageFilename = resolve(fromFilename)
22+
console.log('reading coverage results from %s', coverageFilename)
23+
1524
const coverage = require(coverageFilename)
1625

1726
const coveredFilepaths = Object.keys(coverage).map(name => coverage[name].path)

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"semantic-release": "^17.0.4"
3535
},
3636
"dependencies": {
37+
"arg": "4.1.3",
3738
"lodash": "4.17.15"
3839
}
3940
}

0 commit comments

Comments
 (0)