-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrunner.js
54 lines (51 loc) · 1.74 KB
/
runner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
var path = require('path');
function indexOfDash(arr) {
for (var i = 0; i < arr.length; i++) {
if (arr[i].indexOf('-') === 0) {
return i;
}
}
return -1;
}
module.exports = {
rewrite: function rewite(argv) {
var result = [], mocha;
// remove the `--mocha path` argument
var args = (function extractMocha(args) {
var mochaIsNext = false;
var filtered = args.filter(function (arg) {
if (arg === '--mocha') {
mochaIsNext = true;
return false;
} else if (mochaIsNext) {
mocha = path.join(arg, '/bin/_mocha');
mochaIsNext = false;
return false;
}
return true;
});
if (!mocha) {
// now we assume there is a mocha package next to this package
mocha = args[1].replace(/^(.*)mocha-for-jetbrains(.*?)$/, '$1mocha$2');
}
return filtered;
}(argv));
result.push(args[0]);
// the second argument is now the real mocha
result.push(mocha);
// where do the intellij added arguments start?
var firstDashIndex = indexOfDash(args);
if (firstDashIndex >= 0) {
if (firstDashIndex === 2) {
// no arguments to add at the end
result = result.concat(args.slice(2, args.length));
} else {
// strip the directory at the end
result = result.concat(args.slice(firstDashIndex, args.length - 1));
}
result = result.concat(args.slice(2, firstDashIndex));
}
return result;
}
};