@@ -18,7 +18,7 @@ import DataTable from "./data_table";
1818
1919import {
2020 assignRegistry ,
21- freeRegistry ,
21+ freeRegistry , getRegistry ,
2222 IHook ,
2323 MissingDefinitionError ,
2424 Registry ,
@@ -268,12 +268,17 @@ function createFeature(context: CompositionContext, feature: messages.Feature) {
268268 describe ( feature . name || "<unamed feature>" , ( ) => {
269269 before ( function ( ) {
270270 beforeHandler . call ( this , context ) ;
271+ beforeAllHandler . call ( this , context ) ;
271272 } ) ;
272273
273274 beforeEach ( function ( ) {
274275 beforeEachHandler . call ( this , context ) ;
275276 } ) ;
276277
278+ after ( function ( ) {
279+ afterAllHandler . call ( this , context ) ;
280+ } ) ;
281+
277282 afterEach ( function ( ) {
278283 afterEachHandler . call ( this , context ) ;
279284 } ) ;
@@ -715,6 +720,31 @@ function beforeHandler(context: CompositionContext) {
715720 taskSpecEnvelopes ( context ) ;
716721}
717722
723+ function beforeAllHandler ( this : Mocha . Context , context : CompositionContext ) {
724+ const { registry } = context ;
725+ let beforeAllHooks = registry . resolveBeforeAllHooks ( ) ;
726+ for ( const beforeAllHook of beforeAllHooks ) {
727+ if ( beforeAllHook ) {
728+ const hook = beforeAllHook ;
729+ cy . then ( ( ) => {
730+ const start = createTimestamp ( ) ;
731+ return cy . wrap ( start , { log : false } ) ;
732+ } )
733+ . then ( ( start ) => {
734+ runStepWithLogGroup ( {
735+ fn : ( ) => registry . runHook ( this , hook ) ,
736+ keyword : "BeforeAll"
737+ } ) ;
738+
739+ return cy . wrap ( start , { log : false } ) ;
740+ } )
741+ . then ( ( start ) => {
742+ const end = createTimestamp ( ) ;
743+ } ) ;
744+ }
745+ }
746+ }
747+
718748function beforeEachHandler ( context : CompositionContext ) {
719749 assignRegistry ( context . registry ) ;
720750}
@@ -946,6 +976,30 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
946976 } ) ;
947977}
948978
979+ function afterAllHandler ( this : Mocha . Context , context : CompositionContext ) {
980+ const { registry } = context ;
981+ let afterAllHooks = registry . resolveAfterAllHooks ( ) ;
982+ for ( const afterAllHook of afterAllHooks ) {
983+ if ( afterAllHook ) {
984+ const hook = afterAllHook ;
985+ cy . then ( ( ) => {
986+ const start = createTimestamp ( ) ;
987+ return cy . wrap ( start , { log : false } ) ;
988+ } )
989+ . then ( ( start ) => {
990+ runStepWithLogGroup ( {
991+ fn : ( ) => registry . runHook ( this , hook ) ,
992+ keyword : "AfterAll"
993+ } ) ;
994+
995+ return cy . wrap ( start , { log : false } ) ;
996+ } )
997+ . then ( ( start ) => {
998+ const end = createTimestamp ( ) ;
999+ } ) ;
1000+ }
1001+ }
1002+ }
9491003export default function createTests (
9501004 registry : Registry ,
9511005 seed : number ,
@@ -999,7 +1053,8 @@ export default function createTests(
9991053 const tags = collectTagNames ( pickle . tags ) ;
10001054 const beforeHooks = registry . resolveBeforeHooks ( tags ) ;
10011055 const afterHooks = registry . resolveAfterHooks ( tags ) ;
1002-
1056+ const beforeAllHooks = registry . resolveBeforeAllHooks ( ) ;
1057+ const afterAllHooks = registry . resolveAfterAllHooks ( ) ;
10031058 const hooksToStep = ( hook : IHook ) : messages . TestStep => {
10041059 return {
10051060 id : createTestStepId ( {
@@ -1035,9 +1090,11 @@ export default function createTests(
10351090 id : pickle . id ,
10361091 pickleId : pickle . id ,
10371092 testSteps : [
1093+ ...beforeAllHooks . map ( hooksToStep ) ,
10381094 ...beforeHooks . map ( hooksToStep ) ,
10391095 ...pickle . steps . map ( pickleStepToTestStep ) ,
10401096 ...afterHooks . map ( hooksToStep ) ,
1097+ ...afterAllHooks . map ( hooksToStep )
10411098 ] ,
10421099 } ;
10431100 } ) ;
0 commit comments