Skip to content

Commit f01fcb7

Browse files
committed
Use feature metadata for feature file definition to prevent duplicates
1 parent 34db545 commit f01fcb7

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Feature: <%= featureNames.name %>
22
Scenario: <%= featureNames.name %>
3-
Given <%= givenEvent.name %>
4-
When <%= whenEvent.name %>
5-
Then <%= thenEvent.name %>
3+
Given <%= given %>
4+
When <%= when %>
5+
Then <%= then %>

packages/cody/src/lib/hooks/behaviour-test-files/features/step_definitions/__feature__Steps.ts__tmpl__

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class <%= feature %>Steps {
2323
this.eventStore.attachAppendToListener(listener);
2424
}
2525

26-
@given('<%= givenEvent.name %>')
26+
@given('<%= given %>')
2727
public async given<%= givenEvent.className %>(): Promise<void> {
2828
const payload = {
2929
<%- givenPayload %>
@@ -47,7 +47,7 @@ class <%= feature %>Steps {
4747
}
4848
*/
4949

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

61-
@then('<%= thenEvent.name %>')
61+
@then('<%= then %>')
6262
public async then<%= thenEvent.className %>(): Promise<void> {
6363
const identifier = '<%= expectedIdentifier %>';
6464
const expectedPayload = {

packages/cody/src/lib/hooks/on-feature.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import {listChangesForCodyResponse} from "./utils/fs-tree";
1111

1212
const modeKey = "mode";
1313
const modeValueTest = "test-scenario";
14+
const givenKey = "given";
15+
const whenKey = "when";
16+
const thenKey = "then";
1417

1518
export const onFeature: CodyHook<Context> = async (feature: Node, ctx: Context) => {
1619
try {
@@ -64,7 +67,7 @@ export const onFeature: CodyHook<Context> = async (feature: Node, ctx: Context)
6467
}
6568
}
6669

67-
const changesForCodyResponse = await createTestFiles(feature.getName(), givenNodes, whenCommand, thenNodes, ctx);
70+
const changesForCodyResponse = await createTestFiles(feature.getName(), featureMeta, givenNodes, whenCommand, thenNodes, ctx);
6871

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

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

@@ -111,6 +114,9 @@ async function createTestFiles(featureName: string, givenNodes : Array<Node>, wh
111114
"feature": names(featureName).className,
112115
"serviceNames": names(service),
113116
"featureNames": names(featureName),
117+
"given": featureMeta[givenKey],
118+
"when": featureMeta[whenKey],
119+
"then": featureMeta[thenKey],
114120
"givenEvent": names(givenNodes[0].getName()),
115121
"whenEvent": names(whenCommand.getName()),
116122
"thenEvent": names(thenNodes[0].getName()),

0 commit comments

Comments
 (0)