@@ -57,7 +57,8 @@ var Suite = require('./vows/suite').Suite;
57
57
//
58
58
function addVow ( vow ) {
59
59
var batch = vow . batch ,
60
- event = vow . binding . context . event || 'success' ;
60
+ event = vow . binding . context . event || 'success'
61
+ self = this ;
61
62
62
63
batch . total ++ ;
63
64
batch . vows . push ( vow ) ;
@@ -66,8 +67,8 @@ function addVow(vow) {
66
67
this . on ( event , function ( ) {
67
68
var args = Array . prototype . slice . call ( arguments ) ;
68
69
// If the vow is a sub-event then we know it is an
69
- // emited event. So I don't muck with the arguments
70
- // However the legacey behavior:
70
+ // emitted event. So I don't muck with the arguments
71
+ // However the legacy behavior:
71
72
// If the callback is expecting two or more arguments,
72
73
// pass the error as the first (null) and the result after.
73
74
if ( ! ( this . ctx && this . ctx . isEvent ) &&
@@ -95,7 +96,6 @@ function addVow(vow) {
95
96
this . _vowsEmitedEvents . hasOwnProperty ( event ) ) {
96
97
// make sure no one is messing with me
97
98
if ( Array . isArray ( this . _vowsEmitedEvents [ event ] ) ) {
98
- var self = this ;
99
99
// I don't think I need to optimize for one event,
100
100
// I think it is more important to make sure I check the vow n times
101
101
self . _vowsEmitedEvents [ event ] . forEach ( function ( args ) {
@@ -115,6 +115,17 @@ function addVow(vow) {
115
115
return output ( 'pending' ) ;
116
116
}
117
117
118
+ if ( vow . binding . context . isEvent && vow . binding . context . after ) {
119
+ var after = vow . binding . context . after ;
120
+ // only need to check order. I won't get here if the after event
121
+ // has never been emitted
122
+ if ( self . _vowsEmitedEventsOrder . indexOf ( after ) >
123
+ self . _vowsEmitedEventsOrder . indexOf ( event ) ) {
124
+ output ( 'broken' , event + ' emitted before ' + after ) ;
125
+ return ;
126
+ }
127
+ }
128
+
118
129
// Run the test, and try to catch `AssertionError`s and other exceptions;
119
130
// increment counters accordingly.
120
131
try {
@@ -210,6 +221,7 @@ vows.describe = function (subject) {
210
221
// just in case someone emit's before I get to it
211
222
this . options . Emitter . prototype . emit = function ( event ) {
212
223
this . _vowsEmitedEvents = this . _vowsEmitedEvents || { } ;
224
+ this . _vowsEmitedEventsOrder = this . _vowsEmitedEventsOrder || [ ] ;
213
225
// slice off the event
214
226
var args = Array . prototype . slice . call ( arguments , 1 ) ;
215
227
// if multiple events are fired, add or push
@@ -218,6 +230,9 @@ vows.describe = function (subject) {
218
230
} else {
219
231
this . _vowsEmitedEvents [ event ] = [ args ] ;
220
232
}
233
+
234
+ // push the event onto a stack so I have an order
235
+ this . _vowsEmitedEventsOrder . push ( event ) ;
221
236
return oldEmit . apply ( this , arguments ) ;
222
237
}
223
238
this . suites . push ( suite ) ;
0 commit comments