Skip to content

Commit a4733c6

Browse files
authored
feat: add --exclude-node-modules option (bcoe#321)
1 parent 8365a71 commit a4733c6

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

lib/commands/report.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ exports.outputReport = async function (argv) {
2424
all: argv.all,
2525
allowExternal: argv.allowExternal,
2626
src: argv.src,
27-
skipFull: argv.skipFull
27+
skipFull: argv.skipFull,
28+
excludeNodeModules: argv.excludeNodeModules
2829
})
2930
await report.run()
3031
if (argv.checkCoverage) await checkCoverages(argv, report)

lib/parse-args.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ function buildYargs (withCommands = false) {
4141
describe: 'supplying --src will override cwd as the default location where --all looks for src files. --src can be ' +
4242
'supplied multiple times and each directory will be included. This allows for workspaces spanning multiple projects'
4343
})
44+
.option('exclude-node-modules', {
45+
default: true,
46+
type: 'boolean',
47+
describe: 'whether or not to exclude all node_module folders (i.e. **/node_modules/**) by default'
48+
})
4449
.option('include', {
4550
alias: 'n',
4651
default: [],

lib/report.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class Report {
2727
all,
2828
src,
2929
allowExternal = false,
30-
skipFull
30+
skipFull,
31+
excludeNodeModules
3132
}) {
3233
this.reporter = reporter
3334
this.reportsDirectory = reportsDirectory
@@ -37,7 +38,8 @@ class Report {
3738
this.exclude = new Exclude({
3839
exclude: exclude,
3940
include: include,
40-
relativePath: !allowExternal
41+
relativePath: !allowExternal,
42+
excludeNodeModules: excludeNodeModules
4143
})
4244
this.excludeAfterRemap = excludeAfterRemap
4345
this.omitRelative = omitRelative

test/integration.js_10.snap

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -152,24 +152,24 @@ hey
152152
--------------------------|---------|----------|---------|---------|--------------------------------
153153
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
154154
--------------------------|---------|----------|---------|---------|--------------------------------
155-
All files | 73.7 | 59.76 | 62.5 | 73.7 |
155+
All files | 73.96 | 59.76 | 62.5 | 73.96 |
156156
bin | 78.85 | 60 | 66.67 | 78.85 |
157157
c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51
158-
lib | 76.94 | 54.39 | 72 | 76.94 |
158+
lib | 77.2 | 54.39 | 72 | 77.2 |
159159
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
160-
parse-args.js | 96.72 | 58.33 | 100 | 96.72 | 137-138,146-147,160-161
161-
report.js | 75.16 | 58.33 | 78.57 | 75.16 | ...247,274-275,281-283,304-309
160+
parse-args.js | 96.81 | 58.33 | 100 | 96.81 | 142-143,151-152,165-166
161+
report.js | 75.32 | 58.33 | 78.57 | 75.32 | ...249,276-277,283-285,306-311
162162
source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98
163-
lib/commands | 45.65 | 75 | 16.67 | 45.65 |
163+
lib/commands | 46.24 | 75 | 16.67 | 46.24 |
164164
check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61
165-
report.js | 93.55 | 71.43 | 50 | 93.55 | 9-10
165+
report.js | 93.75 | 71.43 | 50 | 93.75 | 9-10
166166
test/fixtures | 83.33 | 85.71 | 66.67 | 83.33 |
167167
async.js | 100 | 100 | 100 | 100 |
168168
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
169169
--------------------------|---------|----------|---------|---------|--------------------------------
170-
,ERROR: Coverage for lines (73.7%) does not meet global threshold (101%)
170+
,ERROR: Coverage for lines (73.96%) does not meet global threshold (101%)
171171
ERROR: Coverage for branches (59.76%) does not meet global threshold (82%)
172-
ERROR: Coverage for statements (73.7%) does not meet global threshold (95%)
172+
ERROR: Coverage for statements (73.96%) does not meet global threshold (95%)
173173
"
174174
`;
175175

@@ -179,17 +179,17 @@ ERROR: Coverage for branches (60%) does not meet threshold (82%) for bin/c8.js
179179
ERROR: Coverage for statements (78.85%) does not meet threshold (95%) for bin/c8.js
180180
ERROR: Coverage for lines (21.31%) does not meet threshold (101%) for lib/commands/check-coverage.js
181181
ERROR: Coverage for statements (21.31%) does not meet threshold (95%) for lib/commands/check-coverage.js
182-
ERROR: Coverage for lines (93.55%) does not meet threshold (101%) for lib/commands/report.js
182+
ERROR: Coverage for lines (93.75%) does not meet threshold (101%) for lib/commands/report.js
183183
ERROR: Coverage for branches (71.43%) does not meet threshold (82%) for lib/commands/report.js
184-
ERROR: Coverage for statements (93.55%) does not meet threshold (95%) for lib/commands/report.js
184+
ERROR: Coverage for statements (93.75%) does not meet threshold (95%) for lib/commands/report.js
185185
ERROR: Coverage for lines (90%) does not meet threshold (101%) for lib/is-cjs-esm-bridge.js
186186
ERROR: Coverage for branches (25%) does not meet threshold (82%) for lib/is-cjs-esm-bridge.js
187187
ERROR: Coverage for statements (90%) does not meet threshold (95%) for lib/is-cjs-esm-bridge.js
188-
ERROR: Coverage for lines (96.72%) does not meet threshold (101%) for lib/parse-args.js
188+
ERROR: Coverage for lines (96.81%) does not meet threshold (101%) for lib/parse-args.js
189189
ERROR: Coverage for branches (58.33%) does not meet threshold (82%) for lib/parse-args.js
190-
ERROR: Coverage for lines (75.16%) does not meet threshold (101%) for lib/report.js
190+
ERROR: Coverage for lines (75.32%) does not meet threshold (101%) for lib/report.js
191191
ERROR: Coverage for branches (58.33%) does not meet threshold (82%) for lib/report.js
192-
ERROR: Coverage for statements (75.16%) does not meet threshold (95%) for lib/report.js
192+
ERROR: Coverage for statements (75.32%) does not meet threshold (95%) for lib/report.js
193193
ERROR: Coverage for lines (45%) does not meet threshold (101%) for lib/source-map-from-file.js
194194
ERROR: Coverage for statements (45%) does not meet threshold (95%) for lib/source-map-from-file.js
195195
ERROR: Coverage for lines (100%) does not meet threshold (101%) for test/fixtures/async.js
@@ -202,9 +202,9 @@ ERROR: Coverage for statements (75%) does not meet threshold (95%) for test/fixt
202202
exports[`c8 check-coverage exits with 0 if coverage within threshold 1`] = `",,"`;
203203

204204
exports[`c8 check-coverage exits with 1 if coverage is below threshold 1`] = `
205-
",,ERROR: Coverage for lines (73.7%) does not meet global threshold (101%)
205+
",,ERROR: Coverage for lines (73.96%) does not meet global threshold (101%)
206206
ERROR: Coverage for branches (59.76%) does not meet global threshold (82%)
207-
ERROR: Coverage for statements (73.7%) does not meet global threshold (95%)
207+
ERROR: Coverage for statements (73.96%) does not meet global threshold (95%)
208208
"
209209
`;
210210

@@ -287,17 +287,17 @@ exports[`c8 report generates report from existing temporary files 1`] = `
287287
",--------------------------|---------|----------|---------|---------|--------------------------------
288288
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
289289
--------------------------|---------|----------|---------|---------|--------------------------------
290-
All files | 73.7 | 59.76 | 62.5 | 73.7 |
290+
All files | 73.96 | 59.76 | 62.5 | 73.96 |
291291
bin | 78.85 | 60 | 66.67 | 78.85 |
292292
c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51
293-
lib | 76.94 | 54.39 | 72 | 76.94 |
293+
lib | 77.2 | 54.39 | 72 | 77.2 |
294294
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
295-
parse-args.js | 96.72 | 58.33 | 100 | 96.72 | 137-138,146-147,160-161
296-
report.js | 75.16 | 58.33 | 78.57 | 75.16 | ...247,274-275,281-283,304-309
295+
parse-args.js | 96.81 | 58.33 | 100 | 96.81 | 142-143,151-152,165-166
296+
report.js | 75.32 | 58.33 | 78.57 | 75.32 | ...249,276-277,283-285,306-311
297297
source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98
298-
lib/commands | 45.65 | 75 | 16.67 | 45.65 |
298+
lib/commands | 46.24 | 75 | 16.67 | 46.24 |
299299
check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61
300-
report.js | 93.55 | 71.43 | 50 | 93.55 | 9-10
300+
report.js | 93.75 | 71.43 | 50 | 93.75 | 9-10
301301
test/fixtures | 83.33 | 85.71 | 66.67 | 83.33 |
302302
async.js | 100 | 100 | 100 | 100 |
303303
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
@@ -309,24 +309,24 @@ exports[`c8 report supports --check-coverage, when generating reports 1`] = `
309309
",--------------------------|---------|----------|---------|---------|--------------------------------
310310
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
311311
--------------------------|---------|----------|---------|---------|--------------------------------
312-
All files | 73.7 | 59.76 | 62.5 | 73.7 |
312+
All files | 73.96 | 59.76 | 62.5 | 73.96 |
313313
bin | 78.85 | 60 | 66.67 | 78.85 |
314314
c8.js | 78.85 | 60 | 66.67 | 78.85 | 22,27-29,32-33,41-43,50-51
315-
lib | 76.94 | 54.39 | 72 | 76.94 |
315+
lib | 77.2 | 54.39 | 72 | 77.2 |
316316
is-cjs-esm-bridge.js | 90 | 25 | 100 | 90 | 9
317-
parse-args.js | 96.72 | 58.33 | 100 | 96.72 | 137-138,146-147,160-161
318-
report.js | 75.16 | 58.33 | 78.57 | 75.16 | ...247,274-275,281-283,304-309
317+
parse-args.js | 96.81 | 58.33 | 100 | 96.81 | 142-143,151-152,165-166
318+
report.js | 75.32 | 58.33 | 78.57 | 75.32 | ...249,276-277,283-285,306-311
319319
source-map-from-file.js | 45 | 100 | 0 | 45 | 39-50,52-67,69-77,81-98
320-
lib/commands | 45.65 | 75 | 16.67 | 45.65 |
320+
lib/commands | 46.24 | 75 | 16.67 | 46.24 |
321321
check-coverage.js | 21.31 | 100 | 0 | 21.31 | 9-11,14-27,30-44,46-61
322-
report.js | 93.55 | 71.43 | 50 | 93.55 | 9-10
322+
report.js | 93.75 | 71.43 | 50 | 93.75 | 9-10
323323
test/fixtures | 83.33 | 85.71 | 66.67 | 83.33 |
324324
async.js | 100 | 100 | 100 | 100 |
325325
normal.js | 75 | 66.67 | 33.33 | 75 | 14-16,18-20
326326
--------------------------|---------|----------|---------|---------|--------------------------------
327-
,ERROR: Coverage for lines (73.7%) does not meet global threshold (101%)
327+
,ERROR: Coverage for lines (73.96%) does not meet global threshold (101%)
328328
ERROR: Coverage for branches (59.76%) does not meet global threshold (82%)
329-
ERROR: Coverage for statements (73.7%) does not meet global threshold (95%)
329+
ERROR: Coverage for statements (73.96%) does not meet global threshold (95%)
330330
"
331331
`;
332332

0 commit comments

Comments
 (0)