@zohodesk/testinglibrary 0.1.8-stb-bdd-v14n → 0.1.8-stb-bdd-v15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,6 +9,7 @@ var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
|
9
9
|
var _fileUtils = require("../../../utils/fileUtils");
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
var _pathConfig = require("../../config/pathConfig");
|
|
12
|
+
var _logger = require("../../../utils/logger");
|
|
12
13
|
globalThis.testDataMap = new Map();
|
|
13
14
|
function createStepDataMap() {
|
|
14
15
|
const stepFilePath = (0, _pathConfig.getStepFilePath)();
|
|
@@ -29,8 +30,25 @@ function extractPageFixtures(filePath) {
|
|
|
29
30
|
code.split('\n').forEach(step => {
|
|
30
31
|
const trimmedStep = step.trim();
|
|
31
32
|
if (trimmedStep.startsWith('Given') || trimmedStep.startsWith('When') || trimmedStep.startsWith('Then') || trimmedStep.startsWith('And') || trimmedStep.startsWith('Step')) {
|
|
32
|
-
var sortedSpecInput = trimmedStep
|
|
33
|
-
testDataMap.set(trimmedStep
|
|
33
|
+
var sortedSpecInput = extractInputFrmStep(trimmedStep, filePath);
|
|
34
|
+
testDataMap.set(extractDescriptionFrmStep(trimmedStep), sortedSpecInput.pop());
|
|
34
35
|
}
|
|
35
36
|
});
|
|
37
|
+
}
|
|
38
|
+
function extractInputFrmStep(trimmedStep, filePath) {
|
|
39
|
+
try {
|
|
40
|
+
return trimmedStep.split(' ').slice(1).join('').match(/\((.*?)\)/)[1].match(/\{(.*?)\}/g).pop() || [""].pop();
|
|
41
|
+
} catch (error) {
|
|
42
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `${filePath} - Steps Has MisMatched Pattern`);
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function extractDescriptionFrmStep(trimmedStep) {
|
|
47
|
+
var refactoredDescription;
|
|
48
|
+
if (trimmedStep.match(/\((.*?)\)/g).pop().split('').indexOf(`'`) === 1) {
|
|
49
|
+
refactoredDescription = trimmedStep.replace(new RegExp(`'`, 'g'), `;`).match(/;(.*?);/).pop().replace(new RegExp(';', 'g'), ' ').trim();
|
|
50
|
+
} else {
|
|
51
|
+
refactoredDescription = trimmedStep.replace(new RegExp(`"`, 'g'), `;`).match(/;(.*?);/).pop().replace(new RegExp(';', 'g'), ' ').trim();
|
|
52
|
+
}
|
|
53
|
+
return refactoredDescription;
|
|
36
54
|
}
|
|
@@ -20,12 +20,12 @@ function stepReportHandle(Steps, Example) {
|
|
|
20
20
|
return [...resultSteps.split(medium)];
|
|
21
21
|
}
|
|
22
22
|
function testStep(keyword, description, pageFixtureUsed_Step, testData, stepDescription, options) {
|
|
23
|
-
return `await test.step('${keyword.trim()}
|
|
24
|
-
await $${keyword}(
|
|
23
|
+
return `await test.step('${keyword.trim()}:${stepDescription.replace(new RegExp(`'`, 'g'), " ")}',async() => {
|
|
24
|
+
await $${keyword}("${description}")(${pageFixtureUsed_Step},${testData})
|
|
25
25
|
})`;
|
|
26
26
|
}
|
|
27
27
|
function testSuite(description, scenariotestBlock, tags, options = null) {
|
|
28
|
-
return `\ntest.describe(
|
|
28
|
+
return `\ntest.describe("${description.replace(new RegExp('"', 'g'), '')}${tags.join(" ")}", () => {
|
|
29
29
|
${scenariotestBlock}
|
|
30
30
|
})`;
|
|
31
31
|
}
|
|
@@ -33,14 +33,14 @@ function testCase(steps, examples, description, pageFixtures, tags, option) {
|
|
|
33
33
|
if (examples.length >= 1) {
|
|
34
34
|
const exmapleScenario = examples.map(($ele, index) => {
|
|
35
35
|
var exampleDescription = Object.values($ele).map(val => {
|
|
36
|
-
return val.concat(
|
|
36
|
+
return val.concat(" ");
|
|
37
37
|
});
|
|
38
|
-
let
|
|
39
|
-
return testBlock(
|
|
38
|
+
let avoidRepetitionDescription = `Example : ${index + 1} - `.concat(exampleDescription.join(''));
|
|
39
|
+
return testBlock(avoidRepetitionDescription, stepReportHandle(steps, examples[index]), pageFixtures);
|
|
40
40
|
});
|
|
41
41
|
return testSuite(description, exmapleScenario.join('\n'), tags);
|
|
42
42
|
}
|
|
43
|
-
return testSuite(
|
|
43
|
+
return testSuite(`Title: ${description}`, testBlock(description, steps, pageFixtures), tags);
|
|
44
44
|
}
|
|
45
45
|
function testBlock(description, steps, pageFixtures) {
|
|
46
46
|
return `\ntest("${description}", async({${pageFixtures.join(',')}}) => {
|
|
@@ -54,7 +54,7 @@ function scenarioSnippet(scenario) {
|
|
|
54
54
|
var pageFixtureUsed_Step = testDataMap.get(`'${convertedStep}'`) || null;
|
|
55
55
|
/** Step Implementation Check (Walk Through Approach)*/
|
|
56
56
|
if (!pageFixtureUsed_Step) {
|
|
57
|
-
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `${step.
|
|
57
|
+
_logger.Logger.log(_logger.Logger.FAILURE_TYPE, `${step.stepDescription} Not Implemented`);
|
|
58
58
|
process.exit(0);
|
|
59
59
|
}
|
|
60
60
|
currentInputs.push(pageFixtureUsed_Step);
|