UNPKG

793 BJavaScriptView Raw
1'use strict'
2
3const co = require('co')
4const path = require('path')
5const aglob = require('aglob')
6const execcli = require('execcli')
7const _mocha = require.resolve('mocha/bin/_mocha')
8
9/** @lends coverage */
10function 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
31module.exports = coverage