diff --git a/src/decorators.ts b/src/decorators.ts index a7a998d4..4fca117c 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -1,4 +1,4 @@ -import { Fixture } from './steps/decorators/class'; +import { Fixture } from './steps/decorators/fixture'; import { createStepDecorator } from './steps/decorators/steps'; export { Fixture }; diff --git a/src/gen/decoratorSteps.ts b/src/gen/decoratorSteps.ts index ef8543a4..f9f8569f 100644 --- a/src/gen/decoratorSteps.ts +++ b/src/gen/decoratorSteps.ts @@ -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; diff --git a/src/gen/testPoms.ts b/src/gen/testPoms.ts index 09e7aaa7..308b71c4 100644 --- a/src/gen/testPoms.ts +++ b/src/gen/testPoms.ts @@ -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:'; diff --git a/src/steps/decorators/fixture.ts b/src/steps/decorators/fixture.ts new file mode 100644 index 00000000..37bdfa32 --- /dev/null +++ b/src/steps/decorators/fixture.ts @@ -0,0 +1,14 @@ +/** + * Class level @Fixture decorator. + */ + +import { CustomFixtures, KeyValue } from '../../playwright/types'; +import { createPomNode } from './pomGraph'; + +export function Fixture(fixtureName: keyof CustomFixtures) { + // 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); + }; +} diff --git a/src/steps/decorators/class.ts b/src/steps/decorators/pomGraph.ts similarity index 73% rename from src/steps/decorators/class.ts rename to src/steps/decorators/pomGraph.ts index 754d58b0..f0fba8e7 100644 --- a/src/steps/decorators/class.ts +++ b/src/steps/decorators/pomGraph.ts @@ -1,21 +1,15 @@ /** - * 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(); - // POM class with inherited children POMs: representation of classes inheritance. export type PomNode = { fixtureName: string; @@ -23,17 +17,9 @@ export type PomNode = { children: Set; }; -/** - * @Fixture decorator. - */ -export function Fixture(fixtureName: keyof CustomFixtures) { - // 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(); -function createPomNode(Ctor: PomClass, fixtureName: string) { +export function createPomNode(Ctor: PomClass, fixtureName: string) { const pomNode: PomNode = { fixtureName, className: Ctor.name, diff --git a/src/steps/decorators/steps.ts b/src/steps/decorators/steps.ts index 410ae4fd..63906218 100644 --- a/src/steps/decorators/steps.ts +++ b/src/steps/decorators/steps.ts @@ -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'; diff --git a/src/steps/stepConfig.ts b/src/steps/stepConfig.ts index a00f0615..74e81ba6 100644 --- a/src/steps/stepConfig.ts +++ b/src/steps/stepConfig.ts @@ -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;