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);
7979module . exports . beforeEach = runner . addBeforeEachHook . bind ( runner ) ;
8080module . exports . afterEach = runner . addAfterEachHook . bind ( runner ) ;
8181module . 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) {
3232 this . tests = {
3333 concurrent : [ ] ,
3434 serial : [ ] ,
35+ only : [ ] ,
3536 before : [ ] ,
3637 after : [ ] ,
3738 beforeEach : [ ] ,
@@ -97,6 +98,11 @@ Runner.prototype.addSkippedTest = function (title, cb) {
9798 this . tests . concurrent . push ( test ) ;
9899} ;
99100
101+ Runner . prototype . addOnlyTest = function ( title , cb ) {
102+ this . stats . testCount ++ ;
103+ this . tests . only . push ( new Test ( title , cb ) ) ;
104+ } ;
105+
100106Runner . prototype . _runTestWithHooks = function ( test ) {
101107 if ( test . skip ) {
102108 this . _addTestResult ( test ) ;
@@ -203,16 +209,20 @@ Runner.prototype.run = function () {
203209 }
204210 } )
205211 . 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 ) ;
207216 } )
208217 . then ( function ( ) {
209- return self . concurrent ( tests . concurrent ) ;
218+ return tests . only . length ? [ ] : self . concurrent ( tests . concurrent ) ;
210219 } )
211220 . then ( function ( ) {
212221 return eachSeries ( tests . after , self . _runTest . bind ( self ) ) ;
213222 } )
214223 . catch ( noop )
215224 . then ( function ( ) {
225+ stats . testCount = tests . only . length ? tests . only . length : stats . testCount ;
216226 stats . passCount = stats . testCount - stats . failCount ;
217227 } ) ;
218228} ;
Original file line number Diff line number Diff line change @@ -1034,6 +1034,30 @@ test('skip test', function (t) {
10341034 } ) ;
10351035} ) ;
10361036
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+
10371061test ( 'ES2015 support' , function ( t ) {
10381062 t . plan ( 1 ) ;
10391063
You can’t perform that action at this time.
0 commit comments