1 | 'use strict';
|
2 |
|
3 |
|
4 | var shell = require('shelljs'),
|
5 | shellescape = require('shell-escape'),
|
6 | path = require('path'),
|
7 | whichLocal = require('npm-which')(path.resolve(__dirname, '..')),
|
8 | whichCwd = require('npm-which')(process.cwd()),
|
9 | directories = {};
|
10 |
|
11 | shell.config.fatal = false;
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function getBin(filename) {
|
20 | try {
|
21 | return escape(whichLocal.sync(filename));
|
22 | } catch (unused) {
|
23 | return escape(whichCwd.sync(filename));
|
24 | }
|
25 | }
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | function escape(directory){
|
34 | return shellescape([directory]);
|
35 | }
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | module.exports = function (args) {
|
42 | directories.artifacts = shell.env.ARTIFACTS_DIR || path.join(process.cwd(), 'artifacts');
|
43 | directories.coverage = shell.env.COVERAGE_DIR || path.join(directories.artifacts, 'coverage');
|
44 | directories.tests = shell.env.TEST_DIR || path.join(directories.artifacts, 'test');
|
45 |
|
46 |
|
47 | Object.keys(directories).forEach(function (name) {
|
48 | shell.mkdir('-p', directories[name]);
|
49 | });
|
50 |
|
51 |
|
52 | shell.env.XUNIT_FILE = path.join(directories.tests, 'xunit.xml');
|
53 |
|
54 | if (args.indexOf('--no-colors') === -1) {
|
55 | args.unshift('--colors');
|
56 | }
|
57 |
|
58 | var command = [];
|
59 |
|
60 | var noCoverageIndex = args.indexOf('--no-coverage');
|
61 | if (noCoverageIndex === -1) {
|
62 |
|
63 | command.push(getBin('istanbul'));
|
64 | command.push('cover');
|
65 |
|
66 |
|
67 | var coberturaIndex = args.indexOf('--cobertura');
|
68 | if (coberturaIndex !== -1) {
|
69 |
|
70 | args.splice(coberturaIndex, 1);
|
71 | command.push('--report cobertura');
|
72 | }
|
73 |
|
74 | command.push('--dir ' + escape(directories.coverage) + ' --');
|
75 | command.push(getBin('_mocha'));
|
76 | } else {
|
77 |
|
78 | args.splice(noCoverageIndex, 1);
|
79 | command.push(getBin('mocha'));
|
80 | }
|
81 |
|
82 | command.push('--reporter ' + escape(require.resolve('spec-xunit-file')));
|
83 | command.push(shellescape(args));
|
84 |
|
85 |
|
86 | shell.exit(shell.exec(command.join(' ')).code);
|
87 | };
|