Skip to content

Commit

Permalink
fix: Ignore options that are explicitly set undefined. (#40)
Browse files Browse the repository at this point in the history
This happens in an edge case of nyc use where `new NYC` is called with a
hand-crafted config instead of using the result of config / CLI parsing.
  • Loading branch information
coreyfarrell committed Dec 8, 2019
1 parent 131c3b0 commit b57e936
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 9 additions & 4 deletions index.js
Expand Up @@ -8,14 +8,19 @@ const { defaults } = require('@istanbuljs/schema');
const isOutsideDir = require('./is-outside-dir');

class TestExclude {
constructor(opts) {
constructor(opts = {}) {
Object.assign(
this,
{relativePath: true},
defaults.testExclude,
opts
defaults.testExclude
);

for (const [name, value] of Object.entries(opts)) {
if (value !== undefined) {
this[name] = value;
}
}

if (typeof this.include === 'string') {
this.include = [this.include];
}
Expand All @@ -30,7 +35,7 @@ class TestExclude {
this.extension = false;
}

if (this.include.length > 0) {
if (this.include && this.include.length > 0) {
this.include = prepGlobPatterns([].concat(this.include));
} else {
this.include = false;
Expand Down
11 changes: 11 additions & 0 deletions test/test-exclude.js
Expand Up @@ -272,3 +272,14 @@ t.test('allows exclude/include rule to be a string', t =>
yes: ['src/batman/robin/foo.js']
})
);

t.test('tolerates undefined exclude/include', t =>
testHelper(t, {
options: {
exclude: undefined,
include: undefined
},
no: ['test.js'],
yes: ['index.js']
})
);

0 comments on commit b57e936

Please sign in to comment.