@@ -42,6 +42,14 @@ module.exports = function (options, webDriverUrl, autoStartServer, webDriver) {
42
42
gutil . log ( PLUGIN_NAME + ' - We have the config file to the following path: ' + configFilePath ) ;
43
43
args . unshift ( configFilePath ) ;
44
44
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
+
45
53
// Start the Web Driver server
46
54
try {
47
55
if ( autoStartServer ) {
@@ -50,14 +58,13 @@ module.exports = function (options, webDriverUrl, autoStartServer, webDriver) {
50
58
gutil . log ( PLUGIN_NAME + ' - We will run the Protractor engine' ) ;
51
59
52
60
webDriver
53
- . runProtractorAndWait ( args , ( ) => {
61
+ . runProtractorAndWait ( args , ( code ) => {
54
62
gutil . log ( PLUGIN_NAME + ' - We will stop the Protractor engine' ) ;
55
63
56
64
if ( this ) {
57
65
try {
58
66
stopServer ( ) ;
59
- this . emit ( 'end' ) ;
60
-
67
+ finalize ( this , code ) ;
61
68
} catch ( err ) {
62
69
this . emit ( 'error' , new PluginError ( PLUGIN_NAME , err ) ) ;
63
70
}
@@ -77,14 +84,7 @@ module.exports = function (options, webDriverUrl, autoStartServer, webDriver) {
77
84
} else {
78
85
// Just run protractor
79
86
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 ) ;
88
88
} ) ;
89
89
}
90
90
0 commit comments