import Suite from "../suite" ; import * as errors from "../errors" ; const { createMissingArgumentError , createUnsupportedError , createForbiddenExclusivityError , } = errors ; private param { Suite [ ] } suites param { Context } context param { Mocha } mocha return { Object } export default function ( suites , context , mocha ) { context . data = [ ] ; private param { Suite } suite returns { boolean } function shouldBeTested ( suite ) { return ( ! mocha . options . grep || ( mocha . options . grep && mocha . options . grep . test ( suite . fullTitle ( ) ) && ! mocha . options . invert ) ) ; } return { param { Suite } suite return { Function } runWithSuite : function runWithSuite ( suite ) { return function run ( ) { suite . run ( ) ; } ; } , param { string } name param { Function } fn before : function ( name , fn ) { suites [ 0 ] . beforeAll ( name , fn ) ; } , param { string } name param { Function } fn after : function ( name , fn ) { suites [ 0 ] . afterAll ( name , fn ) ; } , param { string } name param { Function } fn beforeEach : function ( name , fn ) { suites [ 0 ] . beforeEach ( name , fn ) ; } , param { string } name param { Function } fn afterEach : function ( name , fn ) { suites [ 0 ] . afterEach ( name , fn ) ; } , suite : { param { Object } opts returns { Suite } only : function only ( opts ) { if ( mocha . options . forbidOnly ) { throw createForbiddenExclusivityError ( mocha ) ; } opts . isOnly = true ; return this . create ( opts ) ; } , param { Object } opts returns { Suite } skip : function skip ( opts ) { opts . pending = true ; return this . create ( opts ) ; } , param { Object } options param { string } opts . title param { Function } opts . fn param { boolean } opts . pending param { string } opts . file param { boolean } opts . isOnly returns { Suite } create : function create ( options ) { context . data . push ( options ) ; const suite = Suite . create ( suites [ 0 ] , options . title ) ; suite . handle = options . handle || "<anonymous>" ; suite . description = options . description || "<unavailable>" ; suite . tags = options . tags || [ ] ; suite . pending = Boolean ( options . pending ) ; suite . file = options . file ; suites . unshift ( suite ) ; if ( options . isOnly ) { suite . markOnly ( ) ; } if ( suite . pending && mocha . options . forbidPending && shouldBeTested ( suite ) ) { throw createUnsupportedError ( "Pending test forbidden" ) ; } if ( typeof options . fn === "function" ) { options . fn . call ( suite ) ; suites . shift ( ) ; } else if ( typeof options . fn === "undefined" && ! suite . pending ) { throw createMissingArgumentError ( 'Suite "' + suite . fullTitle ( ) + '" was defined but no callback was supplied. ' + "Supply a callback or explicitly skip the suite." , "callback" , "function" ) ; } else if ( ! options . fn && suite . pending ) { suites . shift ( ) ; } return suite ; } , } , test : { param { Object } mocha param { Function } test returns { * } only : function ( mocha , test ) { if ( mocha . options . forbidOnly ) { throw createForbiddenExclusivityError ( mocha ) ; } test . markOnly ( ) ; return test ; } , param { string } title skip : function ( title ) { context . test ( title ) ; } , } , } ; }