@zohodesk/testinglibrary 0.1.8-exp-bdd-v7 → 0.1.8-exp-bdd-v9
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.
- package/build/bdd-poc/core-runner/runner.js +4 -3
- package/build/bdd-poc/test/cucumber/featureFileParer.js +3 -1
- package/build/bdd-poc/test/stepGenerate/extractTestInputs.js +7 -6
- package/build/bdd-poc/test/stepGenerate/stepFileGenerate.js +4 -4
- package/build/bdd-poc/test/stepGenerate/stepsnippets.js +25 -19
- package/build/bdd-poc/test/testDataMap.js +7 -6
- package/build/bdd-poc/test/testStructure.js +33 -30
- package/build/bdd-poc/utils/stringManipulation.js +1 -1
- package/build/utils/fileUtils.js +0 -1
- package/package.json +1 -1
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.stepFileMap = stepFileMap;
|
|
7
8
|
var _fastGlob = require("fast-glob");
|
|
8
|
-
var _fileUtils = require("../../utils/fileUtils");
|
|
9
9
|
var _stringManipulation = require("../utils/stringManipulation");
|
|
10
10
|
var _getFilePath = require("../../utils/getFilePath");
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
12
|
async function stepFileMap() {
|
|
12
|
-
const actualSpecPattern = (0, _stringManipulation.filePathPattern)(
|
|
13
|
+
const actualSpecPattern = (0, _stringManipulation.filePathPattern)(_path.default.resolve(process.cwd(), 'uat', 'modules', '**', '**', '**', '**', '**', '**', '**', '**', '*.spec.js'), _getFilePath.isWindows);
|
|
13
14
|
await (0, _fastGlob.globSync)(actualSpecPattern, {
|
|
14
15
|
dot: true,
|
|
15
16
|
cwd: process.cwd()
|
|
16
17
|
}).forEach(FilePath => {
|
|
17
|
-
const specFilePath =
|
|
18
|
+
const specFilePath = _path.default.resolve(process.cwd(), FilePath);
|
|
18
19
|
require(specFilePath);
|
|
19
20
|
});
|
|
20
21
|
}
|
|
@@ -12,7 +12,8 @@ function parseFeature(featureFileContent) {
|
|
|
12
12
|
var currentFeature = {
|
|
13
13
|
feature: "",
|
|
14
14
|
featureTags: [],
|
|
15
|
-
scenarios: []
|
|
15
|
+
scenarios: [],
|
|
16
|
+
featureBackGround: []
|
|
16
17
|
};
|
|
17
18
|
var isBackgroundExist;
|
|
18
19
|
currentFeature.feature = gherkinDocument.feature.name;
|
|
@@ -63,6 +64,7 @@ function parseFeature(featureFileContent) {
|
|
|
63
64
|
scenarioSteps.background = isBackgroundExist || [];
|
|
64
65
|
currentFeature.scenarios.push(scenarioSteps);
|
|
65
66
|
});
|
|
67
|
+
currentFeature.featureBackGround = currentFeature.scenarios[0].background;
|
|
66
68
|
return currentFeature;
|
|
67
69
|
}
|
|
68
70
|
function testDataExtraction(tableHeader, tableBody) {
|
|
@@ -6,12 +6,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.readStepFile = readStepFile;
|
|
8
8
|
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
9
|
-
var _stringManipulation = require("
|
|
10
|
-
var _fileUtils = require("
|
|
11
|
-
var
|
|
9
|
+
var _stringManipulation = require("../../utils/stringManipulation");
|
|
10
|
+
var _fileUtils = require("../../../utils/fileUtils");
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
12
|
+
var _getFilePath = require("../../../utils/getFilePath");
|
|
12
13
|
globalThis.inputsParamterMap = new Map();
|
|
13
14
|
async function readStepFile() {
|
|
14
|
-
const stepFilePath = (0, _stringManipulation.filePathPattern)(
|
|
15
|
+
const stepFilePath = (0, _stringManipulation.filePathPattern)(_path.default.resolve(process.cwd(), 'uat', 'modules', '**', '**', '**', '**', '**', '**', '**', '**', '*.spec.js'), _getFilePath.isWindows);
|
|
15
16
|
const processedSpecFile = [];
|
|
16
17
|
return new Promise(resolve => {
|
|
17
18
|
_fastGlob.default.globSync(stepFilePath, {
|
|
@@ -25,10 +26,10 @@ async function readStepFile() {
|
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
function extractBrowserObjects(filePath) {
|
|
28
|
-
const code = (0, _fileUtils.readFileContents)(
|
|
29
|
+
const code = (0, _fileUtils.readFileContents)(_path.default.resolve(process.cwd(), filePath), 'utf-8');
|
|
29
30
|
code.split('\n').forEach(step => {
|
|
30
31
|
const trimmedStep = step.trim();
|
|
31
|
-
if (trimmedStep.startsWith('Given') || trimmedStep.startsWith('When') || trimmedStep.startsWith('Then')) {
|
|
32
|
+
if (trimmedStep.startsWith('Given') || trimmedStep.startsWith('When') || trimmedStep.startsWith('Then') || trimmedStep.startsWith('And') || trimmedStep.startsWith('Step')) {
|
|
32
33
|
var sortedSpecInput = trimmedStep.split(' ').slice(1).join('').match(/\((.*?)\)/)[1].match(/\{(.*?)\}/g) || [];
|
|
33
34
|
inputsParamterMap.set(trimmedStep.replace(/"/g, `'`).match(/'(.*?)'/g).pop(), sortedSpecInput.pop());
|
|
34
35
|
}
|
|
@@ -14,13 +14,13 @@ var _stringManipulation = require("../../utils/stringManipulation");
|
|
|
14
14
|
var _getFilePath = require("../../../utils/getFilePath");
|
|
15
15
|
var _extractTestInputs = require("./extractTestInputs");
|
|
16
16
|
function stepFileCreation(featureContent, stepFilename, featureFilePath) {
|
|
17
|
-
const stepsFilePath =
|
|
17
|
+
const stepsFilePath = _path.default.resolve(process.cwd(), 'uat', 'feature-gen', stepFilename);
|
|
18
18
|
const stepsSnippets = (0, _testStructure.testSnippet)(featureContent, featureFilePath);
|
|
19
19
|
(0, _fileUtils.writeFileContents)(stepsFilePath, stepsSnippets);
|
|
20
20
|
}
|
|
21
21
|
async function generateSpecFiles() {
|
|
22
|
-
const featureFilePattern = (0, _stringManipulation.filePathPattern)(
|
|
23
|
-
const generatedFolderPath =
|
|
22
|
+
const featureFilePattern = (0, _stringManipulation.filePathPattern)(_path.default.resolve(process.cwd(), 'uat', 'modules', '**', '**', '**', '**', '**', '**', '**', '**', '*.feature'), _getFilePath.isWindows);
|
|
23
|
+
const generatedFolderPath = _path.default.resolve(process.cwd(), 'uat', 'feature-gen');
|
|
24
24
|
if (!(0, _fileUtils.checkIfFileExists)(generatedFolderPath)) {
|
|
25
25
|
(0, _fileUtils.createFolderSync)(generatedFolderPath, {
|
|
26
26
|
recursive: true
|
|
@@ -31,7 +31,7 @@ async function generateSpecFiles() {
|
|
|
31
31
|
dot: true,
|
|
32
32
|
cwd: process.cwd()
|
|
33
33
|
}).forEach(filePath => {
|
|
34
|
-
const featurefilePath =
|
|
34
|
+
const featurefilePath = _path.default.resolve(process.cwd(), filePath);
|
|
35
35
|
const featureContent = (0, _featureFileParer.parseFeature)((0, _fileUtils.readFileContents)(featurefilePath, 'utf-8'));
|
|
36
36
|
const fileName = _path.default.basename(filePath).replace('.feature', '.spec.js');
|
|
37
37
|
stepFileCreation(featureContent, fileName, filePath);
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.TESTING_LIBRARY = void 0;
|
|
7
|
+
exports.testBackGround = testBackGround;
|
|
7
8
|
exports.testCase = testCase;
|
|
8
9
|
exports.testFile = testFile;
|
|
9
10
|
exports.testStep = testStep;
|
|
@@ -12,40 +13,45 @@ const TESTING_LIBRARY = exports.TESTING_LIBRARY = '@zohodesk/testinglibrary';
|
|
|
12
13
|
function testStep(keyword, description, browserObject, testData, options) {
|
|
13
14
|
return `await $${keyword}('${description}')(${browserObject},${testData})\n`;
|
|
14
15
|
}
|
|
15
|
-
function testSuite(description, scenariotestBlock, options) {
|
|
16
|
-
return `\ntest.describe('${description}', () => {
|
|
16
|
+
function testSuite(description, scenariotestBlock, tags, background, options = null) {
|
|
17
|
+
return `\ntest.describe('${description}${tags.join(" ")}', () => {
|
|
18
|
+
${background}
|
|
19
|
+
\n
|
|
17
20
|
${scenariotestBlock}
|
|
18
21
|
})`;
|
|
19
22
|
}
|
|
20
|
-
function testCase(steps, examples, description, browserObjects, tags, option) {
|
|
21
|
-
if (examples.length
|
|
23
|
+
function testCase(steps, examples, description, browserObjects, tags, background, option) {
|
|
24
|
+
if (examples.length >= 1) {
|
|
22
25
|
const exmapleScenario = examples.map(($ele, index) => {
|
|
23
|
-
var
|
|
26
|
+
var exampleDescription = Object.values($ele).map(val => {
|
|
24
27
|
return val.concat('-');
|
|
25
28
|
});
|
|
26
|
-
|
|
29
|
+
let avoidRepitationDescription = exampleDescription.join('').concat(`Example-${index + 1}`);
|
|
30
|
+
return testBlock(avoidRepitationDescription, steps, browserObjects);
|
|
27
31
|
});
|
|
28
|
-
return testSuite(description, exmapleScenario.join('\n'));
|
|
32
|
+
return testSuite(description, exmapleScenario.join('\n'), tags, background);
|
|
29
33
|
}
|
|
30
|
-
return testSuite(`${description}-title`, testBlock(description, steps, browserObjects, tags)
|
|
34
|
+
return testSuite(`${description}-title`, testBlock(description, steps, browserObjects), tags, background);
|
|
31
35
|
}
|
|
32
|
-
function testBlock(description, steps, browserObjects
|
|
33
|
-
return `\ntest("${description}
|
|
36
|
+
function testBlock(description, steps, browserObjects) {
|
|
37
|
+
return `\ntest("${description}", async({${browserObjects.join(',')}}) => {
|
|
34
38
|
${steps.join(`\n\t`)}
|
|
35
39
|
})`;
|
|
36
40
|
}
|
|
37
|
-
function testFile(testCase, relativeFilePath, tags, options = null) {
|
|
41
|
+
function testFile(testCase, relativeFilePath, $tags, options = null) {
|
|
38
42
|
return ` // ${relativeFilePath}
|
|
39
43
|
import { test, createNativeBDD } from "${TESTING_LIBRARY}";
|
|
40
44
|
const {$Given,$When,$Then,$And} = createNativeBDD()
|
|
45
|
+
\n
|
|
46
|
+
test.use({
|
|
47
|
+
$test: ({}, use) => use(test),
|
|
48
|
+
$tags: ({}, use, testInfo) => use(${JSON.stringify($tags)} \n [testInfo.titlePath.slice(2).join("|")] || [])
|
|
49
|
+
\n
|
|
41
50
|
${testCase.join('')}
|
|
42
51
|
`;
|
|
43
52
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// "get started link":[]
|
|
50
|
-
// }[testInfo.titlePath.slice(2).join("|")] || []),
|
|
51
|
-
// });
|
|
53
|
+
function testBackGround(backgroundSteps, inputs) {
|
|
54
|
+
return ` test.beforeEach(async ({${inputs.join(',')}}) => { \n
|
|
55
|
+
${backgroundSteps.join(`\n`)}
|
|
56
|
+
});`;
|
|
57
|
+
}
|
|
@@ -8,21 +8,22 @@ exports.testDataCreation = testDataCreation;
|
|
|
8
8
|
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
9
9
|
var _testStructure = require("./testStructure");
|
|
10
10
|
var _fileUtils = require("../../utils/fileUtils");
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
12
|
var _parserCucumber = _interopRequireDefault(require("./cucumber/parserCucumber"));
|
|
12
13
|
var _stringManipulation = require("../utils/stringManipulation");
|
|
13
14
|
var _getFilePath = require("../../utils/getFilePath");
|
|
14
15
|
async function testDataCreation() {
|
|
15
16
|
var exampleSteps = [];
|
|
16
17
|
const globalTestdata = new Map();
|
|
17
|
-
const actualStepFilePath = (0, _stringManipulation.filePathPattern)(
|
|
18
|
+
const actualStepFilePath = (0, _stringManipulation.filePathPattern)(_path.default.resolve('uat', 'modules', '**', '**', '**', '**', '**', '*.feature'), _getFilePath.isWindows);
|
|
18
19
|
await _fastGlob.default.globSync(actualStepFilePath, {
|
|
19
20
|
dot: true,
|
|
20
21
|
cwd: process.cwd()
|
|
21
22
|
}).forEach(filePath => {
|
|
22
23
|
var body, header;
|
|
23
|
-
var gherkinDocument = (0, _parserCucumber.default)((0, _fileUtils.readFileContents)(
|
|
24
|
+
var gherkinDocument = (0, _parserCucumber.default)((0, _fileUtils.readFileContents)(_path.default.resolve(process.cwd(), filePath), 'utf-8'));
|
|
24
25
|
gherkinDocument.feature.children.forEach($scenario => {
|
|
25
|
-
var _$scenario$scenario;
|
|
26
|
+
var _$scenario$scenario, _$scenario$scenario2;
|
|
26
27
|
const $currentScenario = {
|
|
27
28
|
currentArgument: '',
|
|
28
29
|
dataTableStep: '',
|
|
@@ -57,10 +58,10 @@ async function testDataCreation() {
|
|
|
57
58
|
if (typeof $scenario.background === Object) {
|
|
58
59
|
return;
|
|
59
60
|
}
|
|
60
|
-
if ($scenario.scenario.examples.length) {
|
|
61
|
-
var _$scenario$
|
|
61
|
+
if ((_$scenario$scenario2 = $scenario.scenario) !== null && _$scenario$scenario2 !== void 0 && (_$scenario$scenario2 = _$scenario$scenario2.examples) !== null && _$scenario$scenario2 !== void 0 && _$scenario$scenario2.length) {
|
|
62
|
+
var _$scenario$scenario3;
|
|
62
63
|
exampleSteps = $scenario.scenario.steps.map(element => (0, _testStructure.extactStepArgs)(element.text).refactoredStep);
|
|
63
|
-
(_$scenario$
|
|
64
|
+
(_$scenario$scenario3 = $scenario.scenario) === null || _$scenario$scenario3 === void 0 || _$scenario$scenario3.examples.map(example => {
|
|
64
65
|
var _example$tableHeader;
|
|
65
66
|
body = example === null || example === void 0 ? void 0 : example.tableBody.map(cell => {
|
|
66
67
|
return cell === null || cell === void 0 ? void 0 : cell.cells.map(example => example.value);
|
|
@@ -9,13 +9,14 @@ var _stringManipulation = require("../utils/stringManipulation");
|
|
|
9
9
|
var _stepsnippets = require("./stepGenerate/stepsnippets");
|
|
10
10
|
function testSnippet(featureContent, featureFilePath) {
|
|
11
11
|
var currentScenarios = [];
|
|
12
|
+
var $tags = {};
|
|
12
13
|
featureContent.scenarios.forEach(scenario => {
|
|
13
|
-
scenario.scenarioTags = featureContent.featureTags
|
|
14
|
-
|
|
14
|
+
scenario.scenarioTags = [...scenario.scenarioTags, ...featureContent.featureTags];
|
|
15
|
+
$tags = Object.assign($tags, handleInputTags(scenario));
|
|
15
16
|
const _constructStep = scenarioSnippet(scenario);
|
|
16
17
|
currentScenarios.push(_constructStep);
|
|
17
18
|
});
|
|
18
|
-
return (0, _stepsnippets.testFile)(currentScenarios, featureFilePath);
|
|
19
|
+
return (0, _stepsnippets.testFile)(currentScenarios, featureFilePath, $tags);
|
|
19
20
|
}
|
|
20
21
|
function extactStepArgs(step) {
|
|
21
22
|
var inputParam = [];
|
|
@@ -49,43 +50,45 @@ function scenarioSnippet(scenario) {
|
|
|
49
50
|
return;
|
|
50
51
|
});
|
|
51
52
|
const pageObject = browserObjectHandle(currentInputs);
|
|
52
|
-
return (0, _stepsnippets.testCase)(currentStep, scenario === null || scenario === void 0 ? void 0 : scenario.examples, scenario === null || scenario === void 0 ? void 0 : scenario.scenariodescription, scenario.scenarioTags,
|
|
53
|
+
return (0, _stepsnippets.testCase)(currentStep, scenario === null || scenario === void 0 ? void 0 : scenario.examples, scenario === null || scenario === void 0 ? void 0 : scenario.scenariodescription, pageObject, scenario.scenarioTags, backgroundHandle(scenario.background));
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
function browserObjectHandle(arrayofBrowserObjects) {
|
|
56
|
+
var browserinputs = [];
|
|
57
|
+
arrayofBrowserObjects.forEach(pageObject => {
|
|
58
|
+
browserinputs = [...browserinputs, ...(0, _stringManipulation.removeAll)(pageObject, ['{', '}']).split(',')];
|
|
59
|
+
});
|
|
60
|
+
return (0, _stringManipulation.avoidDuplicate)(browserinputs);
|
|
61
|
+
}
|
|
62
|
+
function handleInputTags(scenario) {
|
|
63
|
+
var _scenario$examples;
|
|
64
|
+
if (((_scenario$examples = scenario.examples) === null || _scenario$examples === void 0 ? void 0 : _scenario$examples.length) >= 1) {
|
|
65
|
+
var _tagsObjects = {};
|
|
66
|
+
scenario.examples.forEach(($ele, index) => {
|
|
58
67
|
var exampleDescription = Object.values($ele).map(val => {
|
|
59
68
|
return val.concat('-');
|
|
60
69
|
});
|
|
61
|
-
|
|
70
|
+
Object.assign(_tagsObjects, {
|
|
62
71
|
[exampleDescription.join('').concat(`Example-${index + 1}`)]: scenario.scenarioTags
|
|
63
72
|
});
|
|
64
73
|
});
|
|
74
|
+
return _tagsObjects;
|
|
65
75
|
}
|
|
66
76
|
return {
|
|
67
77
|
[scenario.scenariodescription]: scenario.scenarioTags
|
|
68
78
|
};
|
|
69
79
|
}
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
80
|
+
function backgroundHandle(background) {
|
|
81
|
+
const currentBackground = [];
|
|
82
|
+
const backgroundInput = [];
|
|
83
|
+
background.forEach(b_scenario => {
|
|
84
|
+
var {
|
|
85
|
+
refactoredStep,
|
|
86
|
+
currentArgument
|
|
87
|
+
} = extactStepArgs(b_scenario.stepDescription);
|
|
88
|
+
var input = inputsParamterMap.get(`'${refactoredStep}'`);
|
|
89
|
+
backgroundInput.push(input);
|
|
90
|
+
currentBackground.push((0, _stepsnippets.testStep)(b_scenario.keyword, refactoredStep, input, currentArgument.join(',')));
|
|
91
|
+
return;
|
|
74
92
|
});
|
|
75
|
-
return (0,
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// function handleInputTags(scenario){
|
|
79
|
-
// if(scenario.examples.length >= 1){
|
|
80
|
-
// var obj = {}
|
|
81
|
-
// scenario.examples.forEach(($ele, index) => {
|
|
82
|
-
// var exampleDescription = Object.values($ele).map((val) => {
|
|
83
|
-
// return val.concat('-');
|
|
84
|
-
// });
|
|
85
|
-
// Object.assign(obj,{ [exampleDescription.join('').concat(`Example-${index + 1}`)]: scenario.scenarioTags })
|
|
86
|
-
|
|
87
|
-
// });
|
|
88
|
-
// return obj
|
|
89
|
-
// }
|
|
90
|
-
// return { [scenario.scenariodescription] : scenario.scenarioTags };
|
|
91
|
-
// }
|
|
93
|
+
return (0, _stepsnippets.testBackGround)(currentBackground, browserObjectHandle(backgroundInput));
|
|
94
|
+
}
|
package/build/utils/fileUtils.js
CHANGED
|
@@ -9,7 +9,6 @@ exports.createFolderSync = createFolderSync;
|
|
|
9
9
|
exports.deleteFile = deleteFile;
|
|
10
10
|
exports.deleteFolder = deleteFolder;
|
|
11
11
|
exports.readFileContents = readFileContents;
|
|
12
|
-
exports.resolveFilePath = resolveFilePath;
|
|
13
12
|
exports.writeFileContents = writeFileContents;
|
|
14
13
|
var _fs = _interopRequireWildcard(require("fs"));
|
|
15
14
|
var _path = _interopRequireDefault(require("path"));
|