UNPKG

2.05 kBJavaScriptView Raw
1var es = require('event-stream');
2var path = require('path');
3var child_process = require('child_process');
4var async = require('async');
5var dargs = require('dargs');
6var PluginError = require('gulp-util').PluginError;
7
8var protractor = function(options) {
9 var files = [],
10 child, args;
11
12 options = options || {};
13 args = options.args || {};
14
15 if (!options.configFile) {
16 this.emit('error', new PluginError('gulp-protractor', 'Please specify the protractor config file'));
17 }
18 return es.through(function(file) {
19 files.push(file.path);
20 }, function() {
21 var stream = this;
22
23 // Attach Files, if any
24 if (files.length) {
25 args.specs = files.join(',');
26 }
27
28 // Pass in args
29 args = dargs(args, ['seleniumAddress', 'seleniumServerJar', 'seleniumPort', 'rootElement', 'stackTrace', 'stackTrace']);
30
31 // Pass in the config file
32 args.unshift(options.configFile);
33
34 // Attach debug if we have to
35 if(options.debug) {
36 args.unshift('debug');
37 }
38
39 child = child_process.spawn(path.resolve('./node_modules/.bin/protractor'), args, {
40 stdio: 'inherit'
41 }).on('exit', function(code) {
42 if (child) {
43 child.kill();
44 }
45 if (stream) {
46 if (code) {
47 stream.emit('error', new PluginError('gulp-protractor', 'protractor exited with code ' + code));
48 }
49 else {
50 stream.emit('end');
51 }
52 }
53 });
54 });
55};
56
57var webdriver_update = function(cb) {
58 child_process.spawn('./node_modules/.bin/webdriver-manager', ['update'], {
59 stdio: 'inherit'
60 }).once('close', cb);
61};
62
63var webdriver_start = function(cb) {
64 var child = child_process.spawn('./node_modules/.bin/webdriver-manager', ['start'], {
65 stdio: 'pipe'
66 });
67
68 child.on('close', cb);
69
70 child.stdout.on('data', function(data) {
71 var sentinal = 'Started org.openqa.jetty.jetty.Server';
72 console.log(data.toString());
73 if (data.toString().indexOf(sentinal) !== -1) {
74 cb(null, child);
75 }
76 });
77};
78
79module.exports = {
80 protractor: protractor,
81 webdriver: function(cb) {
82 async.series([webdriver_update, webdriver_start], cb);
83 }
84};
\No newline at end of file