@@ -4,12 +4,18 @@ var protractor = require('./protractor'),
4
4
path = require ( 'path' ) ,
5
5
util = require ( 'util' ) ,
6
6
fs = require ( 'fs' ) ,
7
- q = require ( 'q' ) ;
7
+ q = require ( 'q' ) ,
8
+ EventEmitter = require ( 'events' ) . EventEmitter ;
8
9
9
10
/*
10
11
* Runner is responsible for starting the execution of a test run and triggering
11
12
* setup, teardown, managing config, etc through its various dependencies.
12
13
*
14
+ * The Protractor Runner is a node EventEmitter with the following events:
15
+ * - testPass
16
+ * - testFail
17
+ * - testsDone
18
+ *
13
19
* @param {Object } config
14
20
* @constructor
15
21
*/
@@ -42,6 +48,8 @@ var Runner = function(config) {
42
48
this . loadDriverProvider_ ( config ) ;
43
49
} ;
44
50
51
+ util . inherits ( Runner , EventEmitter ) ;
52
+
45
53
46
54
/**
47
55
* Execute the Runner's test cases through Jasmine.
@@ -55,6 +63,31 @@ Runner.prototype.runJasmine_ = function(specs, done) {
55
63
self = this ;
56
64
57
65
require ( '../jasminewd' ) ;
66
+
67
+ var RunnerReporter = function ( emitter ) {
68
+ this . emitter = emitter ;
69
+ } ;
70
+
71
+ RunnerReporter . prototype . reportRunnerStarting = function ( ) { } ;
72
+ RunnerReporter . prototype . reportRunnerResults = function ( ) { } ;
73
+ RunnerReporter . prototype . reportSuiteResults = function ( ) { } ;
74
+ RunnerReporter . prototype . reportSpecStarting = function ( ) { } ;
75
+ RunnerReporter . prototype . reportSpecResults = function ( spec ) {
76
+ if ( spec . results ( ) . passed ( ) ) {
77
+ this . emitter . emit ( 'testPass' ) ;
78
+ } else {
79
+ this . emitter . emit ( 'testFail' ) ;
80
+ }
81
+ } ;
82
+ RunnerReporter . prototype . log = function ( ) { } ;
83
+
84
+ // On timeout, the flow should be reset. This will prevent webdriver tasks
85
+ // from overflowing into the next test and causing it to fail or timeout
86
+ // as well. This is done in the reporter instead of an afterEach block
87
+ // to ensure that it runs after any afterEach() blocks with webdriver tasks
88
+ // get to complete first.
89
+ jasmine . getEnv ( ) . addReporter ( new RunnerReporter ( this ) ) ;
90
+
58
91
webdriver . promise . controlFlow ( ) . execute ( function ( ) {
59
92
self . runTestPreparers_ ( ) ;
60
93
} , 'run test preparers' ) . then ( function ( ) {
@@ -101,6 +134,14 @@ Runner.prototype.runMocha_ = function(specs, done) {
101
134
global . it . skip = global . xit = mochaAdapters . xit ;
102
135
} ) ;
103
136
137
+ mocha . suite . on ( 'pass' , function ( ) {
138
+ this . emit ( 'testPass' ) ;
139
+ } ) ;
140
+
141
+ mocha . suite . on ( 'fail' , function ( ) {
142
+ this . emit ( 'testFail' ) ;
143
+ } ) ;
144
+
104
145
mocha . loadFiles ( ) ;
105
146
106
147
webdriver . promise . controlFlow ( ) . execute ( function ( ) {
@@ -132,6 +173,7 @@ Runner.prototype.runMocha_ = function(specs, done) {
132
173
* @param done A callback for when tests are finished.
133
174
*/
134
175
Runner . prototype . runCucumber_ = function ( specs , done ) {
176
+ // TODO - add the event interface for cucumber.
135
177
var Cucumber = require ( 'cucumber' ) ,
136
178
self = this ,
137
179
execOptions = [ 'node' , 'node_modules/.bin/cucumber-js' ] ,
@@ -371,6 +413,7 @@ Runner.prototype.run = function() {
371
413
372
414
// 3) Teardown
373
415
} ) . then ( function ( result ) {
416
+ self . emit ( 'testsDone' , result ) ;
374
417
testResult = result ;
375
418
if ( self . driverprovider_ . updateJob ) {
376
419
return self . driverprovider_ . updateJob ( {
0 commit comments