@zohodesk/testinglibrary 0.1.8-stb-bdd-v24 → 0.1.8-stb-bdd-v25
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.
|
@@ -10,7 +10,7 @@ var _fileUtils = require("../../../utils/fileUtils");
|
|
|
10
10
|
var _path = _interopRequireDefault(require("path"));
|
|
11
11
|
var _pathConfig = require("../../config/pathConfig");
|
|
12
12
|
var _throwError = require("../../errors/throwError");
|
|
13
|
-
globalThis.testDataMap = new Map();
|
|
13
|
+
// globalThis.testDataMap = new Map();
|
|
14
14
|
function createStepDataMap() {
|
|
15
15
|
const stepFilePath = (0, _pathConfig.getStepFilePath)();
|
|
16
16
|
const processedSpecFile = [];
|
|
@@ -36,13 +36,17 @@ function extractPageFixtures(filePath) {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
function extractInputFrmStep(trimmedStep, filePath) {
|
|
39
|
+
var _inputNames$split;
|
|
39
40
|
var toRemovePattern = trimmedStep.match(/async\s*\(([^)]*)\)/)[1].match(/{(.*?)}/);
|
|
40
|
-
var
|
|
41
|
+
var inputNames = trimmedStep.match(/async\s*\(([^)]*)\)/)[1].replace(toRemovePattern[0], "$null") || [];
|
|
42
|
+
var filteredInputs = (_inputNames$split = inputNames.split(',')) === null || _inputNames$split === void 0 ? void 0 : _inputNames$split.slice(1);
|
|
43
|
+
if (filteredInputs.length) {
|
|
44
|
+
filteredInputs = filteredInputs.map(input => `"${input}"`);
|
|
45
|
+
}
|
|
41
46
|
try {
|
|
42
|
-
var _InputNames$split;
|
|
43
47
|
return {
|
|
44
48
|
stepPageFixtureName: trimmedStep.split(' ').slice(1).join('').match(/\((.*?)\)/)[1].match(/\{(.*?)\}/g).pop() || [false].pop(),
|
|
45
|
-
stepInputKey:
|
|
49
|
+
stepInputKey: filteredInputs
|
|
46
50
|
};
|
|
47
51
|
} catch (error) {
|
|
48
52
|
// Logger.log(Logger.FAILURE_TYPE,`${filePath} - Steps Has MisMatched Pattern`)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.traverseASTstep = traverseASTstep;
|
|
8
|
+
var _acorn = require("acorn");
|
|
9
|
+
var _fileUtils = require("../../../utils/fileUtils");
|
|
10
|
+
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
11
|
+
var _pathConfig = require("../../config/pathConfig");
|
|
12
|
+
globalThis.testDataMap = new Map();
|
|
13
|
+
async function extractFixtureFrmNode(node) {
|
|
14
|
+
var stepText;
|
|
15
|
+
return await new Promise(resolve => {
|
|
16
|
+
if ((node === null || node === void 0 ? void 0 : node.type) == "ExpressionStatement" || (node === null || node === void 0 ? void 0 : node.type) == "CallExpression" || (node === null || node === void 0 ? void 0 : node.type) == "ArrowFunctionExpression") {
|
|
17
|
+
extractFixtureFrmNode(node.expression);
|
|
18
|
+
}
|
|
19
|
+
if ((node === null || node === void 0 ? void 0 : node.type) == "CallExpression") {
|
|
20
|
+
if (node.arguments[0].type == "Literal") {
|
|
21
|
+
stepText = node.arguments[0].raw;
|
|
22
|
+
}
|
|
23
|
+
if (node.arguments[1].type == "ArrowFunctionExpression") {
|
|
24
|
+
let callbackInputs = [];
|
|
25
|
+
var fixtures;
|
|
26
|
+
node.arguments[1].params.forEach(input => {
|
|
27
|
+
if (input.type == "ObjectPattern") {
|
|
28
|
+
fixtures = getPageFixture(input.properties);
|
|
29
|
+
}
|
|
30
|
+
if (input.type == "Identifier") {
|
|
31
|
+
callbackInputs.push(input.name);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
testDataMap.set(stepText, {
|
|
35
|
+
stepPageFixtureName: combineAllFixture(fixtures),
|
|
36
|
+
stepInputKey: callbackInputs.map(element => `"${element}"`)
|
|
37
|
+
});
|
|
38
|
+
resolve();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
function combineAllFixture(fixturesArray) {
|
|
44
|
+
if (fixturesArray.length) {
|
|
45
|
+
return `{${fixturesArray}}`;
|
|
46
|
+
}
|
|
47
|
+
const lastFixture = fixturesArray.pop();
|
|
48
|
+
const allFixture = fixturesArray.join(",");
|
|
49
|
+
return `{${allFixture}${lastFixture}}`;
|
|
50
|
+
}
|
|
51
|
+
function traverseASTstep() {
|
|
52
|
+
var $promise = [];
|
|
53
|
+
_fastGlob.default.globSync((0, _pathConfig.getStepFilePath)(), {
|
|
54
|
+
dot: true,
|
|
55
|
+
cwd: process.cwd()
|
|
56
|
+
}).forEach(filePath => {
|
|
57
|
+
$promise.push(nodeAST((0, _fileUtils.readFileContents)(filePath)));
|
|
58
|
+
});
|
|
59
|
+
Promise.all($promise);
|
|
60
|
+
}
|
|
61
|
+
function nodeAST(stepContent) {
|
|
62
|
+
const options = {
|
|
63
|
+
ecmaVersion: 2020
|
|
64
|
+
};
|
|
65
|
+
const $node = (0, _acorn.parse)(stepContent, options).body;
|
|
66
|
+
$node.forEach(node => {
|
|
67
|
+
extractFixtureFrmNode(node);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
function getPageFixture(fixtureNode) {
|
|
71
|
+
return fixtureNode.map($element => {
|
|
72
|
+
var _$element$key;
|
|
73
|
+
return ($element === null || $element === void 0 || (_$element$key = $element.key) === null || _$element$key === void 0 ? void 0 : _$element$key.name) || "page";
|
|
74
|
+
});
|
|
75
|
+
}
|
|
@@ -10,15 +10,17 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
10
10
|
var _featureFileParer = require("../cucumber/featureFileParer");
|
|
11
11
|
var _testStructure = require("../testStructure");
|
|
12
12
|
var _fileUtils = require("../../../utils/fileUtils");
|
|
13
|
-
var _extractTestInputs = require("./extractTestInputs");
|
|
14
13
|
var _pathConfig = require("../../config/pathConfig");
|
|
14
|
+
var _parserSteps = require("./parserSteps");
|
|
15
|
+
// import { createStepDataMap } from './extractTestInputs';
|
|
16
|
+
|
|
15
17
|
function stepFileCreation(parsedFeatureContent, stepFilename, featureFilePath) {
|
|
16
18
|
const stepsFilePath = _path.default.resolve(process.cwd(), 'uat', '.feature-gen', stepFilename);
|
|
17
19
|
const stepsSnippets = (0, _testStructure.testSnippet)(parsedFeatureContent, featureFilePath);
|
|
18
20
|
(0, _fileUtils.writeFileContents)(stepsFilePath, stepsSnippets);
|
|
19
21
|
}
|
|
20
22
|
async function generateSpecFiles() {
|
|
21
|
-
await (0,
|
|
23
|
+
await (0, _parserSteps.traverseASTstep)();
|
|
22
24
|
const featureFilePattern = (0, _pathConfig.getFeatureFilePath)();
|
|
23
25
|
const featureFileFolderPath = _path.default.resolve(process.cwd(), 'uat', '.feature-gen');
|
|
24
26
|
if (!(0, _fileUtils.checkIfFileExists)(featureFileFolderPath)) {
|