1 | 'use strict'
|
2 |
|
3 | const co = require('co')
|
4 | const path = require('path')
|
5 | const aglob = require('aglob')
|
6 | const execcli = require('execcli')
|
7 | const _mocha = require.resolve('mocha/bin/_mocha')
|
8 |
|
9 |
|
10 | function coverage (pattern, options = {}) {
|
11 | let {
|
12 | dir = 'coverage',
|
13 | timeout = 6000,
|
14 | cwd = process.cwd()
|
15 | } = options
|
16 | return co(function * () {
|
17 | let filenames = yield aglob(pattern, { cwd })
|
18 | if (filenames.length === 0) {
|
19 | throw new Error(`File not found with pattern: ${pattern}`)
|
20 | }
|
21 | let istanbul = require.resolve('istanbul/lib/cli.js')
|
22 | return execcli(istanbul, [
|
23 | 'cover', '--dir', dir, _mocha, '--', '-t', timeout, ...filenames
|
24 | ], {
|
25 | cwd,
|
26 | notfound: 'try `npm install istanbul -g`'
|
27 | })
|
28 | })
|
29 | }
|
30 |
|
31 | module.exports = coverage
|