Skip to content

Commit 77678df

Browse files
authored
Merge pull request #45 from zbjornson/master
Emit errors if there are errors in autoStartServer mode
2 parents 70ab711 + b0b0044 commit 77678df

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

gulp-angular-protractor/gulp-stream.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ module.exports = function (options, webDriverUrl, autoStartServer, webDriver) {
4242
gutil.log(PLUGIN_NAME + ' - We have the config file to the following path: ' + configFilePath);
4343
args.unshift(configFilePath);
4444

45+
function finalize(ctx, code) {
46+
if (code) {
47+
ctx.emit('error', new PluginError(PLUGIN_NAME, 'protractor exited with code ' + code));
48+
} else {
49+
ctx.emit('end');
50+
}
51+
}
52+
4553
// Start the Web Driver server
4654
try {
4755
if (autoStartServer) {
@@ -50,14 +58,13 @@ module.exports = function (options, webDriverUrl, autoStartServer, webDriver) {
5058
gutil.log(PLUGIN_NAME + ' - We will run the Protractor engine');
5159

5260
webDriver
53-
.runProtractorAndWait(args, () => {
61+
.runProtractorAndWait(args, (code) => {
5462
gutil.log(PLUGIN_NAME + ' - We will stop the Protractor engine');
5563

5664
if (this) {
5765
try {
5866
stopServer();
59-
this.emit('end');
60-
67+
finalize(this, code);
6168
} catch (err) {
6269
this.emit('error', new PluginError(PLUGIN_NAME, err));
6370
}
@@ -77,14 +84,7 @@ module.exports = function (options, webDriverUrl, autoStartServer, webDriver) {
7784
} else {
7885
// Just run protractor
7986
webDriver.runProtractorAndWait(args, (code) => {
80-
if (this) {
81-
if (code) {
82-
this.emit('error', new PluginError(PLUGIN_NAME, 'protractor exited with code ' + code));
83-
84-
} else {
85-
this.emit('end');
86-
}
87-
}
87+
if (this) finalize(this, code);
8888
});
8989
}
9090

0 commit comments

Comments
 (0)