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

Adding --extension option, allowing override of defaults. #340

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ Here is a list of common options. Run `c8 --help` for the full list and document
| `--all` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `boolean` | `false` |
| `--src` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | `[process.cwd()]`|
| `-n`, `--include` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | `[]` (include all files) |
| `-x`, `--exclude` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | [list](https://github.com/istanbuljs/schema/blob/main/default-exclude.js) |
| `-x`, `--exclude` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | [list](https://github.com/istanbuljs/schema/blob/master/default-exclude.js) |
| `--extension` | list of file extensions to be covered | `Array<string>` | [list](https://github.com/istanbuljs/schema/blob/master/default-extension.js) |
| `--skip-full` | do not show files with 100% statement, branch, and function coverage | `boolean` | `false` |
| `--check-coverage` | check whether coverage is within thresholds provided | `boolean` | `false` |
| `--temp-directory` | directory V8 coverage data is written to and read from | `string` | `process.env.NODE_V8_COVERAGE` |
Expand Down
3 changes: 2 additions & 1 deletion lib/commands/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ exports.outputReport = async function (argv) {
allowExternal: argv.allowExternal,
src: argv.src,
skipFull: argv.skipFull,
excludeNodeModules: argv.excludeNodeModules
excludeNodeModules: argv.excludeNodeModules,
extension: argv.extension
})
await report.run()
if (argv.checkCoverage) await checkCoverages(argv, report)
Expand Down
6 changes: 6 additions & 0 deletions lib/parse-args.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const defaultExclude = require('@istanbuljs/schema/default-exclude')
const defaultExtension = require('@istanbuljs/schema/default-extension')
const findUp = require('find-up')
const { readFileSync } = require('fs')
const Yargs = require('yargs/yargs')
Expand Down Expand Up @@ -71,6 +72,11 @@ function buildYargs (withCommands = false) {
group: 'Reporting options',
describe: 'do not show files with 100% statement, branch, and function coverage'
})
.options('extension', {
default: defaultExtension,
group: 'Reporting options',
describe: 'a list of file extensions that should be covered'
})
.option('check-coverage', {
default: false,
type: 'boolean',
Expand Down
9 changes: 6 additions & 3 deletions lib/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class Report {
src,
allowExternal = false,
skipFull,
excludeNodeModules
excludeNodeModules,
extension
}) {
this.reporter = reporter
this.reportsDirectory = reportsDirectory
Expand All @@ -39,7 +40,8 @@ class Report {
exclude: exclude,
include: include,
relativePath: !allowExternal,
excludeNodeModules: excludeNodeModules
excludeNodeModules: excludeNodeModules,
extension: extension
})
this.excludeAfterRemap = excludeAfterRemap
this.omitRelative = omitRelative
Expand Down Expand Up @@ -187,12 +189,13 @@ class Report {
result: emptyReports
})
const workingDirs = this.src
const { extension } = this.exclude
for (const workingDir of workingDirs) {
this.exclude.globSync(workingDir).forEach((f) => {
const fullPath = resolve(workingDir, f)
if (!fileIndex.has(fullPath)) {
const ext = extname(fullPath)
if (ext === '.js' || ext === '.ts' || ext === '.mjs') {
if (extension.includes(ext)) {
const stat = statSync(fullPath)
const sourceMap = getSourceMapFromFile(fullPath)
if (sourceMap) {
Expand Down