@zohodesk/testinglibrary 0.0.5-exp.9 → 0.0.5-n20-experimental

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.
Files changed (158) hide show
  1. package/.babelrc +9 -1
  2. package/.eslintrc.js +31 -0
  3. package/.gitlab-ci.yml +191 -0
  4. package/.prettierrc +6 -0
  5. package/README.md +151 -1
  6. package/build/common/data-generator/steps/DataGenerator.spec.js +19 -0
  7. package/build/common/data-generator/steps/DataGeneratorStepsHelper.js +19 -0
  8. package/build/common/multi-actor/steps/multiActorHandling.spec.js +26 -0
  9. package/build/common/searchFake/helpers/rpcRequestHelper.js +41 -0
  10. package/build/common/searchFake/steps/searchFake.spec.js +26 -0
  11. package/build/core/dataGenerator/DataGenerator.js +108 -0
  12. package/build/core/dataGenerator/DataGeneratorError.js +50 -0
  13. package/build/core/dataGenerator/DataGeneratorHelper.js +49 -0
  14. package/build/core/jest/preprocessor/jsPreprocessor.js +3 -9
  15. package/build/core/jest/runner/jest-runner.js +1 -0
  16. package/build/core/jest/setup/index.js +1 -7
  17. package/build/core/playwright/builtInFixtures/actorContext.js +75 -0
  18. package/build/core/playwright/builtInFixtures/addTags.js +19 -0
  19. package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
  20. package/build/core/playwright/builtInFixtures/context.js +32 -0
  21. package/build/core/playwright/builtInFixtures/executionContext.js +17 -0
  22. package/build/core/playwright/builtInFixtures/i18N.js +41 -0
  23. package/build/core/playwright/builtInFixtures/index.js +46 -0
  24. package/build/core/playwright/builtInFixtures/page.js +38 -0
  25. package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
  26. package/build/core/playwright/clear-caches.js +49 -0
  27. package/build/core/playwright/codegen.js +5 -6
  28. package/build/core/playwright/configuration/Configuration.js +25 -0
  29. package/build/core/playwright/configuration/ConfigurationHelper.js +43 -0
  30. package/build/core/playwright/configuration/UserArgs.js +12 -0
  31. package/build/core/playwright/constants/browserTypes.js +12 -0
  32. package/build/core/playwright/constants/fileMutexConfig.js +9 -0
  33. package/build/core/playwright/custom-commands.js +1 -2
  34. package/build/core/playwright/env-initializer.js +28 -6
  35. package/build/core/playwright/fixtures.js +24 -0
  36. package/build/core/playwright/helpers/additionalProfiles.js +25 -0
  37. package/build/core/playwright/helpers/auth/accountLogin.js +21 -0
  38. package/build/core/playwright/helpers/auth/checkAuthCookies.js +41 -0
  39. package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
  40. package/build/core/playwright/helpers/auth/getUsers.js +118 -0
  41. package/build/core/playwright/helpers/auth/index.js +76 -0
  42. package/build/core/playwright/helpers/auth/loginDefaultStepsHelper.js +54 -0
  43. package/build/core/playwright/helpers/auth/loginSteps.js +50 -0
  44. package/build/core/playwright/helpers/checkAuthDirectory.js +27 -0
  45. package/build/core/playwright/helpers/configFileNameProvider.js +31 -0
  46. package/build/core/playwright/helpers/customFixturesHelper.js +58 -0
  47. package/build/core/playwright/helpers/fileMutex.js +71 -0
  48. package/build/core/playwright/helpers/getUserFixtures.js +23 -0
  49. package/build/core/playwright/helpers/mergeObjects.js +13 -0
  50. package/build/core/playwright/helpers/parseUserArgs.js +10 -0
  51. package/build/core/playwright/index.js +10 -89
  52. package/build/core/playwright/readConfigFile.js +97 -14
  53. package/build/core/playwright/report-generator.js +9 -10
  54. package/build/core/playwright/runner/Runner.js +22 -0
  55. package/build/core/playwright/runner/RunnerHelper.js +43 -0
  56. package/build/core/playwright/runner/RunnerTypes.js +17 -0
  57. package/build/core/playwright/runner/SpawnRunner.js +113 -0
  58. package/build/core/playwright/setup/config-creator.js +101 -90
  59. package/build/core/playwright/setup/config-utils.js +188 -0
  60. package/build/core/playwright/setup/custom-reporter.js +136 -0
  61. package/build/core/playwright/setup/qc-custom-reporter.js +291 -0
  62. package/build/core/playwright/tagProcessor.js +69 -0
  63. package/build/core/playwright/test-runner.js +84 -67
  64. package/build/core/playwright/types.js +44 -0
  65. package/build/core/playwright/validateFeature.js +28 -0
  66. package/build/decorators.d.ts +1 -0
  67. package/build/decorators.js +16 -0
  68. package/build/index.d.ts +78 -0
  69. package/build/index.js +73 -5
  70. package/build/lib/cli.js +38 -5
  71. package/build/lib/post-install.js +19 -11
  72. package/build/lint/index.js +3 -6
  73. package/build/parser/parser.js +205 -0
  74. package/build/parser/sample.feature +34 -0
  75. package/build/parser/sample.spec.js +37 -0
  76. package/build/parser/verifier.js +130 -0
  77. package/build/setup-folder-structure/helper.js +37 -0
  78. package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
  79. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
  80. package/build/setup-folder-structure/samples/accountLogin-sample.js +19 -0
  81. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  82. package/build/setup-folder-structure/samples/auth-setup-sample.js +15 -0
  83. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  84. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  85. package/build/setup-folder-structure/samples/git-ignore.sample.js +37 -0
  86. package/build/setup-folder-structure/samples/settings.json +7 -0
  87. package/build/setup-folder-structure/samples/testSetup-sample.js +14 -0
  88. package/build/setup-folder-structure/samples/uat-config-sample.js +46 -0
  89. package/build/setup-folder-structure/setupProject.js +36 -18
  90. package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
  91. package/build/test/core/playwright/__tests__/validateFeature.test.js +69 -0
  92. package/build/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js +27 -0
  93. package/build/test/core/playwright/configuration/__tests__/Configuration.test.js +53 -0
  94. package/build/test/core/playwright/helpers/__tests__/additionalProfiles.test.js +45 -0
  95. package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +34 -0
  96. package/build/test/core/playwright/helpers/__tests__/customFixturesHelper.test.js +51 -0
  97. package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +79 -0
  98. package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +80 -0
  99. package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +16 -0
  100. package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +27 -0
  101. package/build/utils/cliArgsToObject.js +9 -1
  102. package/build/utils/commonUtils.js +17 -0
  103. package/build/utils/fileUtils.js +109 -0
  104. package/build/utils/logger.js +7 -35
  105. package/build/utils/rootPath.js +16 -9
  106. package/build/utils/stepDefinitionsFormatter.js +11 -0
  107. package/changelog.md +136 -10
  108. package/jest.config.js +29 -11
  109. package/npm-shrinkwrap.json +10241 -6175
  110. package/package.json +40 -26
  111. package/playwright.config.js +5 -55
  112. package/test-results/.last-run.json +4 -0
  113. package/unit_reports/unit-report.html +277 -0
  114. package/build/bdd-framework/cli/commands/env.js +0 -44
  115. package/build/bdd-framework/cli/commands/export.js +0 -47
  116. package/build/bdd-framework/cli/commands/test.js +0 -60
  117. package/build/bdd-framework/cli/index.js +0 -11
  118. package/build/bdd-framework/cli/options.js +0 -21
  119. package/build/bdd-framework/cli/worker.js +0 -13
  120. package/build/bdd-framework/config/dir.js +0 -27
  121. package/build/bdd-framework/config/env.js +0 -49
  122. package/build/bdd-framework/config/index.js +0 -92
  123. package/build/bdd-framework/cucumber/buildStepDefinition.js +0 -45
  124. package/build/bdd-framework/cucumber/gherkin.d.ts +0 -45
  125. package/build/bdd-framework/cucumber/loadConfig.js +0 -17
  126. package/build/bdd-framework/cucumber/loadFeatures.js +0 -39
  127. package/build/bdd-framework/cucumber/loadSnippetBuilder.js +0 -20
  128. package/build/bdd-framework/cucumber/loadSources.js +0 -58
  129. package/build/bdd-framework/cucumber/loadSteps.js +0 -41
  130. package/build/bdd-framework/decorators.js +0 -21
  131. package/build/bdd-framework/gen/formatter.js +0 -92
  132. package/build/bdd-framework/gen/i18n.js +0 -44
  133. package/build/bdd-framework/gen/index.js +0 -150
  134. package/build/bdd-framework/gen/poms.js +0 -47
  135. package/build/bdd-framework/gen/testFile.js +0 -356
  136. package/build/bdd-framework/gen/testNode.js +0 -50
  137. package/build/bdd-framework/index.js +0 -33
  138. package/build/bdd-framework/playwright/fixtureParameterNames.js +0 -103
  139. package/build/bdd-framework/playwright/getLocationInFile.js +0 -50
  140. package/build/bdd-framework/playwright/loadConfig.js +0 -42
  141. package/build/bdd-framework/playwright/testTypeImpl.js +0 -47
  142. package/build/bdd-framework/playwright/transform.js +0 -85
  143. package/build/bdd-framework/playwright/utils.js +0 -24
  144. package/build/bdd-framework/run/bddFixtures.js +0 -109
  145. package/build/bdd-framework/run/bddWorld.js +0 -91
  146. package/build/bdd-framework/snippets/index.js +0 -132
  147. package/build/bdd-framework/snippets/snippetSyntax.js +0 -50
  148. package/build/bdd-framework/snippets/snippetSyntaxDecorators.js +0 -32
  149. package/build/bdd-framework/snippets/snippetSyntaxTs.js +0 -18
  150. package/build/bdd-framework/stepDefinitions/createBdd.js +0 -52
  151. package/build/bdd-framework/stepDefinitions/createDecorators.js +0 -110
  152. package/build/bdd-framework/stepDefinitions/defineStep.js +0 -62
  153. package/build/bdd-framework/utils/index.js +0 -52
  154. package/build/bdd-framework/utils/jsStringWrap.js +0 -44
  155. package/build/bdd-framework/utils/logger.js +0 -21
  156. package/build/setup-folder-structure/env-config-sample.json +0 -17
  157. package/build/setup-folder-structure/uat-config-sample.js +0 -31
  158. package/build/setup-folder-structure/user-example.json +0 -3
@@ -1,150 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.TestFilesGenerator = void 0;
8
- var _promises = _interopRequireDefault(require("fs/promises"));
9
- var _path = _interopRequireDefault(require("path"));
10
- var _fastGlob = _interopRequireDefault(require("fast-glob"));
11
- var _testFile = require("./testFile");
12
- var _loadConfig = require("../cucumber/loadConfig");
13
- var _loadFeatures = require("../cucumber/loadFeatures");
14
- var _loadSteps = require("../cucumber/loadSteps");
15
- var _config = require("../config");
16
- var _utils = require("../utils");
17
- var _snippets = require("../snippets");
18
- var _createDecorators = require("../stepDefinitions/createDecorators");
19
- var _transform = require("../playwright/transform");
20
- var _dir = require("../config/dir");
21
- var _logger = require("../utils/logger");
22
- var _tagExpressions = _interopRequireDefault(require("@cucumber/tag-expressions"));
23
- /**
24
- * Generate playwright test files from Gherkin documents.
25
- */
26
-
27
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
28
-
29
- class TestFilesGenerator {
30
- // all these props are exist
31
- runConfiguration;
32
- features;
33
- supportCodeLibrary;
34
- files = [];
35
- tagsExpression;
36
- constructor(config) {
37
- this.config = config;
38
- if (config.tags) this.tagsExpression = (0, _tagExpressions.default)(config.tags);
39
- }
40
- async generate() {
41
- await this.loadCucumberConfig();
42
- await Promise.all([this.loadFeatures(), this.loadSteps()]);
43
- this.buildFiles();
44
- await this.checkUndefinedSteps();
45
- this.checkImportCustomTest();
46
- await this.clearOutputDir();
47
- await this.saveFiles();
48
- }
49
- async extractSteps() {
50
- await this.loadCucumberConfig();
51
- await this.loadSteps();
52
- return this.supportCodeLibrary.stepDefinitions;
53
- }
54
- async loadCucumberConfig() {
55
- const environment = {
56
- cwd: (0, _dir.getPlaywrightConfigDir)()
57
- };
58
- const {
59
- runConfiguration
60
- } = await (0, _loadConfig.loadConfig)({
61
- provided: (0, _config.extractCucumberConfig)(this.config)
62
- }, environment);
63
- this.runConfiguration = runConfiguration;
64
- this.warnForTsNodeRegister();
65
- }
66
- async loadFeatures() {
67
- const environment = {
68
- cwd: (0, _dir.getPlaywrightConfigDir)()
69
- };
70
- this.features = await (0, _loadFeatures.loadFeatures)(this.runConfiguration, environment);
71
- }
72
- async loadSteps() {
73
- const environment = {
74
- cwd: (0, _dir.getPlaywrightConfigDir)()
75
- };
76
- this.supportCodeLibrary = await (0, _loadSteps.loadSteps)(this.runConfiguration, environment);
77
- await this.loadDecoratorSteps();
78
- }
79
- async loadDecoratorSteps() {
80
- const {
81
- importTestFrom
82
- } = this.config;
83
- if (importTestFrom) {
84
- // require importTestFrom for case when it is not required by step definitions
85
- // possible re-require but it's not a problem as it is cached by Node.js
86
- await (0, _transform.requireTransform)().requireOrImport(importTestFrom.file);
87
- (0, _createDecorators.appendDecoratorSteps)(this.supportCodeLibrary);
88
- }
89
- }
90
- buildFiles() {
91
- this.files = [...this.features.entries()].map(([doc, pickles]) => {
92
- return new _testFile.TestFile({
93
- doc,
94
- pickles,
95
- supportCodeLibrary: this.supportCodeLibrary,
96
- outputPath: this.getOutputPath(doc),
97
- config: this.config,
98
- tagsExpression: this.tagsExpression
99
- }).build();
100
- }).filter(file => file.testNodes.length > 0);
101
- }
102
- getOutputPath(doc) {
103
- const configDir = (0, _dir.getPlaywrightConfigDir)();
104
- // doc.uri is always relative to cwd (coming after cucumber handling)
105
- // see: https://github.com/cucumber/cucumber-js/blob/main/src/api/gherkin.ts#L51
106
- // Check here if anything is not working
107
- const relFeaturePath = doc.uri !== null ? doc.uri : null;
108
- const absFeaturePath = _path.default.resolve(configDir, relFeaturePath);
109
- const relOutputPath = _path.default.relative(this.config.featuresRoot, absFeaturePath);
110
- if (relOutputPath.startsWith('..')) {
111
- (0, _utils.exitWithMessage)(`All feature files should be located underneath featuresRoot.`, `Please change featuresRoot or paths in configuration.\n`, `featureFile: ${absFeaturePath}\n`, `featuresRoot: ${this.config.featuresRoot}\n`);
112
- }
113
- const absOutputPath = _path.default.resolve(this.config.outputDir, relOutputPath);
114
- return `${absOutputPath}.spec.js`;
115
- }
116
- async checkUndefinedSteps() {
117
- const undefinedSteps = this.files.reduce((sum, file) => sum + file.undefinedSteps.length, 0);
118
- if (undefinedSteps > 0) {
119
- const snippets = new _snippets.Snippets(this.files, this.runConfiguration, this.supportCodeLibrary);
120
- await snippets.printSnippetsAndExit();
121
- }
122
- }
123
- checkImportCustomTest() {
124
- if (this.config.importTestFrom) return;
125
- const hasCustomTest = this.files.some(file => file.hasCustomTest);
126
- if (hasCustomTest) {
127
- (0, _utils.exitWithMessage)(`When using custom "test" function in createBdd() you should`, `set "importTestFrom" config option that points to file exporting custom test.`);
128
- }
129
- }
130
- async saveFiles() {
131
- this.files.forEach(file => {
132
- file.save();
133
- if (this.config.verbose) {
134
- _logger.logger.log(`Generated: ${_path.default.relative(process.cwd(), file.outputPath)}`);
135
- }
136
- });
137
- if (this.config.verbose) _logger.logger.log(`Generated files: ${this.files.length}`);
138
- }
139
- async clearOutputDir() {
140
- const testFiles = await (0, _fastGlob.default)(_path.default.join(this.config.outputDir, '**', '*.spec.js'));
141
- const tasks = testFiles.map(testFile => _promises.default.rm(testFile));
142
- await Promise.all(tasks);
143
- }
144
- warnForTsNodeRegister() {
145
- if ((0, _loadSteps.hasTsNodeRegister)(this.runConfiguration)) {
146
- _logger.logger.log(`WARNING: usage of requireModule: ['ts-node/register'] is not recommended for playwright-bdd.`, `Remove this option from defineBddConfig() and`, `Playwright's built-in loader will be used to compile TypeScript step definitions.`);
147
- }
148
- }
149
- }
150
- exports.TestFilesGenerator = TestFilesGenerator;
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.POMS = void 0;
7
- exports.buildFixtureTag = buildFixtureTag;
8
- var _createDecorators = require("../stepDefinitions/createDecorators");
9
- var _defineStep = require("../stepDefinitions/defineStep");
10
- /**
11
- * Handle POMs graph for decorator steps.
12
- */
13
-
14
- const FIXTURE_TAG_PREFIX = '@fixture:';
15
- class POMS {
16
- usedPoms = new Map();
17
- add(pomNode) {
18
- if (pomNode) this.usedPoms.set(pomNode, null);
19
- }
20
- addByFixtureName(fixtureName) {
21
- const pomNode = (0, _createDecorators.getPomNodeByFixtureName)(fixtureName);
22
- if (pomNode) this.add(pomNode);
23
- }
24
- addByTag(tag) {
25
- const fixtureName = extractFixtureName(tag);
26
- if (fixtureName) this.addByFixtureName(fixtureName);
27
- }
28
- resolveFixtureNames(pomNode) {
29
- const resolvedFixtureNames = this.usedPoms.get(pomNode);
30
- if (resolvedFixtureNames) return resolvedFixtureNames;
31
- const fixtureNames = [...pomNode.children].map(child => this.resolveFixtureNames(child)).flat();
32
- if (this.usedPoms.has(pomNode)) {
33
- // if nothing returned from children, use own fixtureName,
34
- // otherwise use what returned from child
35
- if (!fixtureNames.length) fixtureNames.push(pomNode.fixtureName);
36
- this.usedPoms.set(pomNode, fixtureNames);
37
- }
38
- return fixtureNames;
39
- }
40
- }
41
- exports.POMS = POMS;
42
- function extractFixtureName(tag) {
43
- return tag.startsWith(FIXTURE_TAG_PREFIX) ? tag.replace(FIXTURE_TAG_PREFIX, '') : '';
44
- }
45
- function buildFixtureTag(fixtureName) {
46
- return `${FIXTURE_TAG_PREFIX}${fixtureName}`;
47
- }
@@ -1,356 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.TestFile = void 0;
8
- var _fs = _interopRequireDefault(require("fs"));
9
- var _path = _interopRequireDefault(require("path"));
10
- var _formatter = require("./formatter");
11
- var _i18n = require("./i18n");
12
- var _loadSteps = require("../cucumber/loadSteps");
13
- var _createBdd = require("../stepDefinitions/createBdd");
14
- var _index = require("@cucumber/cucumber/lib/formatter/helpers/index");
15
- var _utils = require("../utils");
16
- var _defineStep = require("../stepDefinitions/defineStep");
17
- var _poms = require("./poms");
18
- var _testNode = require("./testNode");
19
- /**
20
- * Generate test code.
21
- */
22
-
23
- /* eslint-disable max-lines, max-params */
24
-
25
- class TestFile {
26
- lines = [];
27
- i18nKeywordsMap;
28
- formatter;
29
- testNodes = [];
30
- hasCustomTest = false;
31
- undefinedSteps = [];
32
- constructor(options) {
33
- this.options = options;
34
- this.formatter = new _formatter.Formatter(options.config);
35
- }
36
- get sourceFile() {
37
- const {
38
- uri
39
- } = this.options.doc;
40
- if (!uri) throw new Error(`Document without uri`);
41
- return uri;
42
- }
43
- get content() {
44
- return this.lines.join('\n');
45
- }
46
- get language() {
47
- var _this$options$doc$fea;
48
- return ((_this$options$doc$fea = this.options.doc.feature) === null || _this$options$doc$fea === void 0 ? void 0 : _this$options$doc$fea.language) || 'en';
49
- }
50
- get config() {
51
- return this.options.config;
52
- }
53
- get outputPath() {
54
- return this.options.outputPath;
55
- }
56
- build() {
57
- this.loadI18nKeywords();
58
- this.lines = [...this.getFileHeader(),
59
- // prettier-ignore
60
- ...this.getRootSuite(), ...this.getFileFixtures()];
61
- return this;
62
- }
63
- save() {
64
- const dir = _path.default.dirname(this.outputPath);
65
- if (!_fs.default.existsSync(dir)) _fs.default.mkdirSync(dir, {
66
- recursive: true
67
- });
68
- _fs.default.writeFileSync(this.outputPath, this.content);
69
- }
70
- getFileHeader() {
71
- const importTestFrom = this.getRelativeImportTestFrom();
72
- return this.formatter.fileHeader(this.sourceFile, importTestFrom);
73
- }
74
- loadI18nKeywords() {
75
- if (this.language !== 'en') {
76
- this.i18nKeywordsMap = (0, _i18n.getKeywordsMap)(this.language);
77
- }
78
- }
79
- getRelativeImportTestFrom() {
80
- const {
81
- importTestFrom
82
- } = this.config;
83
- if (!importTestFrom) return;
84
- const {
85
- file,
86
- varName
87
- } = importTestFrom;
88
- const dir = _path.default.dirname(this.outputPath);
89
- return {
90
- file: _path.default.relative(dir, file),
91
- varName
92
- };
93
- }
94
- getFileFixtures() {
95
- return this.formatter.useFixtures([...this.formatter.testFixture(), ...this.formatter.tagsFixture(this.testNodes)]);
96
- }
97
- getRootSuite() {
98
- const {
99
- feature
100
- } = this.options.doc;
101
- if (!feature) throw new Error(`Document without feature.`);
102
- return this.getSuite(feature);
103
- }
104
-
105
- /**
106
- * Generate test.describe suite for root Feature or Rule
107
- */
108
- getSuite(feature, parent) {
109
- const node = new _testNode.TestNode(feature, parent);
110
- const lines = [];
111
- feature.children.forEach(child => lines.push(...this.getSuiteChild(child, node)));
112
- return this.formatter.suite(node, lines);
113
- }
114
- getSuiteChild(child, parent) {
115
- if ('rule' in child && child.rule) return this.getSuite(child.rule, parent);
116
- if (child.background) return this.getBeforeEach(child.background);
117
- if (child.scenario) return this.getScenarioLines(child.scenario, parent);
118
- throw new Error(`Empty child: ${JSON.stringify(child)}`);
119
- }
120
- getScenarioLines(scenario, parent) {
121
- return isOutline(scenario) ? this.getOutlineSuite(scenario, parent) : this.getTest(scenario, parent);
122
- }
123
-
124
- /**
125
- * Generate test.beforeEach for Background
126
- */
127
- getBeforeEach(bg) {
128
- const {
129
- fixtures,
130
- lines
131
- } = this.getSteps(bg);
132
- return this.formatter.beforeEach(fixtures, lines);
133
- }
134
-
135
- /**
136
- * Generate test.describe suite for Scenario Outline
137
- */
138
- getOutlineSuite(scenario, parent) {
139
- const node = new _testNode.TestNode(scenario, parent);
140
- const lines = [];
141
- let exampleIndex = 0;
142
- scenario.examples.forEach(examples => {
143
- const titleFormat = this.getExamplesTitleFormat(examples);
144
- examples.tableBody.forEach(exampleRow => {
145
- const testTitle = this.getOutlineTestTitle(titleFormat, examples, exampleRow, ++exampleIndex);
146
- const testLines = this.getOutlineTest(scenario, examples, exampleRow, testTitle, node);
147
- lines.push(...testLines);
148
- });
149
- });
150
- return this.formatter.suite(node, lines);
151
- }
152
-
153
- /**
154
- * Generate test from Examples row of Scenario Outline
155
- */
156
- // eslint-disable-next-line max-params
157
- getOutlineTest(scenario, examples, exampleRow, title, parent) {
158
- const node = new _testNode.TestNode({
159
- name: title,
160
- tags: examples.tags
161
- }, parent);
162
- if (this.skipByTagsExpression(node)) return [];
163
- this.testNodes.push(node);
164
- const {
165
- fixtures,
166
- lines
167
- } = this.getSteps(scenario, node.ownTags, exampleRow.id);
168
- return this.formatter.test(node, fixtures, lines);
169
- }
170
-
171
- /**
172
- * Generate test from Scenario
173
- */
174
- getTest(scenario, parent) {
175
- const node = new _testNode.TestNode(scenario, parent);
176
- if (this.skipByTagsExpression(node)) return [];
177
- this.testNodes.push(node);
178
- const {
179
- fixtures,
180
- lines
181
- } = this.getSteps(scenario, node.ownTags);
182
- return this.formatter.test(node, fixtures, lines);
183
- }
184
-
185
- /**
186
- * Generate test steps
187
- */
188
- getSteps(scenario, ownTestTags, outlineExampleRowId) {
189
- const testFixtureNames = new Set();
190
- const usedPoms = new _poms.POMS();
191
- const decoratorSteps = [];
192
- let previousKeywordType = undefined;
193
- const lines = scenario.steps.map((step, index) => {
194
- const {
195
- keyword,
196
- keywordType,
197
- fixtureNames: stepFixtureNames,
198
- line,
199
- pickleStep,
200
- stepConfig
201
- } = this.getStep(step, previousKeywordType, outlineExampleRowId);
202
- previousKeywordType = keywordType;
203
- testFixtureNames.add(keyword);
204
- stepFixtureNames.forEach(fixtureName => testFixtureNames.add(fixtureName));
205
- if (!line && stepConfig !== null && stepConfig !== void 0 && stepConfig.pomNode) {
206
- usedPoms.add(stepConfig.pomNode);
207
- decoratorSteps.push({
208
- index,
209
- keyword,
210
- pickleStep,
211
- pomNode: stepConfig.pomNode
212
- });
213
- }
214
- return line;
215
- });
216
- if (decoratorSteps.length) {
217
- testFixtureNames.forEach(fixtureName => usedPoms.addByFixtureName(fixtureName));
218
- ownTestTags === null || ownTestTags === void 0 || ownTestTags.forEach(tag => usedPoms.addByTag(tag));
219
- decoratorSteps.forEach(step => {
220
- const {
221
- line,
222
- fixtureNames
223
- } = this.getDecoratorStep(step, usedPoms);
224
- lines[step.index] = line;
225
- fixtureNames.forEach(fixtureName => testFixtureNames.add(fixtureName));
226
- });
227
- }
228
- return {
229
- fixtures: testFixtureNames,
230
- lines
231
- };
232
- }
233
-
234
- /**
235
- * Generate step for Given, When, Then
236
- */
237
- // eslint-disable-next-line max-statements, complexity
238
- getStep(step, previousKeywordType, outlineExampleRowId) {
239
- const pickleStep = this.getPickleStep(step, outlineExampleRowId);
240
- const stepDefinition = (0, _loadSteps.findStepDefinition)(this.options.supportCodeLibrary, pickleStep.text, this.sourceFile);
241
- const keywordType = (0, _index.getStepKeywordType)({
242
- keyword: step.keyword,
243
- language: this.language,
244
- previousKeywordType
245
- });
246
- let keyword = this.getStepKeyword(step);
247
- if (!stepDefinition) {
248
- this.undefinedSteps.push({
249
- keywordType,
250
- step,
251
- pickleStep
252
- });
253
- return this.getMissingStep(keyword, keywordType, pickleStep);
254
- }
255
- // for cucumber-style stepConfig is undefined
256
- const stepConfig = (0, _defineStep.getStepConfig)(stepDefinition);
257
- if (stepConfig !== null && stepConfig !== void 0 && stepConfig.hasCustomTest) this.hasCustomTest = true;
258
- // for cucumber-style transform Given/When/Then -> Given_/When_/Then_
259
- // to use fixtures with own bddWorld (containing fixtures)
260
- if (!(0, _defineStep.isPlaywrightStyle)(stepDefinition)) keyword = `${keyword}_`;
261
- // for decorator steps fixtures defined later in second pass
262
- const fixtureNames = stepConfig !== null && stepConfig !== void 0 && stepConfig.isDecorator ? [] : (0, _createBdd.extractFixtureNames)(stepConfig === null || stepConfig === void 0 ? void 0 : stepConfig.fn);
263
- const line = stepConfig !== null && stepConfig !== void 0 && stepConfig.isDecorator ? '' : this.formatter.step(keyword, pickleStep.text, pickleStep.argument, fixtureNames);
264
- return {
265
- keyword,
266
- keywordType,
267
- fixtureNames,
268
- line,
269
- pickleStep,
270
- stepConfig
271
- };
272
- }
273
- getMissingStep(keyword, keywordType, pickleStep) {
274
- return {
275
- keyword,
276
- keywordType,
277
- fixtureNames: [],
278
- line: this.formatter.missingStep(keyword, pickleStep.text),
279
- pickleStep,
280
- stepConfig: undefined
281
- };
282
- }
283
- getPickleStep(step, outlineExampleRowId) {
284
- for (const pickle of this.options.pickles) {
285
- const pickleStep = pickle.steps.find(({
286
- astNodeIds
287
- }) => {
288
- const hasStepId = astNodeIds.includes(step.id);
289
- const hasRowId = !outlineExampleRowId || astNodeIds.includes(outlineExampleRowId);
290
- return hasStepId && hasRowId;
291
- });
292
- if (pickleStep) return pickleStep;
293
- }
294
- throw new Error(`Pickle step not found for step: ${step.text}`);
295
- }
296
- getStepKeyword(step) {
297
- const origKeyword = step.keyword.trim();
298
- let enKeyword;
299
- if (origKeyword === '*') {
300
- enKeyword = 'And';
301
- } else {
302
- enKeyword = this.i18nKeywordsMap ? this.i18nKeywordsMap.get(origKeyword) : origKeyword;
303
- }
304
- if (!enKeyword) throw new Error(`Keyword not found: ${origKeyword}`);
305
- return enKeyword;
306
- }
307
- getDecoratorStep(step, usedPoms) {
308
- const {
309
- keyword,
310
- pickleStep,
311
- pomNode
312
- } = step;
313
- const fixtureNames = usedPoms.resolveFixtureNames(pomNode);
314
- if (fixtureNames.length !== 1) {
315
- const suggestedTags = fixtureNames.map(name => (0, _poms.buildFixtureTag)(name)).join(', ');
316
- (0, _utils.exitWithMessage)(`Can't guess fixture for decorator step "${pickleStep.text}" in file: ${this.sourceFile}.`, `Please set one of the following tags (${suggestedTags}) or refactor your Page Object classes.`);
317
- }
318
- return {
319
- fixtureNames,
320
- line: this.formatter.step(keyword, pickleStep.text, pickleStep.argument, [fixtureNames[0]])
321
- };
322
- }
323
- getOutlineTestTitle(titleFormat, examples, exampleRow, exampleIndex) {
324
- const params = {
325
- _index_: exampleIndex
326
- };
327
- exampleRow.cells.forEach((cell, index) => {
328
- var _examples$tableHeader;
329
- const colName = (_examples$tableHeader = examples.tableHeader) === null || _examples$tableHeader === void 0 || (_examples$tableHeader = _examples$tableHeader.cells[index]) === null || _examples$tableHeader === void 0 ? void 0 : _examples$tableHeader.value;
330
- if (colName) params[colName] = cell.value;
331
- });
332
- return (0, _utils.template)(titleFormat, params);
333
- }
334
- getExamplesTitleFormat(examples) {
335
- var _comment$text;
336
- const {
337
- line
338
- } = examples.location;
339
- const titleFormatCommentLine = line - 1;
340
- const comment = this.options.doc.comments.find(c => {
341
- return c.location.line === titleFormatCommentLine;
342
- });
343
- const commentText = comment === null || comment === void 0 || (_comment$text = comment.text) === null || _comment$text === void 0 ? void 0 : _comment$text.trim();
344
- const prefix = '# title-format:';
345
- return commentText !== null && commentText !== void 0 && commentText.startsWith(prefix) ? commentText.replace(prefix, '').trim() : this.config.examplesTitleFormat;
346
- }
347
- skipByTagsExpression(node) {
348
- var _this$options$tagsExp;
349
- // see: https://github.com/cucumber/tag-expressions/tree/main/javascript
350
- return ((_this$options$tagsExp = this.options.tagsExpression) === null || _this$options$tagsExp === void 0 ? void 0 : _this$options$tagsExp.evaluate(node.tags)) === false;
351
- }
352
- }
353
- exports.TestFile = TestFile;
354
- function isOutline(scenario) {
355
- return scenario.keyword === 'Scenario Outline' || scenario.keyword === 'Scenario Template';
356
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.TestNode = void 0;
7
- var _utils = require("../utils");
8
- /**
9
- * Universal TestNode class with accumulated data (tags, titiles)
10
- * of parent-child relations in test file structure.
11
- */
12
-
13
- const SPECIAL_TAGS = ['@only', '@skip', '@fixme'];
14
- class TestNode {
15
- title;
16
- titlePath;
17
- ownTags = [];
18
- tags = [];
19
- flags = {};
20
- constructor(origItem, parent) {
21
- this.origItem = origItem;
22
- this.parent = parent;
23
- this.initOwnTags(origItem);
24
- this.tags = (0, _utils.removeDuplicates)(((parent === null || parent === void 0 ? void 0 : parent.tags) || []).concat(this.ownTags));
25
- this.title = origItem.name;
26
- this.titlePath = ((parent === null || parent === void 0 ? void 0 : parent.titlePath) || []).concat([this.title]);
27
- }
28
- initOwnTags(origItem) {
29
- const tagNames = (0, _utils.removeDuplicates)(getTagNames(origItem.tags));
30
- tagNames.forEach(tag => {
31
- if (isSpecialTag(tag)) {
32
- this.setFlag(tag);
33
- } else {
34
- this.ownTags.push(tag);
35
- }
36
- });
37
- }
38
- setFlag(tag) {
39
- if (tag === '@only') this.flags.only = true;
40
- if (tag === '@skip') this.flags.skip = true;
41
- if (tag === '@fixme') this.flags.fixme = true;
42
- }
43
- }
44
- exports.TestNode = TestNode;
45
- function getTagNames(tags) {
46
- return tags.map(tag => tag.name);
47
- }
48
- function isSpecialTag(tag) {
49
- return SPECIAL_TAGS.includes(tag);
50
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "BddWorld", {
7
- enumerable: true,
8
- get: function () {
9
- return _bddWorld.BddWorld;
10
- }
11
- });
12
- Object.defineProperty(exports, "createBdd", {
13
- enumerable: true,
14
- get: function () {
15
- return _createBdd.createBdd;
16
- }
17
- });
18
- Object.defineProperty(exports, "defineBddConfig", {
19
- enumerable: true,
20
- get: function () {
21
- return _config.defineBddConfig;
22
- }
23
- });
24
- Object.defineProperty(exports, "test", {
25
- enumerable: true,
26
- get: function () {
27
- return _bddFixtures.test;
28
- }
29
- });
30
- var _config = require("./config");
31
- var _createBdd = require("./stepDefinitions/createBdd");
32
- var _bddFixtures = require("./run/bddFixtures");
33
- var _bddWorld = require("./run/bddWorld");