UNPKG

1.19 kBJavaScriptView Raw
1/**
2 * apeman task to measure coverage.
3 * @memberof module:apeman-task-coverage/lib
4 * @function define
5 * @param {string} script - Script to run for coverage.
6 * @param {options} [options] - Optional settings.
7 * @param {string} [options.out="coverage"] - Output directory.
8 * @returns {function} - Defined task function.
9 */
10
11'use strict'
12
13const execcli = require('execcli')
14const co = require('co')
15
16/** @lends define */
17function define (script, options = {}) {
18 let out = options.out || 'coverage'
19
20 /**
21 * Defined task.
22 * @function task
23 * @param {object} context - Apeman task context.
24 * @returns {Promise}
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
42define.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
49module.exports = define