-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
48 lines (39 loc) · 948 Bytes
/
index.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
var fork = require('child_process').fork;
var mochaPhantomJsPath = require.resolve('mocha-phantomjs-core/mocha-phantomjs-core');
var phantomJsPath = require.resolve('phantomjs/bin/phantomjs');
function runMochaPhantomJS(url, options, callback) {
if (!options) {
options = {};
}
if (!options.config) {
options.config = {};
}
if (typeof callback !== 'function') {
callback = function () {};
}
var args = [
mochaPhantomJsPath,
url,
options.config.reporter || 'spec',
JSON.stringify(options.config)
];
var child = fork(
phantomJsPath,
args, {
stdio: [
'ignore',
options.out || process.stdout,
options.err || process.stderr,
'ipc'
]
});
child.on('error', callback);
child.on('exit', function (code) {
if (code === 0) {
callback();
} else {
callback(new Error(code));
}
});
};
module.exports = runMochaPhantomJS;