@zohodesk/testinglibrary 0.0.1 → 0.0.2-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 (114) hide show
  1. package/.babelrc +23 -0
  2. package/.eslintrc.js +31 -0
  3. package/.gitlab-ci.yml +163 -0
  4. package/.prettierrc +6 -0
  5. package/README.md +98 -18
  6. package/bin/cli.js +2 -2
  7. package/bin/postinstall.js +1 -16
  8. package/{src → build}/core/jest/preprocessor/jsPreprocessor.js +7 -9
  9. package/{src → build}/core/jest/runner/jest-runner.js +46 -45
  10. package/build/core/jest/setup/index.js +3 -0
  11. package/build/core/playwright/builtInFixtures/addTags.js +19 -0
  12. package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
  13. package/build/core/playwright/builtInFixtures/context.js +32 -0
  14. package/build/core/playwright/builtInFixtures/executionContext.js +17 -0
  15. package/build/core/playwright/builtInFixtures/i18N.js +41 -0
  16. package/build/core/playwright/builtInFixtures/index.js +44 -0
  17. package/build/core/playwright/builtInFixtures/page.js +101 -0
  18. package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
  19. package/build/core/playwright/clear-caches.js +49 -0
  20. package/build/core/playwright/codegen.js +55 -0
  21. package/build/core/playwright/configuration/Configuration.js +25 -0
  22. package/build/core/playwright/configuration/ConfigurationHelper.js +43 -0
  23. package/build/core/playwright/configuration/UserArgs.js +12 -0
  24. package/build/core/playwright/constants/browserTypes.js +12 -0
  25. package/build/core/playwright/constants/fileMutexConfig.js +9 -0
  26. package/build/core/playwright/custom-commands.js +7 -0
  27. package/build/core/playwright/env-initializer.js +43 -0
  28. package/build/core/playwright/fixtures.js +24 -0
  29. package/build/core/playwright/helpers/additionalProfiles.js +18 -0
  30. package/build/core/playwright/helpers/auth/accountLogin.js +21 -0
  31. package/build/core/playwright/helpers/auth/checkAuthCookies.js +41 -0
  32. package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
  33. package/build/core/playwright/helpers/auth/getUsers.js +118 -0
  34. package/build/core/playwright/helpers/auth/index.js +76 -0
  35. package/build/core/playwright/helpers/auth/loginSteps.js +50 -0
  36. package/build/core/playwright/helpers/checkAuthDirectory.js +27 -0
  37. package/build/core/playwright/helpers/configFileNameProvider.js +31 -0
  38. package/build/core/playwright/helpers/fileMutex.js +71 -0
  39. package/build/core/playwright/helpers/getUserFixtures.js +23 -0
  40. package/build/core/playwright/helpers/mergeObjects.js +13 -0
  41. package/build/core/playwright/helpers/parseUserArgs.js +10 -0
  42. package/build/core/playwright/index.js +24 -0
  43. package/build/core/playwright/readConfigFile.js +147 -0
  44. package/build/core/playwright/report-generator.js +42 -0
  45. package/build/core/playwright/runner/Runner.js +22 -0
  46. package/build/core/playwright/runner/RunnerHelper.js +43 -0
  47. package/build/core/playwright/runner/RunnerTypes.js +17 -0
  48. package/build/core/playwright/runner/SpawnRunner.js +110 -0
  49. package/build/core/playwright/setup/config-creator.js +113 -0
  50. package/build/core/playwright/setup/config-utils.js +189 -0
  51. package/build/core/playwright/setup/custom-reporter.js +136 -0
  52. package/build/core/playwright/setup/qc-custom-reporter.js +291 -0
  53. package/build/core/playwright/tagProcessor.js +69 -0
  54. package/build/core/playwright/test-runner.js +116 -0
  55. package/build/core/playwright/types.js +44 -0
  56. package/build/core/playwright/validateFeature.js +28 -0
  57. package/build/decorators.d.ts +1 -0
  58. package/build/decorators.js +16 -0
  59. package/build/index.d.ts +78 -0
  60. package/build/index.js +105 -0
  61. package/build/lib/cli.js +78 -0
  62. package/build/lib/post-install.js +25 -0
  63. package/build/lint/index.js +4 -0
  64. package/build/parser/parser.js +205 -0
  65. package/build/parser/sample.feature +34 -0
  66. package/build/parser/sample.spec.js +37 -0
  67. package/build/parser/verifier.js +130 -0
  68. package/build/setup-folder-structure/helper.js +37 -0
  69. package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
  70. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
  71. package/build/setup-folder-structure/samples/accountLogin-sample.js +19 -0
  72. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  73. package/build/setup-folder-structure/samples/auth-setup-sample.js +15 -0
  74. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  75. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  76. package/build/setup-folder-structure/samples/git-ignore.sample.js +37 -0
  77. package/build/setup-folder-structure/samples/settings.json +7 -0
  78. package/build/setup-folder-structure/samples/testSetup-sample.js +14 -0
  79. package/build/setup-folder-structure/samples/uat-config-sample.js +46 -0
  80. package/build/setup-folder-structure/setupProject.js +122 -0
  81. package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
  82. package/build/test/core/playwright/__tests__/validateFeature.test.js +69 -0
  83. package/build/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js +27 -0
  84. package/build/test/core/playwright/configuration/__tests__/Configuration.test.js +53 -0
  85. package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +34 -0
  86. package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +79 -0
  87. package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +80 -0
  88. package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +16 -0
  89. package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +27 -0
  90. package/build/utils/cliArgsToObject.js +72 -0
  91. package/build/utils/fileUtils.js +89 -0
  92. package/build/utils/getFilePath.js +11 -0
  93. package/build/utils/logger.js +57 -0
  94. package/build/utils/rootPath.js +53 -0
  95. package/build/utils/stepDefinitionsFormatter.js +11 -0
  96. package/changelog.md +167 -0
  97. package/jest.config.js +81 -63
  98. package/npm-shrinkwrap.json +12575 -0
  99. package/package.json +60 -31
  100. package/playwright.config.js +62 -112
  101. package/src/core/jest/setup/index.js +0 -165
  102. package/src/core/playwright/codegen.js +0 -61
  103. package/src/core/playwright/custom-commands.js +0 -3
  104. package/src/core/playwright/env-initializer.js +0 -24
  105. package/src/core/playwright/index.js +0 -81
  106. package/src/core/playwright/readConfigFile.js +0 -18
  107. package/src/core/playwright/report-generator.js +0 -44
  108. package/src/core/playwright/test-runner.js +0 -64
  109. package/src/index.js +0 -9
  110. package/src/lib/cli.js +0 -35
  111. package/src/utils/cliArgsToObject.js +0 -35
  112. package/src/utils/getFilePath.js +0 -9
  113. package/src/utils/logger.js +0 -28
  114. package/src/utils/rootPath.js +0 -19
