@@ -19,7 +19,6 @@ function seal(fn) {
19
19
} ;
20
20
} ;
21
21
22
-
23
22
/**
24
23
* Wraps a function so it runs inside a webdriver.promise.ControlFlow and
25
24
* waits for the flow to complete before continuing.
@@ -28,6 +27,20 @@ function seal(fn) {
28
27
*/
29
28
function wrapInControlFlow ( globalFn ) {
30
29
return function ( ) {
30
+ var driverError = new Error ( ) ;
31
+ driverError . stack = driverError . stack . replace ( / + a t .+ j a s m i n e w d .+ \n / , '' ) ;
32
+
33
+ function asyncTestFn ( fn ) {
34
+ return function ( done ) {
35
+ var thing = flow . execute ( function ( ) {
36
+ fn . call ( jasmine . getEnv ( ) . currentSpec ) ;
37
+ } ) . then ( seal ( done ) , function ( e ) {
38
+ e . stack = driverError . stack ;
39
+ done ( e ) ;
40
+ } ) ;
41
+ } ;
42
+ } ;
43
+
31
44
switch ( arguments . length ) {
32
45
case 1 :
33
46
globalFn ( asyncTestFn ( arguments [ 0 ] ) ) ;
@@ -47,14 +60,6 @@ function wrapInControlFlow(globalFn) {
47
60
throw Error ( 'Invalid # arguments: ' + arguments . length ) ;
48
61
}
49
62
} ;
50
-
51
- function asyncTestFn ( fn ) {
52
- return function ( done ) {
53
- flow . execute ( function ( ) {
54
- fn . call ( jasmine . getEnv ( ) . currentSpec ) ;
55
- } ) . then ( seal ( done ) , done ) ;
56
- } ;
57
- } ;
58
63
} ;
59
64
60
65
global . it = wrapInControlFlow ( global . it ) ;
@@ -73,6 +78,8 @@ global.afterEach = wrapInControlFlow(global.afterEach);
73
78
function wrapMatcher ( matcher , actualPromise , not ) {
74
79
return function ( ) {
75
80
var originalArgs = arguments ;
81
+ var matchError = new Error ( "Failed expectation" ) ;
82
+ matchError . stack = matchError . stack . replace ( / + a t .+ j a s m i n e w d .+ \n / , '' ) ;
76
83
actualPromise . then ( function ( actual ) {
77
84
var expected = originalArgs [ 0 ] ;
78
85
if ( expected instanceof webdriver . promise . Promise ) {
@@ -92,7 +99,14 @@ function wrapMatcher(matcher, actualPromise, not) {
92
99
if ( not ) {
93
100
expectation = expectation . not ;
94
101
}
102
+ var origFn = expectation . spec . addMatcherResult ;
103
+ var error = matchError ;
104
+ expectation . spec . addMatcherResult = function ( result ) {
105
+ result . trace = error ;
106
+ jasmine . Spec . prototype . addMatcherResult . call ( this , result ) ;
107
+ }
95
108
expectation [ matcher ] . apply ( expectation , originalArgs ) ;
109
+ expectation . spec . addMatcherResult = origFn ;
96
110
}
97
111
} ) ;
98
112
} ;
0 commit comments