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