-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
step_definition.ts
50 lines (46 loc) · 1.58 KB
/
step_definition.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import DataTable from './data_table'
import Definition, {
IDefinition,
IGetInvocationDataRequest,
IGetInvocationDataResponse,
IStepDefinitionParameters,
} from './definition'
import { parseStepArgument } from '../step_arguments'
import { Expression } from '@cucumber/cucumber-expressions'
import { doesHaveValue } from '../value_checker'
import { GherkinStepKeyword } from './gherkin_step_keyword'
export default class StepDefinition extends Definition implements IDefinition {
public readonly keyword: GherkinStepKeyword
public readonly pattern: string | RegExp
public readonly expression: Expression
constructor(data: IStepDefinitionParameters) {
super(data)
this.keyword = data.keyword
this.pattern = data.pattern
this.expression = data.expression
}
async getInvocationParameters({
step,
world,
}: IGetInvocationDataRequest): Promise<IGetInvocationDataResponse> {
const parameters = await Promise.all(
this.expression.match(step.text).map((arg) => arg.getValue(world))
)
if (doesHaveValue(step.argument)) {
const argumentParamater = parseStepArgument<any>(step.argument, {
dataTable: (arg) => new DataTable(arg),
docString: (arg) => arg.content,
})
parameters.push(argumentParamater)
}
return {
getInvalidCodeLengthMessage: () =>
this.baseGetInvalidCodeLengthMessage(parameters),
parameters,
validCodeLengths: [parameters.length, parameters.length + 1],
}
}
matchesStepName(stepName: string): boolean {
return doesHaveValue(this.expression.match(stepName))
}
}