Skip to content

Commit

Permalink
- automatic feature file generation
Browse files Browse the repository at this point in the history
- removed old hardcoded test files
- renamed test mode to "test-scenario"
  • Loading branch information
kaitorched committed Oct 5, 2023
1 parent ea22d60 commit 34db545
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 100 deletions.
6 changes: 0 additions & 6 deletions packages/be/features/add_car_to_fleet.feature

This file was deleted.

85 changes: 0 additions & 85 deletions packages/be/features/step_definitions/AddCarToFleetSteps.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Feature: <%= featureNames.name %>
Scenario: <%= featureNames.name %>
Given <%= givenEvent.name %>
When <%= whenEvent.name %>
Then <%= thenEvent.name %>
14 changes: 6 additions & 8 deletions packages/cody/src/lib/hooks/on-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {flushChanges} from "nx/src/generators/tree";
import {listChangesForCodyResponse} from "./utils/fs-tree";

const modeKey = "mode";
const modeValueTest = "test";
const modeValueTest = "test-scenario";

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

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

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

async function createTestFile(featureName: string, givenNodes : Array<Node>, whenCommand : Node, thenNodes : Array<Node>, ctx: Context): Promise<string> {
async function createTestFiles(featureName: string, 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]);

const aggregate = 'car';
Expand All @@ -119,16 +120,13 @@ async function createTestFile(featureName: string, givenNodes : Array<Node>, whe
"aggregate": aggregate,
"expectedIdentifier": "6a76bead-46ce-4651-bea0-d8a387b2e9d0" // TODO: read from "then" node payload (convert to json, read & remove "expectedIdentifier", convert back to string)
}

// console.log(substitutions);

// generate test files
const {tree} = ctx;
generateFiles(tree, __dirname + '/behaviour-test-files', ctx.beSrc+'/../', substitutions); // TODO: setup correct template/target folder

generateFiles(tree, __dirname + '/behaviour-test-files', ctx.beSrc+'/../', substitutions);
await formatFiles(tree);

const changes = tree.listChanges();

flushChanges(ctx.projectRoot, changes);

return listChangesForCodyResponse(tree);
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {camelCase, startCase, snakeCase, kebabCase} from 'lodash';

export const names = (str: string): {name: string, className: string, propertyName: string, constantName: string, fileName: string} => {
return {
name: str,
name: str.trim(),
className: startCase(camelCase(str)).replace(/ /g, ''),
propertyName: camelCase(str),
constantName: snakeCase(str).toUpperCase(),
Expand Down

0 comments on commit 34db545

Please sign in to comment.