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

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/bin/cli.js CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  require('../build/lib/cli');
@@ -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) {
@@ -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,8 +13,8 @@ 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, options = null) {
17
+ return `\ntest.describe('${description}${tags.join(" ")}', () => {
17
18
  ${scenariotestBlock}
18
19
  })`;
19
20
  }
@@ -24,18 +25,18 @@ function testCase(steps, examples, description, browserObjects, tags, option) {
24
25
  return val.concat('-');
25
26
  });
26
27
  let avoidRepitationDescription = exampleDescription.join('').concat(`Example-${index + 1}`);
27
- return testBlock(avoidRepitationDescription, steps, browserObjects, tags);
28
+ return testBlock(avoidRepitationDescription, steps, browserObjects);
28
29
  });
29
- return testSuite(description, exmapleScenario.join('\n'));
30
+ return testSuite(description, exmapleScenario.join('\n'), tags);
30
31
  }
31
- return testSuite(`${description}-title`, testBlock(description, steps, browserObjects, tags));
32
+ return testSuite(`${description}-title`, testBlock(description, steps, browserObjects), tags);
32
33
  }
33
- function testBlock(description, steps, browserObjects, tags) {
34
- return `\ntest("${description} ${tags.join(" ")}", async({${browserObjects.join(',')}}) => {
34
+ function testBlock(description, steps, browserObjects) {
35
+ return `\ntest("${description}", async({${browserObjects.join(',')}}) => {
35
36
  ${steps.join(`\n\t`)}
36
37
  })`;
37
38
  }
38
- function testFile(testCase, relativeFilePath, $tags, options = null) {
39
+ function testFile(testCase, relativeFilePath, $tags, backgroundScenario = " ", options = null) {
39
40
  return ` // ${relativeFilePath}
40
41
  import { test, createNativeBDD } from "${TESTING_LIBRARY}";
41
42
  const {$Given,$When,$Then,$And} = createNativeBDD()
@@ -43,7 +44,15 @@ function testFile(testCase, relativeFilePath, $tags, options = null) {
43
44
  test.use({
44
45
  $test: ({}, use) => use(test),
45
46
  $tags: ({}, use, testInfo) => use(${JSON.stringify($tags)} \n [testInfo.titlePath.slice(2).join("|")] || [])
46
- \n
47
+ })
48
+ \n
49
+ ${backgroundScenario}
50
+ \n
47
51
  ${testCase.join('')}
48
52
  `;
53
+ }
54
+ function testBackGround(backgroundSteps, inputs) {
55
+ return ` test.beforeEach(async ({${inputs.join(',')}}) => { \n
56
+ ${backgroundSteps.join(`\n`)}
57
+ });`;
49
58
  }
@@ -8,14 +8,14 @@ exports.expressionHandle = expressionHandle;
8
8
  var _tagProcessor = require("../../core/playwright/tag-processor");
9
9
  const editionOrder = ['Free', 'Express', 'Standard', 'Professional', 'Enterprise'];
10
10
  function allowedTags(userArgs) {
11
- let tags = userArgs['tags'] || null;
11
+ let tags = (userArgs === null || userArgs === void 0 ? void 0 : userArgs.tags) || null;
12
12
  if (tags !== null) {
13
13
  if (Array.isArray(tags)) {
14
14
  return buildGrepTags(tags, '|');
15
15
  }
16
16
  return tags;
17
17
  }
18
- let edition = userArgs['edition'] || null;
18
+ let edition = (userArgs === null || userArgs === void 0 ? void 0 : userArgs.edition) || null;
19
19
  if (edition !== null) {
20
20
  const editionFrmCli = edition.split(',');
21
21
  if (editionFrmCli.length === 1) {
@@ -23,7 +23,7 @@ async function testDataCreation() {
23
23
  var body, header;
24
24
  var gherkinDocument = (0, _parserCucumber.default)((0, _fileUtils.readFileContents)(_path.default.resolve(process.cwd(), filePath), 'utf-8'));
25
25
  gherkinDocument.feature.children.forEach($scenario => {
26
- var _$scenario$scenario;
26
+ var _$scenario$scenario, _$scenario$scenario2;
27
27
  const $currentScenario = {
28
28
  currentArgument: '',
29
29
  dataTableStep: '',
@@ -58,10 +58,10 @@ async function testDataCreation() {
58
58
  if (typeof $scenario.background === Object) {
59
59
  return;
60
60
  }
61
- if ($scenario.scenario.examples.length) {
62
- var _$scenario$scenario2;
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;
63
63
  exampleSteps = $scenario.scenario.steps.map(element => (0, _testStructure.extactStepArgs)(element.text).refactoredStep);
64
- (_$scenario$scenario2 = $scenario.scenario) === null || _$scenario$scenario2 === void 0 || _$scenario$scenario2.examples.map(example => {
64
+ (_$scenario$scenario3 = $scenario.scenario) === null || _$scenario$scenario3 === void 0 || _$scenario$scenario3.examples.map(example => {
65
65
  var _example$tableHeader;
66
66
  body = example === null || example === void 0 ? void 0 : example.tableBody.map(cell => {
67
67
  return cell === null || cell === void 0 ? void 0 : cell.cells.map(example => example.value);
@@ -8,14 +8,18 @@ exports.testSnippet = testSnippet;
8
8
  var _stringManipulation = require("../utils/stringManipulation");
9
9
  var _stepsnippets = require("./stepGenerate/stepsnippets");
10
10
  function testSnippet(featureContent, featureFilePath) {
11
+ var _featureContent$featu;
11
12
  var currentScenarios = [];
12
- const $tags = {};
13
+ var $tags = {};
13
14
  featureContent.scenarios.forEach(scenario => {
14
- scenario.scenarioTags = [...(scenario.scenarioTags = []), ...featureContent.featureTags] || [];
15
- $tags = Object.assign($tags, handleInputTags(featureContent));
15
+ scenario.scenarioTags = [...scenario.scenarioTags, ...featureContent.featureTags];
16
+ $tags = Object.assign($tags, handleInputTags(scenario));
16
17
  const _constructStep = scenarioSnippet(scenario);
17
18
  currentScenarios.push(_constructStep);
18
19
  });
20
+ if ((_featureContent$featu = featureContent.featureBackGround) !== null && _featureContent$featu !== void 0 && _featureContent$featu.length) {
21
+ return (0, _stepsnippets.testFile)(currentScenarios, featureFilePath, $tags, backgroundHandle(featureContent.featureBackGround));
22
+ }
19
23
  return (0, _stepsnippets.testFile)(currentScenarios, featureFilePath, $tags);
20
24
  }
21
25
  function extactStepArgs(step) {
@@ -53,14 +57,15 @@ function scenarioSnippet(scenario) {
53
57
  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);
54
58
  }
55
59
  function browserObjectHandle(arrayofBrowserObjects) {
56
- var browserinputs = [];
60
+ var browserInputs = [];
57
61
  arrayofBrowserObjects.forEach(pageObject => {
58
- browserinputs = [...browserinputs, ...(0, _stringManipulation.removeAll)(pageObject, ['{', '}']).split(',')];
62
+ browserinputs = [...browserInputs, ...(0, _stringManipulation.removeAll)(pageObject, ['{', '}']).split(',')];
59
63
  });
60
- return (0, _stringManipulation.avoidDuplicate)(browserinputs);
64
+ return (0, _stringManipulation.avoidDuplicate)(browserInputs);
61
65
  }
62
66
  function handleInputTags(scenario) {
63
- if (scenario.examples.length >= 1) {
67
+ var _scenario$examples;
68
+ if (((_scenario$examples = scenario.examples) === null || _scenario$examples === void 0 ? void 0 : _scenario$examples.length) >= 1) {
64
69
  var _tagsObjects = {};
65
70
  scenario.examples.forEach(($ele, index) => {
66
71
  var exampleDescription = Object.values($ele).map(val => {
@@ -75,4 +80,19 @@ function handleInputTags(scenario) {
75
80
  return {
76
81
  [scenario.scenariodescription]: scenario.scenarioTags
77
82
  };
83
+ }
84
+ function backgroundHandle(background) {
85
+ const currentBackground = [];
86
+ const backgroundInput = [];
87
+ background.forEach(b_scenario => {
88
+ var {
89
+ refactoredStep,
90
+ currentArgument
91
+ } = extactStepArgs(b_scenario.stepDescription);
92
+ var input = inputsParamterMap.get(`'${refactoredStep}'`);
93
+ backgroundInput.push(input);
94
+ currentBackground.push((0, _stepsnippets.testStep)(b_scenario.keyword, refactoredStep, input, currentArgument.join(',')));
95
+ return;
96
+ });
97
+ return (0, _stepsnippets.testBackGround)(currentBackground, browserObjectHandle(backgroundInput));
78
98
  }
@@ -20,7 +20,7 @@ function avoidDuplicate(arrayOfInputs) {
20
20
  }
21
21
  function filePathPattern(filePath, isWindows = true) {
22
22
  if (isWindows) {
23
- return filePath.replace('\\', '/');
23
+ return filePath.split('\\').join('/');
24
24
  }
25
25
  return filePath;
26
26
  }
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _default = exports.default = {
8
8
  addTags: [async ({
9
- $tags
9
+ $tags = []
10
10
  }, use, testInfo) => {
11
11
  testInfo.annotations.push({
12
12
  type: 'tags',
@@ -110,8 +110,8 @@ function main() {
110
110
  let promises = [];
111
111
  if (bddMode) {
112
112
  (0, _bddPoc.createCucumberBDD)();
113
- if (userArgsObject['edition'] || userArgsObject['tags']) {
114
- if (userArgsObject['edition']) {
113
+ if (userArgsObject !== null && userArgsObject !== void 0 && userArgsObject.edition || userArgsObject !== null && userArgsObject !== void 0 && userArgsObject.tags) {
114
+ if (userArgsObject !== null && userArgsObject !== void 0 && userArgsObject.edition) {
115
115
  playwrightArgs.push('--grep-invert');
116
116
  } else {
117
117
  playwrightArgs.push('--grep');
@@ -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-v4",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.1.8-exp-bdd-v8",
3
+ "version": "0.1.8-exp-bdd-v10",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {