Skip to content

Commit

Permalink
fixed formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Jan 4, 2025
1 parent 71de81b commit 304244b
Show file tree
Hide file tree
Showing 9 changed files with 586 additions and 586 deletions.
74 changes: 37 additions & 37 deletions lib/mocha/bdd.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
const { CucumberExpression, ParameterTypeRegistry, ParameterType } = require('@cucumber/cucumber-expressions');
const Config = require('../config');
const { CucumberExpression, ParameterTypeRegistry, ParameterType } = require('@cucumber/cucumber-expressions')
const Config = require('../config')

let steps = {};
let steps = {}

const STACK_POSITION = 2;
const STACK_POSITION = 2

/**
* @param {*} step
* @param {*} fn
*/
const addStep = (step, fn) => {
const avoidDuplicateSteps = Config.get('gherkin', {}).avoidDuplicateSteps || false;
const stack = new Error().stack;
const avoidDuplicateSteps = Config.get('gherkin', {}).avoidDuplicateSteps || false
const stack = new Error().stack
if (avoidDuplicateSteps && steps[step]) {
throw new Error(`Step '${step}' is already defined`);
throw new Error(`Step '${step}' is already defined`)
}
steps[step] = fn;
fn.line = stack && stack.split('\n')[STACK_POSITION];
steps[step] = fn
fn.line = stack && stack.split('\n')[STACK_POSITION]
if (fn.line) {
fn.line = fn.line
.trim()
.replace(/^at (.*?)\(/, '(')
.replace(codecept_dir, '.');
.replace(codecept_dir, '.')
}
};
}

const parameterTypeRegistry = new ParameterTypeRegistry();
const parameterTypeRegistry = new ParameterTypeRegistry()

const matchStep = step => {
for (const stepName in steps) {
if (stepName.indexOf('/') === 0) {
const regExpArr = stepName.match(/^\/(.*?)\/([gimy]*)$/) || [];
const res = step.match(new RegExp(regExpArr[1], regExpArr[2]));
const regExpArr = stepName.match(/^\/(.*?)\/([gimy]*)$/) || []
const res = step.match(new RegExp(regExpArr[1], regExpArr[2]))
if (res) {
const fn = steps[stepName];
fn.params = res.slice(1);
return fn;
const fn = steps[stepName]
fn.params = res.slice(1)
return fn
}
continue;
continue
}
const expression = new CucumberExpression(stepName, parameterTypeRegistry);
const res = expression.match(step);
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;
const fn = steps[stepName]
fn.params = res.map(arg => arg.getValue())
return fn
}
}
throw new Error(`No steps matching "${step.toString()}"`);
};
throw new Error(`No steps matching "${step.toString()}"`)
}

const clearSteps = () => {
steps = {};
};
steps = {}
}

const getSteps = () => {
return steps;
};
return steps
}

const defineParameterType = options => {
const parameterType = buildParameterType(options);
parameterTypeRegistry.defineParameterType(parameterType);
};
const parameterType = buildParameterType(options)
parameterTypeRegistry.defineParameterType(parameterType)
}

const buildParameterType = ({ name, regexp, transformer, useForSnippets, preferForRegexpMatch }) => {
if (typeof useForSnippets !== 'boolean') useForSnippets = true;
if (typeof preferForRegexpMatch !== 'boolean') preferForRegexpMatch = false;
return new ParameterType(name, regexp, null, transformer, useForSnippets, preferForRegexpMatch);
};
if (typeof useForSnippets !== 'boolean') useForSnippets = true
if (typeof preferForRegexpMatch !== 'boolean') preferForRegexpMatch = false
return new ParameterType(name, regexp, null, transformer, useForSnippets, preferForRegexpMatch)
}

module.exports = {
Given: addStep,
Expand All @@ -78,4 +78,4 @@ module.exports = {
getSteps,
clearSteps,
defineParameterType,
};
}
Loading

0 comments on commit 304244b

Please sign in to comment.