@@ -0,0 +1,291 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _codeFrame = require("@babel/code-frame");
11
+ class CustomJsonReporter {
12
+ constructor({
13
+ outputFile = 'test-results.json'
14
+ } = {}) {
15
+ this.outputFile = _path.default.resolve(process.cwd(), 'uat/test-results/', outputFile);
16
+ this.rootSuite = null;
17
+ this.report = {
18
+ config: {},
19
+ suites: []
20
+ };
21
+ this.testResultsById = new Map();
22
+ }
23
+ onBegin = (config, suite) => {
24
+ this.rootSuite = suite;
25
+ this.report.config = config;
26
+ };
27
+ onTestEnd(test, result) {
28
+ var _result$errors, _result$steps;
29
+ const key = `${test.location.file}:${test.location.line}:${test.title}`;
30
+ const testResult = {
31
+ status: result.status,
32
+ attachments: result.attachments,
33
+ startTime: result.startTime,
34
+ retry: result.retry,
35
+ stderr: result.stderr.map(err => stdioEntry(err)),
36
+ stdout: result.stdout.map(out => stdioEntry(out)),
37
+ workerIndex: result.workerIndex,
38
+ duration: result.duration,
39
+ error: result.error,
40
+ errors: (_result$errors = result.errors) === null || _result$errors === void 0 ? void 0 : _result$errors.map(processError),
41
+ steps: ((_result$steps = result.steps) === null || _result$steps === void 0 ? void 0 : _result$steps.map(step => extractMergedSteps(this.report.config.rootDir, step))) ?? []
42
+ };
43
+ const existingResults = this.testResultsById.get(key) ?? [];
44
+ this.testResultsById.set(key, [...existingResults, testResult]);
45
+ }
46
+ onEnd() {
47
+ var _this$rootSuite;
48
+ (_this$rootSuite = this.rootSuite) === null || _this$rootSuite === void 0 || (_this$rootSuite = _this$rootSuite.suites) === null || _this$rootSuite === void 0 || _this$rootSuite.map(suite => {
49
+ const extracted = suite.suites.map(suite => extractMergedSuite(this.report.config.rootDir, suite, this.testResultsById));
50
+ this.report.suites.push(...extracted);
51
+ });
52
+ const writableStream = _fs.default.createWriteStream(this.outputFile);
53
+ writableStream.write('{\n');
54
+ writableStream.write(` "config": ${JSON.stringify(this.report.config, null, 2)},\n`);
55
+ writableStream.write(' "suites": [\n');
56
+ for (let i = 0; i < this.report.suites.length; i++) {
57
+ const suite = this.report.suites[i];
58
+ let suiteStr = JSON.stringify(suite, null, 2).split('\n').map(line => ' ' + line).join('\n');
59
+ if (i < this.report.suites.length - 1) {
60
+ suiteStr += ',';
61
+ }
62
+ suiteStr += '\n';
63
+ writableStream.write(suiteStr);
64
+ }
65
+ writableStream.write(' ]\n');
66
+ writableStream.write('}\n');
67
+ writableStream.end();
68
+ console.log(`Custom JSON report written to: ${this.outputFile}`);
69
+ }
70
+ }
71
+ exports.default = CustomJsonReporter;
72
+ const extractMergedSuite = (rootDir, suite, testResultsById) => {
73
+ var _suite$suites;
74
+ const specMap = new Map();
75
+ for (const test of suite.tests ?? []) {
76
+ const existingSpec = specMap.get(test.title);
77
+ if (existingSpec) {
78
+ const newTestInfo = extractTestDetails(test, testResultsById);
79
+ existingSpec.tests.push(newTestInfo);
80
+ } else {
81
+ const newSpec = createSpecEntry(rootDir, test, testResultsById);
82
+ specMap.set(test.title, newSpec);
83
+ }
84
+ }
85
+ return {
86
+ title: suite.title,
87
+ ...parseLocation(rootDir, suite.location),
88
+ ...(suite.location && {
89
+ snippet: formSnippet(rootDir, suite.location)
90
+ }),
91
+ ...(((_suite$suites = suite.suites) === null || _suite$suites === void 0 ? void 0 : _suite$suites.length) > 0 && {
92
+ suites: suite.suites.map(child => extractMergedSuite(rootDir, child, testResultsById))
93
+ }),
94
+ ...(specMap.size > 0 && {
95
+ specs: Array.from(specMap.values())
96
+ })
97
+ };
98
+ };
99
+ const createSpecEntry = (rootDir, test, testResultsById) => ({
100
+ title: test.title,
101
+ ...parseLocation(rootDir, test.location),
102
+ ...(test.location && {
103
+ snippet: formSnippet(test.location)
104
+ }),
105
+ tests: [extractTestDetails(test, testResultsById)]
106
+ });
107
+ const extractTestDetails = (test, testResultsById) => {
108
+ var _test$location, _test$location2;
109
+ const key = `${(_test$location = test.location) === null || _test$location === void 0 ? void 0 : _test$location.file}:${(_test$location2 = test.location) === null || _test$location2 === void 0 ? void 0 : _test$location2.line}:${test.title}`;
110
+ return {
111
+ annotations: test.annotations,
112
+ expectedStatus: test.expectedStatus,
113
+ timeout: test.timeout,
114
+ retries: test.retries,
115
+ tags: test.tags,
116
+ results: testResultsById.get(key) ?? [],
117
+ status: test.outcome()
118
+ };
119
+ };
120
+ const extractMergedSteps = (rootDir, step) => ({
121
+ title: step.title,
122
+ duration: step.duration,
123
+ ...(step.error && {
124
+ error: {
125
+ message: step.error.message,
126
+ stack: step.error.stack,
127
+ snippet: step.error.snippet
128
+ }
129
+ }),
130
+ ...parseLocation(rootDir, step.location),
131
+ status: step.status,
132
+ ...(step.location && {
133
+ snippet: formSnippet(rootDir, step.location)
134
+ }),
135
+ ...(step.steps && step.steps.length > 0 && {
136
+ steps: step.steps.map(subStep => extractMergedSteps(rootDir, subStep))
137
+ })
138
+ });
139
+ const formSnippet = (rootDir, location) => {
140
+ if (location && !(location !== null && location !== void 0 && location.file)) return '';
141
+ try {
142
+ const {
143
+ file,
144
+ line,
145
+ column
146
+ } = parseLocation(rootDir, location, false);
147
+ const raw = _fs.default.readFileSync(file, 'utf8');
148
+ return (0, _codeFrame.codeFrameColumns)(raw, {
149
+ start: {
150
+ line,
151
+ column
152
+ }
153
+ }, {
154
+ linesAbove: 2,
155
+ linesBelow: 2,
156
+ highlightCode: true
157
+ });
158
+ } catch {
159
+ return '';
160
+ }
161
+ };
162
+ const parseLocation = (rootDir, {
163
+ file,
164
+ line,
165
+ column
166
+ } = {}, isRelative = true) => file ? {
167
+ file: isRelative ? _path.default.relative(rootDir, file) : file,
168
+ line,
169
+ column
170
+ } : {};
171
+ const stdioEntry = s => typeof s === 'string' ? {
172
+ text: s
173
+ } : {
174
+ buffer: s.toString('base64')
175
+ };
176
+ const processError = error => {
177
+ const message = error.message || error.value || '';
178
+ const stack = error.stack;
179
+ if (!stack && !error.location) return {
180
+ message
181
+ };
182
+ const tokens = [];
183
+ const parsedStack = stack ? constructErrorStack(stack) : undefined;
184
+ tokens.push((parsedStack === null || parsedStack === void 0 ? void 0 : parsedStack.message) || message);
185
+ if (error.snippet) {
186
+ tokens.push('');
187
+ tokens.push(error.snippet);
188
+ }
189
+ if (parsedStack && parsedStack.stackLines.length) {
190
+ const dimmedStackLines = parsedStack.stackLines.split('\n').map(line => dimify(line));
191
+ tokens.push(dimmedStackLines.join('\n'));
192
+ }
193
+ let location = error.location;
194
+ if (parsedStack && !location) location = parsedStack.location;
195
+ if (error.cause) tokens.push(dimify('[cause]: ') + processError(error.cause).message);
196
+ return {
197
+ location,
198
+ message: tokens.join('\n')
199
+ };
200
+ };
201
+ const constructErrorStack = stack => parseErrorStack(stack, _path.default.sep, false);
202
+ const dimify = text => `\x1b[2m${text}\x1b[22m`;
203
+ const parseErrorStack = (stack, pathSeparator, showInternalStackFrames = false) => {
204
+ const lines = stack.split("\n");
205
+ let firstStackLineIndex = lines.findIndex(line => line.startsWith(" at "));
206
+ if (firstStackLineIndex === -1) firstStackLineIndex = lines.length;
207
+ const message = lines.slice(0, firstStackLineIndex).join("\n");
208
+ const stackStartIndex = indexLocator(stack, '\n', firstStackLineIndex) + 1 || 0;
209
+ const stackLinesString = stackStartIndex ? stack.slice(stackStartIndex) : '';
210
+ let location;
211
+ const stackLinesArr = stackLinesString.split('\n');
212
+ for (const line of stackLinesArr) {
213
+ const frame = parseStackFrame(line, pathSeparator, showInternalStackFrames);
214
+ if (!frame || !frame.file) continue;
215
+ if (isInNodeModules(frame.file, pathSeparator)) continue;
216
+ location = {
217
+ file: frame.file,
218
+ column: frame.column || 0,
219
+ line: frame.line || 0
220
+ };
221
+ break;
222
+ }
223
+ return {
224
+ message,
225
+ stackLines: stackLinesString,
226
+ location
227
+ };
228
+ };
229
+ const indexLocator = (str, pat, n) => {
230
+ let L = str.length,
231
+ i = -1;
232
+ while (n-- && i++ < L) {
233
+ i = str.indexOf(pat, i);
234
+ if (i < 0) break;
235
+ }
236
+ return i;
237
+ };
238
+ const isInNodeModules = (file, pathSeparator) => file.includes(`${pathSeparator}node_modules${pathSeparator}`);
239
+ const parseStackFrame = (text, pathSeparator, showInternalStackFrames) => {
240
+ const re = new RegExp("^(?:\\s*at )?(?:(new) )?(?:(.*?) \\()?(?:eval at ([^ ]+) \\((.+?):(\\d+):(\\d+)\\), )?(?:(.+?):(\\d+):(\\d+)|(native))(\\)?)$");
241
+ const methodRe = /^(.*?) \[as (.*?)\]$/;
242
+ const match = text && text.match(re);
243
+ if (!match) return null;
244
+ let fname = match[2];
245
+ let file = match[7];
246
+ if (!file) return null;
247
+ if (!showInternalStackFrames && (file.startsWith("internal") || file.startsWith("node:"))) return null;
248
+ const line = match[8];
249
+ const column = match[9];
250
+ const closeParen = match[11] === ")";
251
+ const frame = {
252
+ file: "",
253
+ line: 0,
254
+ column: 0
255
+ };
256
+ if (line) frame.line = Number(line);
257
+ if (column) frame.column = Number(column);
258
+ if (closeParen && file) {
259
+ let closes = 0;
260
+ for (let i = file.length - 1; i > 0; i--) {
261
+ if (file.charAt(i) === ")") {
262
+ closes++;
263
+ } else if (file.charAt(i) === "(" && file.charAt(i - 1) === " ") {
264
+ closes--;
265
+ if (closes === -1 && file.charAt(i - 1) === " ") {
266
+ const before = file.slice(0, i - 1);
267
+ const after = file.slice(i + 1);
268
+ file = after;
269
+ fname += ` (${before}`;
270
+ break;
271
+ }
272
+ }
273
+ }
274
+ }
275
+ if (fname) {
276
+ const methodMatch = fname.match(methodRe);
277
+ if (methodMatch) fname = methodMatch[1];
278
+ }
279
+ if (file) {
280
+ if (file.startsWith("file://")) file = fileURLToPath(file, pathSeparator);
281
+ frame.file = file;
282
+ }
283
+ if (fname) frame.function = fname;
284
+ return frame;
285
+ };
286
+ const fileURLToPath = (fileUrl, pathSeparator) => {
287
+ if (!fileUrl.startsWith("file://")) return fileUrl;
288
+ let path = decodeURIComponent(fileUrl.slice(7));
289
+ if (path.startsWith("/") && /^[a-zA-Z]:/.test(path.slice(1))) path = path.slice(1);
290
+ return path.replace(/\//g, pathSeparator);
291
+ };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ var _logger = require("../../utils/logger");
4
+ function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
5
+ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
6
+ function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
7
+ var _TagProcessor_brand = /*#__PURE__*/new WeakSet();
8
+ class TagProcessor {
9
+ constructor(editionOrder) {
10
+ _classPrivateMethodInitSpec(this, _TagProcessor_brand);
11
+ this.editionOrder = editionOrder;
12
+ }
13
+ processTags(userArgs) {
14
+ const tagArgs = userArgs['tags'] || '';
15
+ const edition = userArgs['edition'] || null;
16
+ if (!edition) return tagArgs;
17
+ const editionsArray = edition.split(',');
18
+ const editionTags = editionsArray.length === 1 ? _assertClassBrand(_TagProcessor_brand, this, _processSingleEdition).call(this, editionsArray[0], tagArgs) : _assertClassBrand(_TagProcessor_brand, this, _processMultipleEditions).call(this, editionsArray, tagArgs);
19
+ return editionTags;
20
+ }
21
+ }
22
+ function _buildTagsString(tags, editionTags) {
23
+ return tags && tags !== '' ? `${tags} and not (${editionTags})` : `not (${editionTags})`;
24
+ }
25
+ function _parseEdition(edition) {
26
+ if (edition.startsWith('<=')) return ['<=', edition.slice(2)];
27
+ if (edition.startsWith('>=')) return ['>=', edition.slice(2)];
28
+ if (edition.startsWith('<')) return ['<', edition.slice(1)];
29
+ if (edition.startsWith('>')) return ['>', edition.slice(1)];
30
+ return [null, edition];
31
+ }
32
+ function _processSingleEdition(selectedEdition, tagArgs) {
33
+ const editionArgs = _assertClassBrand(_TagProcessor_brand, this, _getEditionArgs).call(this, selectedEdition);
34
+ if (editionArgs && editionArgs.length > 0) {
35
+ const editionTags = _assertClassBrand(_TagProcessor_brand, this, _buildEditionTags).call(this, editionArgs, 'or');
36
+ return _assertClassBrand(_TagProcessor_brand, this, _buildTagsString).call(this, tagArgs, editionTags);
37
+ }
38
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `No matching editions for ${selectedEdition} found. Running with default edition`);
39
+ return tagArgs;
40
+ }
41
+ function _processMultipleEditions(editionsArray, tagArgs) {
42
+ const filteredEditions = this.editionOrder.filter(edition => !editionsArray.includes(edition));
43
+ const editionTags = _assertClassBrand(_TagProcessor_brand, this, _buildEditionTags).call(this, filteredEditions, 'or');
44
+ return _assertClassBrand(_TagProcessor_brand, this, _buildTagsString).call(this, tagArgs, editionTags);
45
+ }
46
+ function _getEditionArgs(selectedEdition) {
47
+ const [operator, editionValue] = _assertClassBrand(_TagProcessor_brand, this, _parseEdition).call(this, selectedEdition.toLowerCase());
48
+ const index = this.editionOrder.findIndex(edition => edition.toLowerCase() === editionValue);
49
+ if (index === -1) {
50
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `No matching editions for ${selectedEdition} found. Running with default edition`);
51
+ return [];
52
+ }
53
+ switch (operator) {
54
+ case '<=':
55
+ return this.editionOrder.slice(index + 1);
56
+ case '>=':
57
+ return this.editionOrder.slice(0, index);
58
+ case '<':
59
+ return this.editionOrder.slice(index);
60
+ case '>':
61
+ return this.editionOrder.slice(0, index + 1);
62
+ default:
63
+ return this.editionOrder.filter((_, i) => i !== index);
64
+ }
65
+ }
66
+ function _buildEditionTags(editionArgs, operator = 'or') {
67
+ return editionArgs.map(edition => `@edition_${edition}`).join(` ${operator} `);
68
+ }
69
+ module.exports = TagProcessor;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ exports.runPreprocessing = runPreprocessing;
9
+ var _child_process = require("child_process");
10
+ var _path = _interopRequireDefault(require("path"));
11
+ var _customCommands = require("./custom-commands");
12
+ var _cliArgsToObject = require("../../utils/cliArgsToObject");
13
+ var _envInitializer = require("./env-initializer");
14
+ var _logger = require("../../utils/logger");
15
+ var _readConfigFile = require("./readConfigFile");
16
+ var _rootPath = require("../../utils/rootPath");
17
+ var _tagProcessor = _interopRequireDefault(require("./tagProcessor"));
18
+ var _configUtils = require("./setup/config-utils");
19
+ var _browserTypes = require("./constants/browserTypes");
20
+ var _ConfigurationHelper = require("./configuration/ConfigurationHelper");
21
+ var _Configuration = _interopRequireDefault(require("./configuration/Configuration"));
22
+ var _UserArgs = _interopRequireDefault(require("./configuration/UserArgs"));
23
+ var _RunnerHelper = _interopRequireDefault(require("./runner/RunnerHelper"));
24
+ var _Runner = _interopRequireDefault(require("./runner/Runner"));
25
+ function runPreprocessing(tagArgs, configPath) {
26
+ const beforeCommand = 'node';
27
+ const bddGenPath = _path.default.resolve((0, _rootPath.getExecutableBinaryPath)('bddgen'));
28
+ const beforeArgs = [bddGenPath, '-c', configPath];
29
+ if (tagArgs) {
30
+ beforeArgs.push('--tags');
31
+ beforeArgs.push(tagArgs);
32
+ }
33
+ return new Promise((resolve, reject) => {
34
+ const childProcessForPreprocessing = (0, _child_process.spawn)(beforeCommand, beforeArgs, {
35
+ stdio: 'inherit',
36
+ env: {
37
+ ...process.env
38
+ }
39
+ });
40
+ childProcessForPreprocessing.on('error', data => {
41
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, data);
42
+ reject(data);
43
+ });
44
+ childProcessForPreprocessing.on('exit', code => {
45
+ if (code === 0) {
46
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Feature Files Processed Successfully');
47
+ resolve();
48
+ } else {
49
+ reject(`BddGen exited with code ${code}`);
50
+ }
51
+ });
52
+ });
53
+ }
54
+ function runPlaywright(command, args) {
55
+ return new Promise((resolve, reject) => {
56
+ const childProcessForRunningPlaywright = (0, _child_process.spawn)(command, args, {
57
+ stdio: 'inherit',
58
+ env: {
59
+ ...process.env
60
+ }
61
+ });
62
+ childProcessForRunningPlaywright.on('error', error => {
63
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, error);
64
+ });
65
+ childProcessForRunningPlaywright.on('exit', (code, signal) => {
66
+ if (code !== 0) {
67
+ reject(`Child Process Exited with Code ${code} and Signal ${signal}`);
68
+ } else {
69
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Test Ran Successfully');
70
+ resolve();
71
+ }
72
+ });
73
+ process.on('exit', () => {
74
+ childProcessForRunningPlaywright.kill();
75
+ reject('Terminating Playwright Process...');
76
+ });
77
+ process.on('SIGINT', () => {
78
+ childProcessForRunningPlaywright.kill();
79
+ reject('Cleaning up...');
80
+ });
81
+ });
82
+ }
83
+ function main() {
84
+ // Getting the default config's from framework
85
+ const uatConfig = new _Configuration.default((0, _readConfigFile.getDefaultConfig)());
86
+ // overriding the application config's from project
87
+ const userArgConfig = new _Configuration.default(_UserArgs.default.parseToObject(process.argv.slice(2)));
88
+ const mode = userArgConfig.get("mode");
89
+ uatConfig.addAll(new _Configuration.default((0, _ConfigurationHelper.getApplicationConfig)(mode)));
90
+ // overriding the user config's from CLI
91
+ uatConfig.addAll(userArgConfig);
92
+ const modules = uatConfig.get('modules');
93
+
94
+ //We need to change this process.env variable to pass the module name in future.
95
+ process.env.modules = modules;
96
+ const {
97
+ isAuthMode,
98
+ editionOrder,
99
+ debug,
100
+ bddMode = false,
101
+ headless = false
102
+ } = uatConfig.getAll();
103
+ (0, _envInitializer.initializeEnvConfig)(mode, isAuthMode);
104
+
105
+ //This is only used for pass the user arguments to need places in legacy code. We need to rewamp that also.
106
+ const userArgsObject = userArgConfig.getAll();
107
+ const tagProcessor = new _tagProcessor.default(editionOrder);
108
+ const tagArgs = tagProcessor.processTags(userArgsObject);
109
+ const runnerObj = new _Runner.default();
110
+ runnerObj.setTagArgs(tagArgs);
111
+ runnerObj.setUserArgs(userArgsObject);
112
+ runnerObj.setConfig(uatConfig);
113
+ const runner = _RunnerHelper.default.createRunner('spawn', runnerObj);
114
+ runner.run();
115
+ }
116
+ var _default = exports.default = main;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * @typedef {Object|null} viewportConfig
3
+ * @property {number} width - width of the viewport
4
+ * @property {number} height - height of the viewport
5
+ */
6
+ /**
7
+ * @typedef {Object|null} viewportConfig
8
+ * @property {number} width - width of the viewport
9
+ * @property {number} height - height of the viewport
10
+ */
11
+
12
+ /**
13
+ * @typedef {Object|null} testSetupConfig
14
+ * @property {any} page - Function that will be called while setting up page fixtures
15
+ * @property {any} context - Function that will be called while setting up context fixtures
16
+ */
17
+
18
+ /**
19
+ * Represents the user configuration object.
20
+ * @typedef {Object} UserConfig
21
+ * @property {string} uatDirectory - Directory in which uat configuration is places.
22
+ * @property {string} headless - Headless Browsers mode.
23
+ * @property {number} trace - trace for test cases.
24
+ * @property {boolean} video - video for test cases,
25
+ * @property {boolean} debug - debug mode
26
+ * @property {string} mode: mode in which the test cases needs to run
27
+ * @property {boolean} isAuthMode - Auth Mode. config whether authentication step needed before running test cases
28
+ * @property {string} authFilePath - File Path where the cookies stored
29
+ * @property {any} browsers: List of browsers
30
+ * @property {string} openReportOn: default Option value (never, on-failure and always)
31
+ * @property {any} reportPath : directory where report is generate
32
+ * @property {boolean} bddMode: Feature files needs to be processed
33
+ * @property {number} expectTimeout: time in milliseconds which the expect condition should fail
34
+ * @property {number} testTimeout: time in milliseconds which the test should fail
35
+ * @property {Object} additionalPages: custom pages configuration
36
+ * @property {string} featureFilesFolder: folder name under which feature-files will be placed. Default is feature-files
37
+ * @property {string} stepDefinitionsFolder: folder name under which step implementations will be placed. Default is steps
38
+ * @property {viewportConfig} viewport: viewport configuration for the browser. Default is { width: 1280, height: 720 }
39
+ * @property {string} testIdAttribute: Change the default data-testid attribute. configure what attribute to search while calling getByTestId
40
+ * @property {Array} editionOrder: Order in the form of larger editions in the back. Edition with the most privelages should be last
41
+ * @property {testSetupConfig} testSetup: Specify page and context functions that will be called while intilaizing fixtures.
42
+ * @property {string} modules: Modules name to be used for running the specific module test cases.
43
+ */
44
+ "use strict";
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _parseUserArgs = _interopRequireDefault(require("./helpers/parseUserArgs"));
9
+ var _readConfigFile = require("./readConfigFile");
10
+ var _tagProcessor = _interopRequireDefault(require("./tagProcessor"));
11
+ var _testRunner = require("./test-runner");
12
+ var _logger = require("../../utils/logger");
13
+ const validateFeatureFiles = () => {
14
+ const userArgsObject = (0, _parseUserArgs.default)();
15
+ const uatConfig = (0, _readConfigFile.generateConfigFromFile)();
16
+ const {
17
+ editionOrder
18
+ } = uatConfig;
19
+ const configPath = (0, _readConfigFile.isUserConfigFileAvailable)() ? require.resolve('./setup/config-creator.js') : require.resolve('../../../playwright.config.js');
20
+ const tagProcessor = new _tagProcessor.default(editionOrder);
21
+ const tagArgs = tagProcessor.processTags(userArgsObject);
22
+ (0, _testRunner.runPreprocessing)(tagArgs, configPath).then(() => {
23
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Feature files validated successfully.');
24
+ }).catch(error => {
25
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Error while validating the feature files - ${error}`);
26
+ });
27
+ };
28
+ var _default = exports.default = validateFeatureFiles;
@@ -0,0 +1 @@
1
+ export * from 'playwright-bdd/decorators';
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _decorators = require("playwright-bdd/decorators");
7
+ Object.keys(_decorators).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _decorators[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _decorators[key];
14
+ }
15
+ });
16
+ });
@@ -0,0 +1,78 @@
1
+ import {
2
+ expect,
3
+ test,
4
+ createBdd
5
+ } from './core/playwright/index';
6
+ import { fireEvent, render } from '@testing-library/react';
7
+ import {
8
+ PlaywrightTestArgs,
9
+ PlaywrightTestOptions,
10
+ PlaywrightWorkerArgs,
11
+ PlaywrightWorkerOptions,
12
+ TestType,
13
+ Page
14
+ } from '@playwright/test';
15
+ import { DefineStepPattern } from '@cucumber/cucumber/lib/support_code_library_builder/types';
16
+
17
+ export type KeyValue = { [key: string]: any };
18
+
19
+ export type BuiltInFixturesWorker = PlaywrightWorkerArgs &
20
+ PlaywrightWorkerOptions;
21
+ export type BuiltInFixtures = PlaywrightTestArgs &
22
+ PlaywrightTestOptions &
23
+ BuiltInFixturesWorker;
24
+
25
+ export type FixturesArg<T extends KeyValue = {}, W extends KeyValue = {}> = T &
26
+ W &
27
+ BuiltInFixtures;
28
+
29
+ export declare let hasCustomTest: boolean;
30
+
31
+ export declare function createBdd<
32
+ T extends KeyValue = BuiltInFixtures,
33
+ W extends KeyValue = BuiltInFixturesWorker,
34
+ World
35
+ >(
36
+ customTest?: TestType<T, W> | null,
37
+ _CustomWorld?: new (...args: any[]) => World
38
+ ): {
39
+ Given: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
40
+ When: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
41
+ Then: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
42
+ And: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
43
+ But: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
44
+ Step: (pattern: DefineStepPattern, fn: StepFunction<T, W>) => void;
45
+ Before: any;
46
+ After: any;
47
+ BeforeAll: any;
48
+ AfterAll: any;
49
+ };
50
+
51
+ type StepFunctionFixturesArg<
52
+ T extends KeyValue,
53
+ W extends KeyValue
54
+ > = FixturesArg<T, W>;
55
+ type StepFunction<T extends KeyValue, W extends KeyValue> = (
56
+ fixtures: StepFunctionFixturesArg<T, W>,
57
+ ...args: any[]
58
+ ) => unknown;
59
+
60
+ const { Given, Then, When, Step, And, But } = createBdd();
61
+
62
+ type UserConfig = import('./core/playwright/readConfigFile').UserConfig;
63
+
64
+ export {
65
+ UserConfig,
66
+ Given,
67
+ Then,
68
+ When,
69
+ Step,
70
+ And,
71
+ But,
72
+ expect,
73
+ test,
74
+ createBdd,
75
+ Page
76
+ };
77
+
78
+ export * from '@playwright/test/types/test';