forked from jonkemp/node-qunit-phantomjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (60 loc) · 2.32 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
var path = require('path'),
chalk = require('chalk'),
childProcess = require('child_process'),
phantomjs = require('phantomjs'),
binPath = phantomjs.path;
module.exports = function (filepath, options, callback) {
var opt = options || {},
cb = callback || function () {},
runner = './runner.js';
var absolutePath = path.resolve(filepath),
isAbsolutePath = absolutePath.indexOf(filepath) >= 0,
childArgs = [];
childArgs.push(
path.join(__dirname, runner),
(isAbsolutePath ? 'file:///' + absolutePath.replace(/\\/g, '/') : filepath)
);
if ( opt.coverageLocation ) {
childArgs.push( path.resolve(opt.coverageLocation) );
}
var proc = childProcess.execFile(binPath, childArgs, function (err, stdout, stderr) {
console.log('Testing ' + chalk.blue( path.relative(__dirname, filepath) ));
if (stdout) {
try {
var out,
result,
message,
output;
stdout.trim().split('\n').forEach(function(line) {
try{
out = JSON.parse(line.trim());
result = out.result;
message = 'Took ' + result.runtime + ' ms to run ' + result.total + ' tests. ' + result.passed + ' passed, ' + result.failed + ' failed.';
output = result.failed > 0 ? chalk.red(message) : chalk.green(message);
console.log(output);
if(out.exceptions) {
for(var test in out.exceptions) {
console.log('\n' + chalk.red('Test failed') + ': ' + chalk.red(test) + ': \n' + out.exceptions[test].join('\n '));
}
}
} catch(e) {
line = line.trim(); // Trim trailing cr-lf
console.log(line);
}
});
} catch (e) {
this.emit('error', new Error(e));
}
}
if (stderr) {
console.log(stderr);
}
if (err) {
console.log(err);
}
}.bind(this));
proc.on('close', function (code) {
return cb(code);
});
};