Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.runtime[keyword] = (expression, implementation) => this.definitions[keyword].push({
implementation,
expression: new CucumberExpression(expression, parameterTypeRegistry)
});
})
export default function defaultStepDefinitionRegistry(): StepDefinitionRegistry {
return new StepDefinitionRegistry([
new StepDefinition(
new CucumberExpression('a passed {word}', new ParameterTypeRegistry()),
() => undefined
),
new StepDefinition(
new CucumberExpression('a failed {word}', new ParameterTypeRegistry()),
() => {
throw new Error('Nope')
}
),
new StepDefinition(
new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
() => 'pending'
),
new StepDefinition(
new CucumberExpression(
'an ambiguous {word}',
new ParameterTypeRegistry()
),
() => undefined
),
new StepDefinition(
export default function defaultStepDefinitionRegistry(): StepDefinitionRegistry {
return new StepDefinitionRegistry([
new StepDefinition(
new CucumberExpression('a passed {word}', new ParameterTypeRegistry()),
() => undefined
),
new StepDefinition(
new CucumberExpression('a failed {word}', new ParameterTypeRegistry()),
() => {
throw new Error('Nope')
}
),
new StepDefinition(
new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
() => 'pending'
),
new StepDefinition(
new CucumberExpression(
'an ambiguous {word}',
new ParameterTypeRegistry()
({ code, line, options, pattern, uri }) => {
const expression =
typeof pattern === 'string'
? new CucumberExpression(pattern, this.parameterTypeRegistry)
: new RegularExpression(pattern, this.parameterTypeRegistry)
const wrappedCode = this.wrapCode({
code,
wrapperOptions: options.wrapperOptions,
})
return new StepDefinition({
code: wrappedCode,
expression,
id: this.newId(),
line,
options,
pattern,
unwrappedCode: code,
uri,
})
}
this.runtime = (matcher, implementation) => {
let expression;
if (matcher instanceof RegExp) {
expression = new RegularExpression(
matcher,
this.options.parameterTypeRegistry
);
} else {
expression = new CucumberExpression(
matcher,
this.options.parameterTypeRegistry
);
}
this.definitions.push({
implementation,
expression,
featureName: window.currentFeatureName || "___GLOBAL_EXECUTION___"
});
};
export default function defaultStepDefinitionRegistry(): StepDefinitionRegistry {
return new StepDefinitionRegistry([
new StepDefinition(
new CucumberExpression('a passed {word}', new ParameterTypeRegistry()),
() => undefined
),
new StepDefinition(
new CucumberExpression('a failed {word}', new ParameterTypeRegistry()),
() => {
throw new Error('Nope')
}
),
new StepDefinition(
new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
() => 'pending'
),
new StepDefinition(
new CucumberExpression(
'an ambiguous {word}',
new ParameterTypeRegistry()
),
() => undefined
),
new StepDefinition(
new CucumberExpression('an {word} step', new ParameterTypeRegistry()),
() => undefined
),
new StepDefinition(
new CucumberExpression(
'I have {int} cukes in my belly',
new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
() => 'pending'
),
new StepDefinition(
new CucumberExpression(
'an ambiguous {word}',
new ParameterTypeRegistry()
),
() => undefined
),
new StepDefinition(
new CucumberExpression('an {word} step', new ParameterTypeRegistry()),
() => undefined
),
new StepDefinition(
new CucumberExpression(
'I have {int} cukes in my belly',
new ParameterTypeRegistry()
),
cukes => cukes
),
])
}
const matchStep = (step) => {
for (const stepName in steps) {
if (stepName.indexOf('/') === 0) {
const res = step.match(new RegExp(stepName.slice(1, -1)));
if (res) {
const fn = steps[stepName];
fn.params = res.slice(1);
return fn;
}
continue;
}
const expression = new CucumberExpression(stepName, parameterTypeRegistry);
const res = expression.match(step);
if (res) {
const fn = steps[stepName];
fn.params = res.map(arg => arg.getValue());
return fn;
}
}
throw new Error(`No steps matching "${step.toString()}"`);
};
new StepDefinition(
new CucumberExpression('a passed {word}', new ParameterTypeRegistry()),
() => undefined
),
new StepDefinition(
new CucumberExpression('a failed {word}', new ParameterTypeRegistry()),
() => {
throw new Error('Nope')
}
),
new StepDefinition(
new CucumberExpression('a pending {word}', new ParameterTypeRegistry()),
() => 'pending'
),
new StepDefinition(
new CucumberExpression(
'an ambiguous {word}',
new ParameterTypeRegistry()
),
() => undefined
),
new StepDefinition(
new CucumberExpression('an {word} step', new ParameterTypeRegistry()),
() => undefined
),
new StepDefinition(
new CucumberExpression(
'I have {int} cukes in my belly',
new ParameterTypeRegistry()
),
cukes => cukes
),
private registerStepDefinition(
expression: string | RegExp,
body: AnyBody
): void {
const sourceReference = getSourceReference(new Error().stack)
const expr =
typeof expression === 'string'
? new CucumberExpression(expression, this.parameterTypeRegistry)
: new RegularExpression(expression, this.parameterTypeRegistry)
const stepDefinition = new ExpressionStepDefinition(
this.newId(),
expr,
sourceReference,
body
)
this.stepDefinitions.push(stepDefinition)
}