-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
64 lines (53 loc) · 2.24 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
'use strict';
var path = require('path');
var childProcess = require('child_process');
var gutil = require('gulp-util');
var through = require('through2');
var phantomjs = require('phantomjs-prebuilt');
var binPath = phantomjs.path;
module.exports = function(phantomArgs){
return through.obj(function (file, enc, cb) {
var filepath = file.path
var isWindows = /^win/.test(process.platform);
// Horrible workaround since Windows-style paths ('c:\foo\bar') seem to break PhantomJS
if(isWindows) {
var mangledpath = file.path.split(path.sep)
mangledpath[0] = ''
filepath = mangledpath.join('/')
}
var childArgs = [
path.join(__dirname, 'jasmine2-runner.js'),
filepath
];
if(phantomArgs) {
if(typeof phantomArgs === 'string') {
childArgs.unshift(phantomArgs)
} else if(Object.prototype.toString.call(phantomArgs) == '[object Array]') {
phantomArgs.concat(childArgs)
} else {
this.emit('error', new gutil.PluginError('gulp-jasmine2-phantomjs', 'provided parameter must be string or an array of strings'));
}
}
if (file.isNull()) {
this.push(file);
return cb();
}
childProcess.execFile(binPath, childArgs, function(err, stdout, stderr) {
gutil.log('Start running spec file: ', file.path)
gutil.log('PhantomJS path: ', binPath);
console.log(stdout);
if (stderr !== '') {
gutil.log('gulp-jasmine2-phantomjs: Failed to open test runner ' + gutil.colors.blue(file.relative));
gutil.log(gutil.colors.red('error: '), stderr);
this.emit('error', new gutil.PluginError('gulp-jasmine2-phantomjs', stderr));
}
if (err !== null) {
gutil.log('gulp-jasmine2-phantomjs: ' + gutil.colors.red("\u2716 ") + 'Assertions failed in ' + gutil.colors.blue(file.relative));
this.emit('error', new gutil.PluginError('gulp-jasmine2-phantomjs', err));
}
this.push(file);
this.emit('end');
return cb();
}.bind(this));
});
};