@@ -3,7 +3,8 @@ var protractor = require('./protractor'),
3
3
util = require ( 'util' ) ,
4
4
q = require ( 'q' ) ,
5
5
EventEmitter = require ( 'events' ) . EventEmitter ,
6
- helper = require ( './util' ) ;
6
+ helper = require ( './util' ) ,
7
+ Plugins = require ( './plugins' ) ;
7
8
8
9
/*
9
10
* Runner is responsible for starting the execution of a test run and triggering
@@ -191,9 +192,11 @@ Runner.prototype.run = function() {
191
192
var self = this ,
192
193
driver ,
193
194
specs ,
194
- testPassed ;
195
+ testPassed ,
196
+ plugins ;
195
197
196
198
specs = this . config_ . specs ;
199
+ plugins = new Plugins ( this . config_ ) ;
197
200
198
201
if ( ! specs . length ) {
199
202
throw new Error ( 'Spec patterns did not match any files.' ) ;
@@ -225,10 +228,12 @@ Runner.prototype.run = function() {
225
228
} ) . then ( function ( ) {
226
229
return driver . manage ( ) . timeouts ( )
227
230
. setScriptTimeout ( self . config_ . allScriptsTimeout ) ;
228
- // 3) Execute test cases
231
+ // 3) Setup globals and plugins
229
232
} ) . then ( function ( ) {
230
233
self . setupGlobals_ . bind ( self ) ( driver ) ;
231
-
234
+ return plugins . setup ( ) ;
235
+ // 4) Execute test cases
236
+ } ) . then ( function ( ) {
232
237
// Do the framework setup here so that jasmine and mocha globals are
233
238
// available to the onPrepare function.
234
239
var frameworkPath = '' ;
@@ -245,7 +250,14 @@ Runner.prototype.run = function() {
245
250
') is not a valid framework.' ) ;
246
251
}
247
252
return require ( frameworkPath ) . run ( self , specs ) ;
248
- // 4) Teardown
253
+ // 5) Teardown plugins
254
+ } ) . then ( function ( result ) {
255
+ var deferred = q . defer ( ) ;
256
+ plugins . teardown ( ) . then ( function ( ) {
257
+ deferred . resolve ( result ) ;
258
+ } ) ;
259
+ return deferred . promise ;
260
+ // 6) Teardown
249
261
} ) . then ( function ( result ) {
250
262
self . emit ( 'testsDone' , result ) ;
251
263
testPassed = result . failedCount === 0 ;
@@ -258,7 +270,7 @@ Runner.prototype.run = function() {
258
270
} else {
259
271
return self . driverprovider_ . teardownEnv ( ) ;
260
272
}
261
- // 5 ) Exit process
273
+ // 7 ) Exit process
262
274
} ) . then ( function ( ) {
263
275
var exitCode = testPassed ? 0 : 1 ;
264
276
return self . exit_ ( exitCode ) ;
0 commit comments