Skip to content

Commit 839095b

Browse files
j8kinbruno-morel
authored andcommitted
remove unused code
remove unused code replaced by jest-cucumber generated code
1 parent 70b5756 commit 839095b

File tree

1 file changed

+5
-133
lines changed

1 file changed

+5
-133
lines changed

src/index.js

Lines changed: 5 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ const matchJestTestSuiteWithCucumberFeature = (
127127

128128
// when scenario outline table contains examples then jest-cucumber.loadFeature
129129
// calculates scenario parameters and place them into currentScenarioOrOutline.scenarios[0].steps
130-
// at the same time currentScenarioOrOutline.steps contains pure steps without
130+
// at the same time currentScenarioOrOutline.steps contains pure steps without
131131
// example substutions for example if the scenario outline looks like:
132132
// Scenario Outline: test scenario
133133
// Given Step sentence
@@ -207,138 +207,10 @@ const isFunctionForScenario = (
207207
scenarioSentence,
208208
stepDefinitionFunction,
209209
isOutline
210-
) => {
211-
if (stepDefinitionFunction.stepRegExp) {
212-
if (isOutline && /<[\w]*>/.test(scenarioSentence)) {
213-
return isPotentialStepFunctionForScenario(
214-
scenarioSentence,
215-
stepDefinitionFunction.stepRegExp
216-
);
217-
} else return scenarioSentence.match(stepDefinitionFunction.stepRegExp);
218-
}
219-
220-
return scenarioSentence === stepDefinitionFunction.stepExpression;
221-
};
222-
223-
const isPotentialStepFunctionForScenario = (
224-
scenarioDefinition,
225-
regStepFunc
226-
) => {
227-
//so this one is tricky, to ensure we only find the
228-
// step definition corresponding to actual steps function in the case of outlined gherkin
229-
// we have to "disable" the outlining (since it can replace regular expression
230-
// and then ensure that all "non-outlined" part do respect the regular expression of
231-
// of the step function
232-
// FIRST, we clean the string version of the step definition that has outline variable
233-
const cleanedStepFunc = regStepFunc.source
234-
.replace(/^\^/, "")
235-
// .replace( /\\\(/g, '(' )
236-
// .replace( /\\\)/g, ')')
237-
// .replace( /\\\^/g, '^')
238-
// .replace( /\\\$/g, '$')
239-
.replace(/\$$/, "");
240-
// .replace( /\([.\\]+[sSdDwWbB*][*?+]?\)|\(\[.*\](?:[+?*]{1}|\{\d\})\)/g, '' )
241-
242-
let currentScenarioPart;
243-
let currentStepFuncLeft = cleanedStepFunc;
244-
let currentScenarioDefLeft = scenarioDefinition;
245-
246-
//we step through each of the scenario outline variables
247-
// from there, we will try to detect any regexp present in the
248-
// step definition, so that we can ensure to find the right match
249-
while (
250-
(currentScenarioPart = /<[\w]*>/gi.exec(currentScenarioDefLeft)) != null
251-
) {
252-
let fixedPart = currentScenarioPart.input.substring(
253-
0,
254-
currentScenarioPart.index
255-
);
256-
let idxCutScenarioPart =
257-
currentScenarioPart.index + currentScenarioPart[0].length;
258-
259-
const regEscapedStepFunc = /\([a-zA-Z0!|,:?*+.^=${}><\\\-]+\)/g.exec(
260-
currentStepFuncLeft
261-
.replace(/\\\(/g, "(")
262-
.replace(/\\\)/g, ")")
263-
.replace(/\\\^/g, "^")
264-
.replace(/\\\$/g, "$")
265-
);
266-
const regStepFuncLeft = /\([a-zA-Z0!|,:?*+.^=${}><\\\-]+\)/g.exec(
267-
currentStepFuncLeft
268-
);
269-
270-
if (
271-
regStepFuncLeft &&
272-
regEscapedStepFunc.index == currentScenarioPart.index
273-
) {
274-
//if we have a regex inside our step function definition
275-
// and that regex is at the same position than our Outlined variable
276-
// we just need to check that the sentence match,
277-
// so we can "evaluate" the step function and remove the regex in it
278-
currentStepFuncLeft =
279-
regEscapedStepFunc.input.substring(0, regEscapedStepFunc.index) +
280-
currentStepFuncLeft.substring(
281-
regStepFuncLeft.index + regStepFuncLeft[0].length
282-
);
283-
} else if (
284-
regStepFuncLeft &&
285-
regStepFuncLeft.index < currentScenarioPart.index
286-
) {
287-
//if we have a regex inside our step function definition
288-
// but that regex is not at the same position than our outlined variable
289-
// we need to evaluate the regex against the scenario part
290-
const strRegexToEvaluate = regStepFuncLeft.input.substring(
291-
0,
292-
regStepFuncLeft.index + regStepFuncLeft[0].length
293-
);
294-
const regexToEvaluate = new RegExp(strRegexToEvaluate);
295-
const regIntermediatePart = regexToEvaluate.exec(
296-
currentScenarioPart.input
297-
);
298-
if (regIntermediatePart) {
299-
fixedPart = regStepFuncLeft.input.substring(
300-
0,
301-
regStepFuncLeft.index + regStepFuncLeft[0].length
302-
);
303-
idxCutScenarioPart = regIntermediatePart[0].length;
304-
}
305-
}
306-
307-
const partIndex = currentStepFuncLeft.indexOf(fixedPart);
308-
if (partIndex !== -1) {
309-
currentStepFuncLeft = currentStepFuncLeft.substring(
310-
partIndex + fixedPart.length
311-
);
312-
currentScenarioDefLeft =
313-
currentScenarioDefLeft.substring(idxCutScenarioPart);
314-
} else {
315-
return false;
316-
}
317-
}
318-
319-
return (
320-
(currentScenarioDefLeft === "" && currentStepFuncLeft === "") ||
321-
evaluateStepFuncEndVsScenarioEnd(
322-
currentStepFuncLeft,
323-
currentScenarioDefLeft
324-
)
325-
);
326-
};
327-
328-
const evaluateStepFuncEndVsScenarioEnd = (
329-
stepFunctionDef,
330-
scenarioDefinition
331-
) => {
332-
if (
333-
/\(.*(\?\:)?[.\\]*[sSdDwWbB*][*?+]?.*\)|\(\[.*\](?:[+?*]{1}|\{\d\})\)/g.test(
334-
stepFunctionDef
335-
)
336-
) {
337-
return new RegExp(stepFunctionDef).test(scenarioDefinition);
338-
}
339-
340-
return stepFunctionDef.endsWith(scenarioDefinition);
341-
};
210+
) =>
211+
stepDefinitionFunction.stepRegExp
212+
? scenarioSentence.match(stepDefinitionFunction.stepRegExp)
213+
: scenarioSentence === stepDefinitionFunction.stepExpression;
342214

343215
const injectVariable = (
344216
scenarioType,

0 commit comments

Comments
 (0)