Skip to content

Commit

Permalink
Use feature metadata for feature file definition to prevent duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
bofalke committed Oct 6, 2023
1 parent 34db545 commit f01fcb7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature: <%= featureNames.name %>
Scenario: <%= featureNames.name %>
Given <%= givenEvent.name %>
When <%= whenEvent.name %>
Then <%= thenEvent.name %>
Given <%= given %>
When <%= when %>
Then <%= then %>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class <%= feature %>Steps {
this.eventStore.attachAppendToListener(listener);
}

@given('<%= givenEvent.name %>')
@given('<%= given %>')
public async given<%= givenEvent.className %>(): Promise<void> {
const payload = {
<%- givenPayload %>
Expand All @@ -47,7 +47,7 @@ class <%= feature %>Steps {
}
*/

@when('<%= whenEvent.name %>')
@when('<%= when %>')
public async when<%= whenEvent.className %>(): Promise<void> {
const payload = {
<%- whenPayload %>
Expand All @@ -58,7 +58,7 @@ class <%= feature %>Steps {
await this.messageBox.dispatch(command.name, command.payload, command.meta);
}

@then('<%= thenEvent.name %>')
@then('<%= then %>')
public async then<%= thenEvent.className %>(): Promise<void> {
const identifier = '<%= expectedIdentifier %>';
const expectedPayload = {
Expand Down
10 changes: 8 additions & 2 deletions packages/cody/src/lib/hooks/on-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import {listChangesForCodyResponse} from "./utils/fs-tree";

const modeKey = "mode";
const modeValueTest = "test-scenario";
const givenKey = "given";
const whenKey = "when";
const thenKey = "then";

export const onFeature: CodyHook<Context> = async (feature: Node, ctx: Context) => {
try {
Expand Down Expand Up @@ -64,7 +67,7 @@ export const onFeature: CodyHook<Context> = async (feature: Node, ctx: Context)
}
}

const changesForCodyResponse = await createTestFiles(feature.getName(), givenNodes, whenCommand, thenNodes, ctx);
const changesForCodyResponse = await createTestFiles(feature.getName(), featureMeta, givenNodes, whenCommand, thenNodes, ctx);

// for logging:
const loggedNodes: Array<string> = [];
Expand Down Expand Up @@ -99,7 +102,7 @@ export const onFeature: CodyHook<Context> = async (feature: Node, ctx: Context)
}
}

async function createTestFiles(featureName: string, givenNodes : Array<Node>, whenCommand : Node, thenNodes : Array<Node>, ctx: Context): Promise<string> {
async function createTestFiles(featureName: string, featureMeta: any, givenNodes : Array<Node>, whenCommand : Node, thenNodes : Array<Node>, ctx: Context): Promise<string> {
// if using a service from another board (e.g. Fleet Management), make sure to set this up in the test feature's metadata!
const service = withErrorCheck(detectService, [whenCommand, ctx]);

Expand All @@ -111,6 +114,9 @@ async function createTestFiles(featureName: string, givenNodes : Array<Node>, wh
"feature": names(featureName).className,
"serviceNames": names(service),
"featureNames": names(featureName),
"given": featureMeta[givenKey],
"when": featureMeta[whenKey],
"then": featureMeta[thenKey],
"givenEvent": names(givenNodes[0].getName()),
"whenEvent": names(whenCommand.getName()),
"thenEvent": names(thenNodes[0].getName()),
Expand Down

0 comments on commit f01fcb7

Please sign in to comment.