@zohodesk/testinglibrary 0.1.8-exp-bdd-v7 → 0.1.8-exp-bdd-v8

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.
@@ -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)((0, _fileUtils.resolveFilePath)(process.cwd(), 'uat', 'modules', '**', '**', '**', '**', '**', '**', '**', '**', '*.spec.js'), _getFilePath.isWindows);
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 = path.resolve(process.cwd(), FilePath);
18
+ const specFilePath = _path.default.resolve(process.cwd(), FilePath);
18
19
  require(specFilePath);
19
20
  });
20
21
  }
@@ -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("../utils/stringManipulation");
10
- var _fileUtils = require("../../utils/fileUtils");
11
- var _getFilePath = require("../../utils/getFilePath");
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)((0, _fileUtils.resolveFilePath)(process.cwd(), 'uat', 'modules', '**', '**', '**', '**', '**', '**', '**', '**', '*.spec.js'), _getFilePath.isWindows);
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)((0, _fileUtils.resolveFilePath)(process.cwd(), filePath), 'utf-8');
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 = (0, _fileUtils.resolveFilePath)(process.cwd(), 'uat', 'feature-gen', stepFilename);
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)((0, _fileUtils.resolveFilePath)(process.cwd(), 'uat', 'modules', '**', '**', '**', '**', '**', '**', '**', '**', '*.feature'), _getFilePath.isWindows);
23
- const generatedFolderPath = (0, _fileUtils.resolveFilePath)(process.cwd(), 'uat', 'feature-gen');
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 = (0, _fileUtils.resolveFilePath)(process.cwd(), filePath);
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);
@@ -18,12 +18,13 @@ function testSuite(description, scenariotestBlock, options) {
18
18
  })`;
19
19
  }
20
20
  function testCase(steps, examples, description, browserObjects, tags, option) {
21
- if (examples.length <= 1) {
21
+ if (examples.length >= 1) {
22
22
  const exmapleScenario = examples.map(($ele, index) => {
23
- var exmapleDescription = Object.values($ele).map(val => {
23
+ var exampleDescription = Object.values($ele).map(val => {
24
24
  return val.concat('-');
25
25
  });
26
- return testBlock(exmapleDescription.join('').concat(`Example-${index + 1}`), steps, browserObjects, tags);
26
+ let avoidRepitationDescription = exampleDescription.join('').concat(`Example-${index + 1}`);
27
+ return testBlock(avoidRepitationDescription, steps, browserObjects, tags);
27
28
  });
28
29
  return testSuite(description, exmapleScenario.join('\n'));
29
30
  }
@@ -34,18 +35,15 @@ function testBlock(description, steps, browserObjects, tags) {
34
35
  ${steps.join(`\n\t`)}
35
36
  })`;
36
37
  }
37
- function testFile(testCase, relativeFilePath, tags, options = null) {
38
+ function testFile(testCase, relativeFilePath, $tags, options = null) {
38
39
  return ` // ${relativeFilePath}
39
40
  import { test, createNativeBDD } from "${TESTING_LIBRARY}";
40
41
  const {$Given,$When,$Then,$And} = createNativeBDD()
42
+ \n
43
+ test.use({
44
+ $test: ({}, use) => use(test),
45
+ $tags: ({}, use, testInfo) => use(${JSON.stringify($tags)} \n [testInfo.titlePath.slice(2).join("|")] || [])
46
+ \n
41
47
  ${testCase.join('')}
42
48
  `;
43
- }
44
-
45
- // test.use({
46
- // $test: ({}, use) => use(test),
47
- // $tags: ({}, use, testInfo) => use({
48
- // "Clear searched results in setup left panel @edition_agent": ["@edition_agent"],
49
- // "get started link":[]
50
- // }[testInfo.titlePath.slice(2).join("|")] || []),
51
- // });
49
+ }
@@ -8,19 +8,20 @@ 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)((0, _fileUtils.resolveFilePath)('uat', 'modules', '**', '**', '**', '**', '**', '*.feature'), _getFilePath.isWindows);
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)((0, _fileUtils.resolveFilePath)(process.cwd(), filePath), 'utf-8'));
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
26
  var _$scenario$scenario;
26
27
  const $currentScenario = {
@@ -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
+ const $tags = {};
12
13
  featureContent.scenarios.forEach(scenario => {
13
- scenario.scenarioTags = featureContent.featureTags || [];
14
- // const $tags = tagsAsInput(featureContent)
14
+ scenario.scenarioTags = [...(scenario.scenarioTags = []), ...featureContent.featureTags] || [];
15
+ $tags = Object.assign($tags, handleInputTags(featureContent));
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,29 @@ 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, pageObject, 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);
53
54
  }
54
- function tagsAsInput(scenario) {
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) {
55
63
  if (scenario.examples.length >= 1) {
56
- var tagsInput = {};
57
- return scenario.examples.map(($ele, index) => {
64
+ var _tagsObjects = {};
65
+ scenario.examples.forEach(($ele, index) => {
58
66
  var exampleDescription = Object.values($ele).map(val => {
59
67
  return val.concat('-');
60
68
  });
61
- return Object.assign(tagsInput, {
69
+ Object.assign(_tagsObjects, {
62
70
  [exampleDescription.join('').concat(`Example-${index + 1}`)]: scenario.scenarioTags
63
71
  });
64
72
  });
73
+ return _tagsObjects;
65
74
  }
66
75
  return {
67
76
  [scenario.scenariodescription]: scenario.scenarioTags
68
77
  };
69
- }
70
- function browserObjectHandle(arrayofBrowserObjects) {
71
- var browserinputs = [];
72
- arrayofBrowserObjects.forEach(pageObject => {
73
- browserinputs = [...browserinputs, ...(0, _stringManipulation.removeAll)(pageObject, ['{', '}']).split(',')];
74
- });
75
- return (0, _stringManipulation.avoidDuplicate)(browserinputs);
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
- // }
78
+ }
@@ -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"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.1.8-exp-bdd-v7",
3
+ "version": "0.1.8-exp-bdd-v8",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {