@zohodesk/testinglibrary 0.1.8-stb-bdd-v14n → 0.1.8-stb-bdd-v16
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.
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.throwNotImplementError = throwNotImplementError;
|
|
7
|
+
var _logger = require("../../utils/logger");
|
|
8
|
+
function throwNotImplementError(step, stepInSpec, keyword) {
|
|
9
|
+
return _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `
|
|
10
|
+
\n ${step} - Not Implemented
|
|
11
|
+
\n ${keyword}(${stepInSpec},async({page}) => {
|
|
12
|
+
\n ..........................................
|
|
13
|
+
\n }
|
|
14
|
+
`);
|
|
15
|
+
}
|
|
@@ -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);
|
|
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(',')}}) => {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.extractStepArgument = extractStepArgument;
|
|
7
7
|
exports.testSnippet = testSnippet;
|
|
8
8
|
var _logger = require("../../utils/logger");
|
|
9
|
+
var _throwError = require("../errors/throwError");
|
|
9
10
|
var _stringManipulation = require("../utils/stringManipulation");
|
|
10
11
|
var _stepsnippets = require("./stepGenerate/stepsnippets");
|
|
11
12
|
function testSnippet(parsedFeature, featureFilePath) {
|
|
@@ -51,10 +52,10 @@ function scenarioSnippet(scenario) {
|
|
|
51
52
|
convertedStep,
|
|
52
53
|
currentArgument
|
|
53
54
|
} = extractStepArgument(step.stepDescription);
|
|
54
|
-
var pageFixtureUsed_Step = testDataMap.get(
|
|
55
|
+
var pageFixtureUsed_Step = testDataMap.get(convertedStep) || null;
|
|
55
56
|
/** Step Implementation Check (Walk Through Approach)*/
|
|
56
57
|
if (!pageFixtureUsed_Step) {
|
|
57
|
-
|
|
58
|
+
(0, _throwError.throwNotImplementError)(step.stepDescription, convertedStep, step.keyword);
|
|
58
59
|
process.exit(0);
|
|
59
60
|
}
|
|
60
61
|
currentInputs.push(pageFixtureUsed_Step);
|