Skip to content

Commit

Permalink
fix: cucumber keywords on logging
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkenos committed Jun 25, 2024
1 parent 5666f73 commit 3b41b22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/common/utils/object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** https://stackoverflow.com/a/56204398/2285470 */
export function deepSearch(object: any, key: string, value: any) {
let result = undefined;
JSON.stringify(object, (_, nestedValue) => {
if (nestedValue && nestedValue[key] === value) {
result = nestedValue;
}
return nestedValue;
});
return result;
}
7 changes: 5 additions & 2 deletions src/core/gherkin/world.def.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import * as object from "@common/utils/object";

import {
After,
AfterStep,
Expand All @@ -21,8 +23,9 @@ Before({}, async function(this: World) {
});

BeforeStep({}, async function(this: This, params: ITestStepHookParameter) {
const { pickleStep } = params;
this.logger.info(`${chalk.green.dim.bold(`${pickleStep.type}: `)}${chalk.green.dim(pickleStep.text)}`);
const { pickleStep, gherkinDocument } = params;
const step = object.deepSearch(gherkinDocument, "id", pickleStep.astNodeIds[0]);
this.logger.info(`${chalk.green.dim.bold(step.keyword.trim())} ${chalk.green.dim(step.text)}`);
});

AfterStep({}, async function(this: This, params: ITestStepHookParameter) {
Expand Down

0 comments on commit 3b41b22

Please sign in to comment.