File tree Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Expand file tree Collapse file tree 3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -79,3 +79,4 @@ module.exports.after = runner.addAfterHook.bind(runner);
79
79
module . exports . beforeEach = runner . addBeforeEachHook . bind ( runner ) ;
80
80
module . exports . afterEach = runner . addAfterEachHook . bind ( runner ) ;
81
81
module . exports . skip = runner . addSkippedTest . bind ( runner ) ;
82
+ module . exports . only = runner . addOnlyTest . bind ( runner ) ;
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ function Runner(opts) {
32
32
this . tests = {
33
33
concurrent : [ ] ,
34
34
serial : [ ] ,
35
+ only : [ ] ,
35
36
before : [ ] ,
36
37
after : [ ] ,
37
38
beforeEach : [ ] ,
@@ -97,6 +98,11 @@ Runner.prototype.addSkippedTest = function (title, cb) {
97
98
this . tests . concurrent . push ( test ) ;
98
99
} ;
99
100
101
+ Runner . prototype . addOnlyTest = function ( title , cb ) {
102
+ this . stats . testCount ++ ;
103
+ this . tests . only . push ( new Test ( title , cb ) ) ;
104
+ } ;
105
+
100
106
Runner . prototype . _runTestWithHooks = function ( test ) {
101
107
if ( test . skip ) {
102
108
this . _addTestResult ( test ) ;
@@ -203,16 +209,20 @@ Runner.prototype.run = function () {
203
209
}
204
210
} )
205
211
. then ( function ( ) {
206
- return self . serial ( tests . serial ) ;
212
+ return self . concurrent ( tests . only ) ;
213
+ } )
214
+ . then ( function ( ) {
215
+ return tests . only . length ? [ ] : self . serial ( tests . serial ) ;
207
216
} )
208
217
. then ( function ( ) {
209
- return self . concurrent ( tests . concurrent ) ;
218
+ return tests . only . length ? [ ] : self . concurrent ( tests . concurrent ) ;
210
219
} )
211
220
. then ( function ( ) {
212
221
return eachSeries ( tests . after , self . _runTest . bind ( self ) ) ;
213
222
} )
214
223
. catch ( noop )
215
224
. then ( function ( ) {
225
+ stats . testCount = tests . only . length ? tests . only . length : stats . testCount ;
216
226
stats . passCount = stats . testCount - stats . failCount ;
217
227
} ) ;
218
228
} ;
Original file line number Diff line number Diff line change @@ -1034,6 +1034,30 @@ test('skip test', function (t) {
1034
1034
} ) ;
1035
1035
} ) ;
1036
1036
1037
+ test ( 'only test' , function ( t ) {
1038
+ t . plan ( 3 ) ;
1039
+
1040
+ var runner = new Runner ( ) ;
1041
+ var arr = [ ] ;
1042
+
1043
+ runner . addTest ( function ( a ) {
1044
+ arr . push ( 'a' ) ;
1045
+ a . end ( ) ;
1046
+ } ) ;
1047
+
1048
+ runner . addOnlyTest ( function ( a ) {
1049
+ arr . push ( 'b' ) ;
1050
+ a . end ( ) ;
1051
+ } ) ;
1052
+
1053
+ runner . run ( ) . then ( function ( ) {
1054
+ t . is ( runner . stats . testCount , 1 ) ;
1055
+ t . is ( runner . stats . passCount , 1 ) ;
1056
+ t . same ( arr , [ 'b' ] ) ;
1057
+ t . end ( ) ;
1058
+ } ) ;
1059
+ } ) ;
1060
+
1037
1061
test ( 'ES2015 support' , function ( t ) {
1038
1062
t . plan ( 1 ) ;
1039
1063
You can’t perform that action at this time.
0 commit comments