@@ -52,10 +52,6 @@ const TestResult = {
52
52
Crashed : 'crashed' , // If testrunner crashed due to this test
53
53
} ;
54
54
55
- function isTestFailure ( testResult ) {
56
- return testResult === TestResult . Failed || testResult === TestResult . TimedOut || testResult === TestResult . Crashed ;
57
- }
58
-
59
55
function createHook ( callback , name ) {
60
56
const location = getCallerLocation ( __filename ) ;
61
57
return { name, body : callback , location } ;
@@ -104,6 +100,7 @@ class Test {
104
100
105
101
setSkipped ( skipped ) {
106
102
this . _skipped = skipped ;
103
+ return this ;
107
104
}
108
105
109
106
focused ( ) {
@@ -112,6 +109,7 @@ class Test {
112
109
113
110
setFocused ( focused ) {
114
111
this . _focused = focused ;
112
+ return this ;
115
113
}
116
114
117
115
timeout ( ) {
@@ -120,6 +118,7 @@ class Test {
120
118
121
119
setTimeout ( timeout ) {
122
120
this . _timeout = timeout ;
121
+ return this ;
123
122
}
124
123
125
124
expectation ( ) {
@@ -128,6 +127,7 @@ class Test {
128
127
129
128
setExpectation ( expectation ) {
130
129
this . _expectation = expectation ;
130
+ return this ;
131
131
}
132
132
133
133
repeat ( ) {
@@ -136,14 +136,17 @@ class Test {
136
136
137
137
setRepeat ( repeat ) {
138
138
this . _repeat = repeat ;
139
+ return this ;
139
140
}
140
141
141
142
before ( callback ) {
142
143
this . _hooks . push ( createHook ( callback , 'before' ) ) ;
144
+ return this ;
143
145
}
144
146
145
147
after ( callback ) {
146
148
this . _hooks . push ( createHook ( callback , 'after' ) ) ;
149
+ return this ;
147
150
}
148
151
149
152
hooks ( name ) {
@@ -184,6 +187,7 @@ class Suite {
184
187
185
188
setSkipped ( skipped ) {
186
189
this . _skipped = skipped ;
190
+ return this ;
187
191
}
188
192
189
193
focused ( ) {
@@ -192,6 +196,7 @@ class Suite {
192
196
193
197
setFocused ( focused ) {
194
198
this . _focused = focused ;
199
+ return this ;
195
200
}
196
201
197
202
location ( ) {
@@ -204,6 +209,7 @@ class Suite {
204
209
205
210
setExpectation ( expectation ) {
206
211
this . _expectation = expectation ;
212
+ return this ;
207
213
}
208
214
209
215
repeat ( ) {
@@ -212,22 +218,27 @@ class Suite {
212
218
213
219
setRepeat ( repeat ) {
214
220
this . _repeat = repeat ;
221
+ return this ;
215
222
}
216
223
217
224
beforeEach ( callback ) {
218
225
this . _hooks . push ( createHook ( callback , 'beforeEach' ) ) ;
226
+ return this ;
219
227
}
220
228
221
229
afterEach ( callback ) {
222
230
this . _hooks . push ( createHook ( callback , 'afterEach' ) ) ;
231
+ return this ;
223
232
}
224
233
225
234
beforeAll ( callback ) {
226
235
this . _hooks . push ( createHook ( callback , 'beforeAll' ) ) ;
236
+ return this ;
227
237
}
228
238
229
239
afterAll ( callback ) {
230
240
this . _hooks . push ( createHook ( callback , 'afterAll' ) ) ;
241
+ return this ;
231
242
}
232
243
233
244
hooks ( name ) {
@@ -647,12 +658,13 @@ class TestRunner extends EventEmitter {
647
658
648
659
this . describe = this . _suiteBuilder ( [ ] ) ;
649
660
this . it = this . _testBuilder ( [ ] ) ;
661
+ this . Expectations = { ...TestExpectation } ;
650
662
651
663
if ( installCommonHelpers ) {
652
- this . fdescribe = this . describe . setup ( s => s . setFocused ( true ) ) ;
653
- this . xdescribe = this . describe . setup ( s => s . setSkipped ( true ) ) ;
654
- this . fit = this . it . setup ( t => t . setFocused ( true ) ) ;
655
- this . xit = this . it . setup ( t => t . setSkipped ( true ) ) ;
664
+ this . fdescribe = this . _suiteBuilder ( [ { callback : s => s . setFocused ( true ) , args : [ ] } ] ) ;
665
+ this . xdescribe = this . _suiteBuilder ( [ { callback : s => s . setSkipped ( true ) , args : [ ] } ] ) ;
666
+ this . fit = this . _testBuilder ( [ { callback : t => t . setFocused ( true ) , args : [ ] } ] ) ;
667
+ this . xit = this . _testBuilder ( [ { callback : t => t . setSkipped ( true ) , args : [ ] } ] ) ;
656
668
}
657
669
}
658
670
@@ -666,10 +678,9 @@ class TestRunner extends EventEmitter {
666
678
callback ( ...suiteArgs ) ;
667
679
this . _suites . push ( suite ) ;
668
680
this . _currentSuite = suite . parentSuite ( ) ;
681
+ return suite ;
669
682
} , {
670
683
get : ( obj , prop ) => {
671
- if ( prop === 'setup' )
672
- return callback => this . _suiteBuilder ( [ ...callbacks , { callback, args : [ ] } ] ) ;
673
684
if ( this . _suiteModifiers . has ( prop ) )
674
685
return ( ...args ) => this . _suiteBuilder ( [ ...callbacks , { callback : this . _suiteModifiers . get ( prop ) , args } ] ) ;
675
686
if ( this . _suiteAttributes . has ( prop ) )
@@ -687,10 +698,9 @@ class TestRunner extends EventEmitter {
687
698
for ( const { callback, args } of callbacks )
688
699
callback ( test , ...args ) ;
689
700
this . _tests . push ( test ) ;
701
+ return test ;
690
702
} , {
691
703
get : ( obj , prop ) => {
692
- if ( prop === 'setup' )
693
- return callback => this . _testBuilder ( [ ...callbacks , { callback, args : [ ] } ] ) ;
694
704
if ( this . _testModifiers . has ( prop ) )
695
705
return ( ...args ) => this . _testBuilder ( [ ...callbacks , { callback : this . _testModifiers . get ( prop ) , args } ] ) ;
696
706
if ( this . _testAttributes . has ( prop ) )
0 commit comments