Skip to content

Commit

Permalink
refactor: make customTest, pomNode and worldFixture as getters, make …
Browse files Browse the repository at this point in the history
…options private
  • Loading branch information
vitalets committed Oct 23, 2024
1 parent 5f41a2e commit 904b4bf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/gen/importTestFrom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class ImportTestFromGuesser {
}

private fillCustomTestsFromRegularSteps() {
this.usedStepDefinitions.forEach((stepDefinition) => {
const { customTest } = stepDefinition.options;
this.usedStepDefinitions.forEach(({ customTest }) => {
if (customTest) this.customTestsSet.add(customTest);
});
}
Expand Down
5 changes: 2 additions & 3 deletions src/gen/testFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export class TestFile {
index,
keywordEng,
pickleStep,
pomNode: stepDefinition.options.pomNode,
pomNode: stepDefinition.pomNode,
});

// for decorator steps, line and fixtureNames are filled later in second pass
Expand Down Expand Up @@ -424,8 +424,7 @@ export class TestFile {
private getWorldFixtureName() {
const worldFixtureNames = new Set<string>();

this.usedStepDefinitions.forEach((stepDefinition) => {
const { worldFixture } = stepDefinition.options;
this.usedStepDefinitions.forEach(({ worldFixture }) => {
if (worldFixture) worldFixtureNames.add(worldFixture);
});

Expand Down
18 changes: 15 additions & 3 deletions src/steps/stepDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export type StepDefinitionOptions = {
export class StepDefinition {
#expression?: Expression;

constructor(public options: StepDefinitionOptions) {}
constructor(private options: StepDefinitionOptions) {}

get keyword() {
return this.options.keyword;
Expand All @@ -46,6 +46,18 @@ export class StepDefinition {
return this.options.location.line;
}

get customTest() {
return this.options.customTest;
}

get pomNode() {
return this.options.pomNode;
}

get worldFixture() {
return this.options.worldFixture;
}

get expression() {
// create expression lazily b/c we need all parameter types to be loaded
if (!this.#expression) {
Expand All @@ -65,14 +77,14 @@ export class StepDefinition {
/**
* Decorator steps have pom node.
*/
isDecorator(): this is this & { options: StepDefinitionOptions & { pomNode: PomNode } } {
isDecorator(): this is this & { pomNode: PomNode } {
return Boolean(this.options.pomNode);
}

/**
* New cucumber-style steps have worldFixture in step config.
*/
isCucumberStyle(): this is this & { options: StepDefinitionOptions & { worldFixture: string } } {
isCucumberStyle(): this is this & { worldFixture: string } {
return Boolean(this.options.worldFixture);
}
}

0 comments on commit 904b4bf

Please sign in to comment.