@@ -13,7 +13,7 @@ import { v4 as uuid } from "uuid";
1313
1414import random from "seedrandom" ;
1515
16- import { assert , assertAndReturn , fail } from "./helpers/assertions" ;
16+ import { assert , ensure , fail } from "./helpers/assertions" ;
1717
1818import DataTable from "./data_table" ;
1919
@@ -293,7 +293,7 @@ function emitSkippedPickle(
293293}
294294
295295function findPickleById ( context : CompositionContext , astId : string ) {
296- return assertAndReturn (
296+ return ensure (
297297 context . pickles . find (
298298 ( pickle ) => pickle . astNodeIds && pickle . astNodeIds . includes ( astId ) ,
299299 ) ,
@@ -304,11 +304,8 @@ function findPickleById(context: CompositionContext, astId: string) {
304304function collectExampleIds ( examples : readonly messages . Examples [ ] ) {
305305 return examples
306306 . map ( ( examples ) => {
307- return assertAndReturn (
308- examples . tableBody ,
309- "Expected to find a table body" ,
310- ) . map ( ( row ) =>
311- assertAndReturn ( row . id , "Expected table row to have an id" ) ,
307+ return ensure ( examples . tableBody , "Expected to find a table body" ) . map (
308+ ( row ) => ensure ( row . id , "Expected table row to have an id" ) ,
312309 ) ;
313310 } )
314311 . reduce ( ( acum , el ) => acum . concat ( el ) , [ ] ) ;
@@ -346,8 +343,8 @@ function getTestStepId(options: {
346343} ) {
347344 const { context, pickleId, hookIdOrPickleStepId } = options ;
348345
349- return assertAndReturn (
350- assertAndReturn (
346+ return ensure (
347+ ensure (
351348 context . testStepIds . get ( pickleId ) ,
352349 "Expected to find test step IDs for pickle = " + pickleId ,
353350 ) . get ( hookIdOrPickleStepId ) ,
@@ -422,7 +419,7 @@ function createRule(context: CompositionContext, rule: messages.Rule) {
422419 return findPickleById ( context , exampleId ) ;
423420 } ) ;
424421 } else {
425- const scenarioId = assertAndReturn (
422+ const scenarioId = ensure (
426423 scenario . id ,
427424 "Expected scenario to have an id" ,
428425 ) ;
@@ -473,10 +470,7 @@ function createScenario(
473470 createPickle ( context , { ...pickle , name : exampleName } ) ;
474471 }
475472 } else {
476- const scenarioId = assertAndReturn (
477- scenario . id ,
478- "Expected scenario to have an id" ,
479- ) ;
473+ const scenarioId = ensure ( scenario . id , "Expected scenario to have an id" ) ;
480474
481475 const pickle = findPickleById ( context , scenarioId ) ;
482476
@@ -521,12 +515,9 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
521515 [ INTERNAL_SPEC_PROPERTIES ] : internalProperties ,
522516 } ;
523517
524- const scenario = assertAndReturn (
518+ const scenario = ensure (
525519 context . astIdsMap . get (
526- assertAndReturn (
527- pickle . astNodeIds ?. [ 0 ] ,
528- "Expected to find at least one astNodeId" ,
529- ) ,
520+ ensure ( pickle . astNodeIds ?. [ 0 ] , "Expected to find at least one astNodeId" ) ,
530521 ) ,
531522 `Expected to find scenario associated with id = ${ pickle . astNodeIds ?. [ 0 ] } ` ,
532523 ) ;
@@ -624,7 +615,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
624615 remainingSteps . shift ( ) ;
625616
626617 for ( const skippedStep of remainingSteps ) {
627- const hookIdOrPickleStepId = assertAndReturn (
618+ const hookIdOrPickleStepId = ensure (
628619 skippedStep . hook ?. id ?? skippedStep . pickleStep ?. id ,
629620 "Expected a step to either be a hook or a pickleStep" ,
630621 ) ;
@@ -729,14 +720,14 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
729720 hookIdOrPickleStepId : pickleStep . id ,
730721 } ) ;
731722
732- const text = assertAndReturn (
723+ const text = ensure (
733724 pickleStep . text ,
734725 "Expected pickle step to have a text" ,
735726 ) ;
736727
737- const scenarioStep = assertAndReturn (
728+ const scenarioStep = ensure (
738729 context . astIdsMap . get (
739- assertAndReturn (
730+ ensure (
740731 pickleStep . astNodeIds ?. [ 0 ] ,
741732 "Expected to find at least one astNodeId" ,
742733 ) ,
@@ -797,7 +788,7 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
797788 return beforeHooksChain . then ( ( ) => {
798789 try {
799790 return runStepWithLogGroup ( {
800- keyword : assertAndReturn (
791+ keyword : ensure (
801792 "keyword" in scenarioStep && scenarioStep . keyword ,
802793 "Expected to find a keyword in the scenario step" ,
803794 ) ,
@@ -935,12 +926,9 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
935926
936927 if ( remainingSteps . length > 0 ) {
937928 if ( this . currentTest ?. state === "failed" ) {
938- const error = assertAndReturn (
939- this . currentTest ?. err ,
940- "Expected to find an error" ,
941- ) ;
929+ const error = ensure ( this . currentTest ?. err , "Expected to find an error" ) ;
942930
943- const message = assertAndReturn (
931+ const message = ensure (
944932 error . message ,
945933 "Expected to find an error message" ,
946934 ) ;
@@ -949,12 +937,12 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
949937 return ;
950938 }
951939
952- const failedStep = assertAndReturn (
940+ const failedStep = ensure (
953941 remainingSteps . shift ( ) ,
954942 "Expected there to be a remaining step" ,
955943 ) ;
956944
957- const hookIdOrPickleStepId = assertAndReturn (
945+ const hookIdOrPickleStepId = ensure (
958946 failedStep . hook ?. id ?? failedStep . pickleStep ?. id ,
959947 "Expected a step to either be a hook or a pickleStep" ,
960948 ) ;
@@ -998,7 +986,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
998986 message,
999987 } ) ,
1000988 duration : duration (
1001- assertAndReturn (
989+ ensure (
1002990 currentStepStartedAt ,
1003991 "Expected there to be a timestamp for current step" ,
1004992 ) ,
@@ -1021,7 +1009,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
10211009 taskTestStepFinished ( context , failedTestStepFinished ) ;
10221010
10231011 for ( const skippedStep of remainingSteps ) {
1024- const hookIdOrPickleStepId = assertAndReturn (
1012+ const hookIdOrPickleStepId = ensure (
10251013 skippedStep . hook ?. id ?? skippedStep . pickleStep ?. id ,
10261014 "Expected a step to either be a hook or a pickleStep" ,
10271015 ) ;
@@ -1053,12 +1041,12 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
10531041 }
10541042 } else if ( this . currentTest ?. state === "pending" ) {
10551043 if ( currentStepStartedAt ) {
1056- const skippedStep = assertAndReturn (
1044+ const skippedStep = ensure (
10571045 remainingSteps . shift ( ) ,
10581046 "Expected there to be a remaining step" ,
10591047 ) ;
10601048
1061- const hookIdOrPickleStepId = assertAndReturn (
1049+ const hookIdOrPickleStepId = ensure (
10621050 skippedStep . hook ?. id ?? skippedStep . pickleStep ?. id ,
10631051 "Expected a step to either be a hook or a pickleStep" ,
10641052 ) ;
@@ -1081,7 +1069,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
10811069 }
10821070
10831071 for ( const remainingStep of remainingSteps ) {
1084- const hookIdOrPickleStepId = assertAndReturn (
1072+ const hookIdOrPickleStepId = ensure (
10851073 remainingStep . hook ?. id ?? remainingStep . pickleStep ?. id ,
10861074 "Expected a step to either be a hook or a pickleStep" ,
10871075 ) ;
@@ -1113,7 +1101,7 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
11131101 }
11141102 } else {
11151103 for ( const remainingStep of remainingSteps ) {
1116- const hookIdOrPickleStepId = assertAndReturn (
1104+ const hookIdOrPickleStepId = ensure (
11171105 remainingStep . hook ?. id ?? remainingStep . pickleStep ?. id ,
11181106 "Expected a step to either be a hook or a pickleStep" ,
11191107 ) ;
@@ -1146,12 +1134,12 @@ function afterEachHandler(this: Mocha.Context, context: CompositionContext) {
11461134 }
11471135 }
11481136
1149- const currentRetry = assertAndReturn (
1137+ const currentRetry = ensure (
11501138 ( this . currentTest as any ) ?. _currentRetry ,
11511139 "Expected to find an attribute _currentRetry" ,
11521140 ) ;
11531141
1154- const retries = assertAndReturn (
1142+ const retries = ensure (
11551143 ( this . currentTest as any ) ?. _retries ,
11561144 "Expected to find an attribute _retries" ,
11571145 ) ;
@@ -1318,10 +1306,7 @@ export default function createTests(
13181306 specEnvelopes . push ( {
13191307 source : {
13201308 data : source ,
1321- uri : assertAndReturn (
1322- gherkinDocument . uri ,
1323- "Expected gherkin document to have URI" ,
1324- ) ,
1309+ uri : ensure ( gherkinDocument . uri , "Expected gherkin document to have URI" ) ,
13251310 mediaType : SourceMediaType . TEXT_X_CUCUMBER_GHERKIN_PLAIN ,
13261311 } ,
13271312 } ) ;
@@ -1495,7 +1480,7 @@ function createMissingStepDefinitionMessage(
14951480 . map ( ( expression ) =>
14961481 generateSnippet (
14971482 expression ,
1498- assertAndReturn ( pickleStep . type , "Expected pickleStep to have a type" ) ,
1483+ ensure ( pickleStep . type , "Expected pickleStep to have a type" ) ,
14991484 parameter ,
15001485 ) ,
15011486 )
0 commit comments