1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict'
|
12 |
|
13 | const execcli = require('execcli')
|
14 | const co = require('co')
|
15 |
|
16 |
|
17 | function define (script, options = {}) {
|
18 | let out = options.out || 'coverage'
|
19 |
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function task (context) {
|
27 | let { logger } = context
|
28 |
|
29 | logger.debug('Measure coverage with script:', script)
|
30 | let cmdArgs = [ 'cover' ].concat(script.split(' ')).concat({
|
31 | dir: out
|
32 | })
|
33 | return co(function * () {
|
34 | return yield define.istanbul(cmdArgs)
|
35 | })
|
36 | }
|
37 |
|
38 | task.$desc = 'Measure test coverage.'
|
39 | return task;
|
40 | }
|
41 |
|
42 | define.istanbul = function istanbul (args) {
|
43 | return execcli.npmBin('istanbul', args, {
|
44 | notfound: 'try `npm install istanbul -g`',
|
45 | search: [ process.cwd(), __dirname ]
|
46 | })
|
47 | }
|
48 |
|
49 | module.exports = define
|