forked from webdriverio-boneyard/gulp-webdriver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (46 loc) · 1.64 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
'use strict';
var path = require('path'),
fs = require('fs'),
through = require('through2'),
dargs = require('dargs'),
gutil = require('gulp-util'),
spawn = require('child_process').spawn,
deepmerge = require('deepmerge');
module.exports = function(options) {
return through.obj(function(file, enc, done) {
var stream = this,
configFile = file.path,
isWin = /^win/.test(process.platform),
wdioBin = require.resolve(path.join('webdriverio', 'bin', isWin ? 'wdio.cmd' : 'wdio'));
var opts = deepmerge({
wdioBin: wdioBin
}, options || {});
/**
* check webdriverio dependency
*/
if (!fs.existsSync(opts.wdioBin)) {
return this.emit('error', new gutil.PluginError('gulp-webdriver', 'Haven\'t found the WebdriverIO test runner', {
showStack: false
}));
}
var args = process.execArgv.concat([configFile]).concat(dargs(opts, {
excludes: ['wdioBin'],
keepCamelCase: true
}));
gutil.log('spawn wdio with these attributes:\n', args.join('\n'));
var wdio = spawn(opts.wdioBin, args, {
stdio: 'inherit'
});
wdio.on('exit', function(code) {
gutil.log('wdio testrunner finished with exit code', code);
if (code !== 0) {
stream.emit('error', new gutil.PluginError('gulp-webdriver', 'wdio exited with code ' + code, {
showStack: false
}));
}
done();
done = null;
});
return stream;
});
};