This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cov8.js
executable file
路73 lines (69 loc) 路 2.16 KB
/
cov8.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
#!/usr/bin/env node
'use strict'
const yargs = require('yargs')
const exclude = require('test-exclude')
const sw = require('spawn-wrap')
const foreground = require('foreground-child')
const mkdirp = require('mkdirp')
const rimraf = require('rimraf')
const path = require('path')
yargs // eslint-disable-line
.usage('$0 [opts] <script> [opts]')
.pkgConf('nyc')
.option('exclude', {
alias: 'x',
default: exclude.defaultExclude,
describe: 'a list of specific files and directories that should be excluded from coverage, glob patterns are supported.'
})
.option('include', {
alias: 'n',
default: [],
describe: 'a list of specific files that should be covered, glob patterns are supported'
})
.option('coverage-directory', {
alias: 'd',
default: './coverage',
describe: 'directory to output coverage JSON and reports'
})
.option('forks', {
alias: 'f',
default: false,
boolean: true,
describe: 'only cover fork processes'
})
.command('<script>')
.describe('default', 'Execute test')
.example('$0 mocha test.js', 'Execute test and generate coverage')
.command('report <reporter>')
.describe('report', 'Generate reporting')
.example('$0 report lcov', 'Generate lcov coverage report')
.command('clear')
.describe('clear', 'Clear coverage directory')
.demandCommand(1)
.argv
mkdirp.sync(path.join(yargs.argv['coverage-directory'], './tmp'))
if (yargs.argv._[0] === 'clear') {
rimraf.sync(yargs.argv['coverage-directory'])
} else if (yargs.argv._[0] === 'report') {
// reporting
const reporters = yargs.argv._
reporters.shift()
if (Number(process.version.match(/^v(\d+\.\d+)/)[1]) > 8.0) {
const Report = require('../src/report')
new Report(yargs.argv['coverage-directory'], reporters).generateReport()
} else {
console.error('[COV8] This module only works for node > 8.0')
}
} else {
// launch coverage
sw([require.resolve('../src/launch.js')], {
COV8_OPTIONS: JSON.stringify({
include: yargs.argv.include,
exclude: yargs.argv.exclude,
directory: yargs.argv['coverage-directory'],
forks: yargs.argv.forks
})
})
// launch test
foreground(yargs.argv._)
}