@@ -41,10 +41,6 @@ function Test(title, fn) {
41
41
if ( this . title === 'callee$0$0' ) {
42
42
this . title = '[anonymous]' ;
43
43
}
44
-
45
- Object . keys ( Test . prototype ) . forEach ( function ( key ) {
46
- this [ key ] = this [ key ] . bind ( this ) ;
47
- } , this ) ;
48
44
}
49
45
50
46
module . exports = Test ;
@@ -53,33 +49,6 @@ Test.prototype._assert = function () {
53
49
this . assertCount ++ ;
54
50
} ;
55
51
56
- // patch assert methods to increase assert count and store errors
57
- Object . keys ( assert ) . forEach ( function ( el ) {
58
- Test . prototype [ el ] = function ( ) {
59
- var self = this ;
60
-
61
- try {
62
- var fn = assert [ el ] . apply ( assert , arguments ) ;
63
-
64
- fn = observableToPromise ( fn ) ;
65
-
66
- if ( isPromise ( fn ) ) {
67
- return Promise . resolve ( fn )
68
- . catch ( function ( err ) {
69
- self . _setAssertError ( err ) ;
70
- } )
71
- . finally ( function ( ) {
72
- self . _assert ( ) ;
73
- } ) ;
74
- }
75
- } catch ( err ) {
76
- this . _setAssertError ( err ) ;
77
- }
78
-
79
- this . _assert ( ) ;
80
- } ;
81
- } ) ;
82
-
83
52
Test . prototype . _setAssertError = function ( err ) {
84
53
if ( this . assertError !== undefined ) {
85
54
return ;
@@ -128,7 +97,7 @@ Test.prototype.run = function () {
128
97
var ret ;
129
98
130
99
try {
131
- ret = this . fn ( this ) ;
100
+ ret = this . fn ( this . _publicApi ( ) ) ;
132
101
} catch ( err ) {
133
102
this . _setAssertError ( err ) ;
134
103
this . exit ( ) ;
@@ -171,7 +140,7 @@ Test.prototype.run = function () {
171
140
Object . defineProperty ( Test . prototype , 'end' , {
172
141
get : function ( ) {
173
142
if ( this . metadata . callback ) {
174
- return this . _end ;
143
+ return this . _end . bind ( this ) ;
175
144
}
176
145
throw new Error ( 't.end is not supported in this context. To use t.end as a callback, you must use "callback mode" via `test.cb(testName, fn)` ' ) ;
177
146
}
@@ -230,3 +199,66 @@ Test.prototype.exit = function () {
230
199
} ) ;
231
200
}
232
201
} ;
202
+
203
+ Test . prototype . _publicApi = function ( ) {
204
+ var self = this ;
205
+ var api = { } ;
206
+
207
+ // Getters
208
+ [
209
+ 'assertCount' ,
210
+ 'title' ,
211
+ 'end' ,
212
+ '_capt' ,
213
+ '_expr'
214
+ ]
215
+ . forEach ( function ( name ) {
216
+ Object . defineProperty ( api , name , {
217
+ enumerable : ! / ^ _ / . test ( name ) ,
218
+ get ( ) {
219
+ return self [ name ] ;
220
+ }
221
+ } ) ;
222
+ } ) ;
223
+
224
+ // Get / Set
225
+ Object . defineProperty ( api , 'context' , {
226
+ enumerable : true ,
227
+ get ( ) {
228
+ return self . context ;
229
+ } ,
230
+ set ( context ) {
231
+ self . context = context ;
232
+ }
233
+ } ) ;
234
+
235
+ // Bound Functions
236
+ api . plan = this . plan . bind ( this ) ;
237
+
238
+ // Patched assert methods: increase assert count and store errors.
239
+ Object . keys ( assert ) . forEach ( function ( el ) {
240
+ api [ el ] = function ( ) {
241
+ try {
242
+ var fn = assert [ el ] . apply ( assert , arguments ) ;
243
+
244
+ fn = observableToPromise ( fn ) ;
245
+
246
+ if ( isPromise ( fn ) ) {
247
+ return Promise . resolve ( fn )
248
+ . catch ( function ( err ) {
249
+ self . _setAssertError ( err ) ;
250
+ } )
251
+ . finally ( function ( ) {
252
+ self . _assert ( ) ;
253
+ } ) ;
254
+ }
255
+ } catch ( err ) {
256
+ self . _setAssertError ( err ) ;
257
+ }
258
+
259
+ self . _assert ( ) ;
260
+ } ;
261
+ } ) ;
262
+
263
+ return api ;
264
+ } ;
0 commit comments