Skip to content

Commit

Permalink
refactor: decorators/class -> decorators/pomGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalets committed Apr 19, 2024
1 parent 73def2f commit adbe7d5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/decorators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fixture } from './steps/decorators/class';
import { Fixture } from './steps/decorators/fixture';
import { createStepDecorator } from './steps/decorators/steps';

export { Fixture };
Expand Down
2 changes: 1 addition & 1 deletion src/gen/decoratorSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* Then fixtures are guessed and slots are filled with decorator steps lines.
*/
import { PickleStep } from '@cucumber/messages';
import { PomNode } from '../steps/decorators/class';
import { TestPoms, UsedFixture } from './testPoms';
import { exit } from '../utils/exit';
import { PomNode } from '../steps/decorators/pomGraph';

type DecoratorStepsOptions = {
statefulPoms?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/gen/testPoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* If test uses steps from classes A and B, and has @fixture:C
* -> actually @fixture tag has no effect, resolved fixture will be A and B (warning?)
*/
import { PomNode, getPomNodeByFixtureName } from '../steps/decorators/class';
import { PomNode, getPomNodeByFixtureName } from '../steps/decorators/pomGraph';
import { exit } from '../utils/exit';

const FIXTURE_TAG_PREFIX = '@fixture:';
Expand Down
14 changes: 14 additions & 0 deletions src/steps/decorators/fixture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Class level @Fixture decorator.
*/

import { CustomFixtures, KeyValue } from '../../playwright/types';
import { createPomNode } from './pomGraph';

export function Fixture<T extends KeyValue>(fixtureName: keyof CustomFixtures<T>) {
// context parameter is required for decorator by TS even though it's not used
// eslint-disable-next-line @typescript-eslint/ban-types
return (Ctor: Function, _context: ClassDecoratorContext) => {
createPomNode(Ctor, fixtureName);
};
}
22 changes: 4 additions & 18 deletions src/steps/decorators/class.ts → src/steps/decorators/pomGraph.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
/**
* Class level @Fixture decorator.
* Tree-structure of all POM classes.
* Allows to guess correct fixture for decorator steps.
*/

/* eslint-disable @typescript-eslint/ban-types */

import { CustomFixtures, KeyValue } from '../../playwright/types';
import { linkStepsWithPomNode } from './steps';
import { exit } from '../../utils/exit';

type PomClass = Function;

/**
* Graph of POM class inheritance.
* Allows to guess correct fixture by step text.
*/
const pomGraph = new Map<PomClass, PomNode>();

// POM class with inherited children POMs: representation of classes inheritance.
export type PomNode = {
fixtureName: string;
className: string;
children: Set<PomNode>;
};

/**
* @Fixture decorator.
*/
export function Fixture<T extends KeyValue>(fixtureName: keyof CustomFixtures<T>) {
// context parameter is required for decorator by TS even though it's not used
return (Ctor: Function, _context: ClassDecoratorContext) => {
createPomNode(Ctor, fixtureName);
};
}
const pomGraph = new Map<PomClass, PomNode>();

function createPomNode(Ctor: PomClass, fixtureName: string) {
export function createPomNode(Ctor: PomClass, fixtureName: string) {
const pomNode: PomNode = {
fixtureName,
className: Ctor.name,
Expand Down
2 changes: 1 addition & 1 deletion src/steps/decorators/steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { buildStepDefinition } from '../../cucumber/buildStepDefinition';
import { GherkinStepKeyword } from '@cucumber/cucumber/lib/models/gherkin_step_keyword';
import { StepConfig } from '../stepConfig';
import { buildCucumberStepFn } from '../defineStep';
import { PomNode } from './class';
import { PomNode } from './pomGraph';
import { ISupportCodeLibrary } from '../../cucumber/types';
import { isBddAutoInjectFixture } from '../../run/bddFixtures/autoInject';
import { getLocationByOffset } from '../../playwright/getLocationInFile';
Expand Down
2 changes: 1 addition & 1 deletion src/steps/stepConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
} from '@cucumber/cucumber/lib/support_code_library_builder/types';
import StepDefinition from '@cucumber/cucumber/lib/models/step_definition';
import { BddWorld } from '../run/bddWorld';
import { PomNode } from './decorators/class';
import { PlaywrightLocation } from '../playwright/types';
import { PomNode } from './decorators/pomGraph';

export type StepConfig = {
keyword: GherkinStepKeyword;
Expand Down

0 comments on commit adbe7d5

Please sign in to comment.