-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
466 lines (441 loc) · 10.7 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
'use strict';
const defaultExclude = require('./default-exclude.js');
const defaultExtension = require('./default-extension.js');
const nycCommands = {
all: [null, 'check-coverage', 'instrument', 'merge', 'report'],
testExclude: [null, 'instrument', 'report', 'check-coverage'],
instrument: [null, 'instrument'],
checkCoverage: [null, 'report', 'check-coverage'],
report: [null, 'report'],
main: [null],
instrumentOnly: ['instrument']
};
const cwd = {
description: 'working directory used when resolving paths',
type: 'string',
get default() {
return process.cwd();
},
nycCommands: nycCommands.all
};
const nycrcPath = {
description: 'specify an explicit path to find nyc configuration',
nycCommands: nycCommands.all
};
const tempDir = {
description: 'directory to output raw coverage information to',
type: 'string',
default: './.nyc_output',
nycAlias: 't',
nycHiddenAlias: 'temp-directory',
nycCommands: [null, 'check-coverage', 'merge', 'report']
};
const testExclude = {
exclude: {
description: 'a list of specific files and directories that should be excluded from coverage, glob patterns are supported',
type: 'array',
items: {
type: 'string'
},
default: defaultExclude,
nycCommands: nycCommands.testExclude,
nycAlias: 'x'
},
excludeNodeModules: {
description: 'whether or not to exclude all node_module folders (i.e. **/node_modules/**) by default',
type: 'boolean',
default: true,
nycCommands: nycCommands.testExclude
},
include: {
description: 'a list of specific files that should be covered, glob patterns are supported',
type: 'array',
items: {
type: 'string'
},
default: [],
nycCommands: nycCommands.testExclude,
nycAlias: 'n'
},
extension: {
description: 'a list of extensions that nyc should handle in addition to .js',
type: 'array',
items: {
type: 'string'
},
default: defaultExtension,
nycCommands: nycCommands.testExclude,
nycAlias: 'e'
}
};
const instrumentVisitor = {
coverageVariable: {
description: 'variable to store coverage',
type: 'string',
default: '__coverage__',
nycCommands: nycCommands.instrument
},
coverageGlobalScope: {
description: 'scope to store the coverage variable',
type: 'string',
default: 'this',
nycCommands: nycCommands.instrument
},
coverageGlobalScopeFunc: {
description: 'avoid potentially replaced `Function` when finding global scope',
type: 'boolean',
default: true,
nycCommands: nycCommands.instrument
},
ignoreClassMethods: {
description: 'class method names to ignore for coverage',
type: 'array',
items: {
type: 'string'
},
default: [],
nycCommands: nycCommands.instrument
}
};
const instrumentParseGen = {
autoWrap: {
description: 'allow `return` statements outside of functions',
type: 'boolean',
default: true,
nycCommands: nycCommands.instrument
},
esModules: {
description: 'should files be treated as ES Modules',
type: 'boolean',
default: true,
nycCommands: nycCommands.instrument
},
parserPlugins: {
description: 'babel parser plugins to use when parsing the source',
type: 'array',
items: {
type: 'string'
},
/* Babel parser plugins are to be enabled when the feature is stage 3 and
* implemented in a released version of node.js. */
default: [
'asyncGenerators',
'bigInt',
'classProperties',
'classPrivateProperties',
'classPrivateMethods',
'dynamicImport',
'importMeta',
'numericSeparator',
'objectRestSpread',
'optionalCatchBinding',
'topLevelAwait'
],
nycCommands: nycCommands.instrument
},
compact: {
description: 'should the output be compacted?',
type: 'boolean',
default: true,
nycCommands: nycCommands.instrument
},
preserveComments: {
description: 'should comments be preserved in the output?',
type: 'boolean',
default: true,
nycCommands: nycCommands.instrument
},
produceSourceMap: {
description: 'should source maps be produced?',
type: 'boolean',
default: true,
nycCommands: nycCommands.instrument
}
};
const checkCoverage = {
excludeAfterRemap: {
description: 'should exclude logic be performed after the source-map remaps filenames?',
type: 'boolean',
default: true,
nycCommands: nycCommands.checkCoverage
},
branches: {
description: 'what % of branches must be covered?',
type: 'number',
default: 0,
minimum: 0,
maximum: 100,
nycCommands: nycCommands.checkCoverage
},
functions: {
description: 'what % of functions must be covered?',
type: 'number',
default: 0,
minimum: 0,
maximum: 100,
nycCommands: nycCommands.checkCoverage
},
lines: {
description: 'what % of lines must be covered?',
type: 'number',
default: 90,
minimum: 0,
maximum: 100,
nycCommands: nycCommands.checkCoverage
},
statements: {
description: 'what % of statements must be covered?',
type: 'number',
default: 0,
minimum: 0,
maximum: 100,
nycCommands: nycCommands.checkCoverage
},
perFile: {
description: 'check thresholds per file',
type: 'boolean',
default: false,
nycCommands: nycCommands.checkCoverage
}
};
const report = {
checkCoverage: {
description: 'check whether coverage is within thresholds provided',
type: 'boolean',
default: false,
nycCommands: nycCommands.report
},
reporter: {
description: 'coverage reporter(s) to use',
type: 'array',
items: {
type: 'string'
},
default: ['text'],
nycCommands: nycCommands.report,
nycAlias: 'r'
},
reportDir: {
description: 'directory to output coverage reports in',
type: 'string',
default: 'coverage',
nycCommands: nycCommands.report
},
showProcessTree: {
description: 'display the tree of spawned processes',
type: 'boolean',
default: false,
nycCommands: nycCommands.report
},
skipEmpty: {
description: 'don\'t show empty files (no lines of code) in report',
type: 'boolean',
default: false,
nycCommands: nycCommands.report
},
skipFull: {
description: 'don\'t show files with 100% statement, branch, and function coverage',
type: 'boolean',
default: false,
nycCommands: nycCommands.report
}
};
const nycMain = {
silent: {
description: 'don\'t output a report after tests finish running',
type: 'boolean',
default: false,
nycCommands: nycCommands.main,
nycAlias: 's'
},
all: {
description: 'whether or not to instrument all files of the project (not just the ones touched by your test suite)',
type: 'boolean',
default: false,
nycCommands: nycCommands.main,
nycAlias: 'a'
},
eager: {
description: 'instantiate the instrumenter at startup (see https://git.io/vMKZ9)',
type: 'boolean',
default: false,
nycCommands: nycCommands.main
},
cache: {
description: 'cache instrumentation results for improved performance',
type: 'boolean',
default: true,
nycCommands: nycCommands.main,
nycAlias: 'c'
},
cacheDir: {
description: 'explicitly set location for instrumentation cache',
type: 'string',
nycCommands: nycCommands.main
},
babelCache: {
description: 'cache babel transpilation results for improved performance',
type: 'boolean',
default: false,
nycCommands: nycCommands.main
},
useSpawnWrap: {
description: 'use spawn-wrap instead of setting process.env.NODE_OPTIONS',
type: 'boolean',
default: false,
nycCommands: nycCommands.main
},
hookRequire: {
description: 'should nyc wrap require?',
type: 'boolean',
default: true,
nycCommands: nycCommands.main
},
hookRunInContext: {
description: 'should nyc wrap vm.runInContext?',
type: 'boolean',
default: false,
nycCommands: nycCommands.main
},
hookRunInThisContext: {
description: 'should nyc wrap vm.runInThisContext?',
type: 'boolean',
default: false,
nycCommands: nycCommands.main
},
clean: {
description: 'should the .nyc_output folder be cleaned before executing tests',
type: 'boolean',
default: true,
nycCommands: nycCommands.main
}
};
const instrumentOnly = {
inPlace: {
description: 'should nyc run the instrumentation in place?',
type: 'boolean',
default: false,
nycCommands: nycCommands.instrumentOnly
},
exitOnError: {
description: 'should nyc exit when an instrumentation failure occurs?',
type: 'boolean',
default: false,
nycCommands: nycCommands.instrumentOnly
},
delete: {
description: 'should the output folder be deleted before instrumenting files?',
type: 'boolean',
default: false,
nycCommands: nycCommands.instrumentOnly
},
completeCopy: {
description: 'should nyc copy all files from input to output as well as instrumented files?',
type: 'boolean',
default: false,
nycCommands: nycCommands.instrumentOnly
}
};
const nyc = {
description: 'nyc configuration options',
type: 'object',
properties: {
cwd,
nycrcPath,
tempDir,
/* Test Exclude */
...testExclude,
/* Instrumentation settings */
...instrumentVisitor,
/* Instrumentation parser/generator settings */
...instrumentParseGen,
sourceMap: {
description: 'should nyc detect and handle source maps?',
type: 'boolean',
default: true,
nycCommands: nycCommands.instrument
},
require: {
description: 'a list of additional modules that nyc should attempt to require in its subprocess, e.g., @babel/register, @babel/polyfill',
type: 'array',
items: {
type: 'string'
},
default: [],
nycCommands: nycCommands.instrument,
nycAlias: 'i'
},
instrument: {
description: 'should nyc handle instrumentation?',
type: 'boolean',
default: true,
nycCommands: nycCommands.instrument
},
/* Check coverage */
...checkCoverage,
/* Report options */
...report,
/* Main command options */
...nycMain,
/* Instrument command options */
...instrumentOnly
}
};
const configs = {
nyc,
testExclude: {
description: 'test-exclude options',
type: 'object',
properties: {
cwd,
...testExclude
}
},
babelPluginIstanbul: {
description: 'babel-plugin-istanbul options',
type: 'object',
properties: {
cwd,
...testExclude,
...instrumentVisitor
}
},
instrumentVisitor: {
description: 'instrument visitor options',
type: 'object',
properties: instrumentVisitor
},
instrumenter: {
description: 'stand-alone instrumenter options',
type: 'object',
properties: {
...instrumentVisitor,
...instrumentParseGen
}
}
};
function defaultsReducer(defaults, [name, {default: value}]) {
/* Modifying arrays in defaults is safe, does not change schema. */
if (Array.isArray(value)) {
value = [...value];
}
return Object.assign(defaults, {[name]: value});
}
module.exports = {
...configs,
defaults: Object.keys(configs).reduce(
(defaults, id) => {
Object.defineProperty(defaults, id, {
enumerable: true,
get() {
/* This defers `process.cwd()` until defaults are requested. */
return Object.entries(configs[id].properties)
.filter(([, info]) => 'default' in info)
.reduce(defaultsReducer, {});
}
});
return defaults;
},
{}
)
};