@zohodesk/testinglibrary 3.1.10-experimental → 3.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitlab-ci.yml CHANGED
@@ -146,4 +146,18 @@ uatconfigmodule:
146
146
  paths:
147
147
  - examples/uat/playwright-report
148
148
 
149
+ uat-smoketest:
150
+ stage: uat
151
+ script:
152
+ - cd examples
153
+ - npm install $(npm pack ../../testing-framework | tail -1)
154
+ - output=$(npm run uat-smoketest)
155
+ - echo "$output"
156
+ - node ../ValidateUATReport.js examples
157
+
158
+ artifacts:
159
+ when: always
160
+ paths:
161
+ - examples/uat/playwright-report
162
+
149
163
 
@@ -9,6 +9,8 @@ var _auth = require("../helpers/auth");
9
9
  var _readConfigFile = require("../readConfigFile");
10
10
  /* eslint-disable global-require */
11
11
 
12
+ //import { additionProfiles } from '../helpers/additionalProfiles';
13
+
12
14
  function getTagInputFromSelectedTags(tags, inputString) {
13
15
  const selectedTag = [...tags].reverse().find(tag => tag.startsWith(inputString));
14
16
  let tagInput = null;
@@ -18,7 +20,7 @@ function getTagInputFromSelectedTags(tags, inputString) {
18
20
  return tagInput;
19
21
  }
20
22
  function getCustomAccountDetails(tags) {
21
- const tagsTobeFiltered = ['@profile', '@edition', '@beta', '@portal'];
23
+ const tagsTobeFiltered = ['@profile', '@edition', '@beta', '@portal', '@additional_profile'];
22
24
  const filteredTags = tags.filter(tag => tagsTobeFiltered.some(prefix => tag.startsWith(prefix)));
23
25
  if (filteredTags && filteredTags.length > 0) {
24
26
  const portalInfo = getTagInputFromSelectedTags(filteredTags, '@portal');
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.additionProfiles = additionProfiles;
7
+ var _getUsers = require("./auth/getUsers");
8
+ function additionProfiles(tags, editionInfo, betaFeature, portalInfo) {
9
+ const additionalProfileTags = tags.filter(tag => tag.startsWith('@additional_profile_'));
10
+ let additionalProfileActors = [];
11
+ if (additionalProfileTags.length > 0 && editionInfo) {
12
+ additionalProfileActors = additionalProfileTags.map(tag => {
13
+ const additionalProfile = tag.replace('@additional_profile_', '');
14
+ return (0, _getUsers.getUserForSelectedEditionAndProfile)(editionInfo, additionalProfile, betaFeature, portalInfo);
15
+ });
16
+ }
17
+ return additionalProfileActors;
18
+ }
@@ -4,12 +4,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- Object.defineProperty(exports, "DataGenerator", {
8
- enumerable: true,
9
- get: function () {
10
- return _DataGenerator.default;
11
- }
12
- });
13
7
  Object.defineProperty(exports, "accountLogin", {
14
8
  enumerable: true,
15
9
  get: function () {
@@ -79,5 +73,4 @@ Object.defineProperty(exports, "verifyIfCookieFileExists", {
79
73
  var _accountLogin = _interopRequireDefault(require("./accountLogin"));
80
74
  var _checkAuthCookies = require("./checkAuthCookies");
81
75
  var _getUsers = require("./getUsers");
82
- var _loginSteps = _interopRequireDefault(require("./loginSteps"));
83
- var _DataGenerator = _interopRequireDefault(require("../../../../common/data-generator/DataGenerator"));
76
+ var _loginSteps = _interopRequireDefault(require("./loginSteps"));
@@ -10,7 +10,6 @@ var _fileMutex = _interopRequireDefault(require("../fileMutex"));
10
10
  var _fileMutexConfig = require("../../constants/fileMutexConfig");
11
11
  var _checkAuthCookies = require("./checkAuthCookies");
12
12
  var _checkAuthDirectory = require("../checkAuthDirectory");
13
- var _fs = require("fs");
14
13
  /* eslint-disable no-console */
15
14
 
16
15
  async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
@@ -12,6 +12,7 @@ var _configUtils = require("./config-utils");
12
12
  const uatConfig = (0, _readConfigFile.generateConfigFromFile)();
13
13
  const {
14
14
  browsers,
15
+ isSmokeTest,
15
16
  trace,
16
17
  video,
17
18
  isAuthMode,
@@ -31,6 +32,7 @@ const {
31
32
  const projects = (0, _configUtils.getProjects)({
32
33
  browsers,
33
34
  isAuthMode,
35
+ isSmokeTest,
34
36
  authFilePath,
35
37
  expectTimeout,
36
38
  testTimeout,
@@ -61,7 +63,21 @@ if (customReporter) {
61
63
  *
62
64
  * @returns {import('@playwright/test').PlaywrightTestConfig}
63
65
  */
66
+
64
67
  function getPlaywrightConfig() {
68
+ const commonConfig = {
69
+ storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), authFilePath)) : {}
70
+ };
71
+ const dependencies = isAuthMode ? ['setup'] : [];
72
+ const smokeTestProject = {
73
+ name: 'smokeTest',
74
+ testMatch: /.*\.smokeTest\.js/,
75
+ testDir: _path.default.join(process.cwd(), 'uat'),
76
+ use: {
77
+ ...commonConfig
78
+ },
79
+ dependencies: dependencies
80
+ };
65
81
  const playwrightConfig = {
66
82
  testDir,
67
83
  globalTimeout: globalTimeout || 3600000,
@@ -78,11 +94,11 @@ function getPlaywrightConfig() {
78
94
  testMatch: /.*\.setup\.js/,
79
95
  testDir: _path.default.join(process.cwd(), 'uat'),
80
96
  teardown: 'cleanup'
81
- }, {
97
+ }, ...(isSmokeTest ? [smokeTestProject] : []), {
82
98
  name: 'cleanup',
83
99
  testMatch: /.*\.teardown\.js/,
84
100
  testDir: _path.default.join(process.cwd(), 'uat')
85
- }, ...projects] : [...projects],
101
+ }, ...projects] : [...projects, ...(isSmokeTest ? [smokeTestProject] : [])],
86
102
  ...uatConfig
87
103
  };
88
104
  return playwrightConfig;
@@ -19,9 +19,11 @@ var _fileUtils = require("../../../utils/fileUtils");
19
19
  ** Playwright project configuration
20
20
  * @returns {import('@playwright/test').Project}
21
21
  */
22
+
22
23
  function getBrowserConfig({
23
24
  browserName,
24
25
  isAuthMode,
26
+ isSmokeTest,
25
27
  authFilePath,
26
28
  expectTimeout,
27
29
  testTimeout,
@@ -32,7 +34,9 @@ function getBrowserConfig({
32
34
  viewport,
33
35
  storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), authFilePath)) : {}
34
36
  };
35
- const dependencies = isAuthMode ? ['setup'] : [];
37
+ // Determine dependencies based on the mode and smoke test status
38
+ let dependencies = isAuthMode ? ['setup'] : [];
39
+ dependencies = isSmokeTest ? [...dependencies, 'smokeTest'] : dependencies;
36
40
  if (browser === 'chrome') {
37
41
  return {
38
42
  name: _browserTypes.BROWSER_PROJECT_MAPPING.CHROME,
@@ -99,6 +103,7 @@ function getBrowserConfig({
99
103
  function getProjects({
100
104
  browsers,
101
105
  isAuthMode,
106
+ isSmokeTest,
102
107
  authFilePath,
103
108
  expectTimeout,
104
109
  testTimeout,
@@ -107,6 +112,7 @@ function getProjects({
107
112
  return browsers.map(browserName => getBrowserConfig({
108
113
  browserName,
109
114
  isAuthMode,
115
+ isSmokeTest,
110
116
  authFilePath,
111
117
  expectTimeout,
112
118
  testTimeout,
@@ -167,7 +173,7 @@ function getTestDir(bddMode, cwd, {
167
173
  }) {
168
174
  return bddMode ? (0, _playwrightBdd.defineBddConfig)({
169
175
  features: getPathsForFeatureFiles(cwd),
170
- steps: [_path.default.join(cwd, 'uat', '**', stepDefinitionsFolder, '*.spec.js'), _path.default.join(cwd, '/node_modules/@zohodesk/testinglibrary/build/common/', '**', 'uat', '**', '*.spec.js'), require.resolve('../fixtures.js')],
176
+ steps: [_path.default.join(cwd, 'uat', '**', stepDefinitionsFolder, '*.spec.js'), require.resolve('../fixtures.js')],
171
177
  importTestFrom: require.resolve('../fixtures.js'),
172
178
  featuresRoot: _path.default.join(cwd, 'uat'),
173
179
  outputDir: _path.default.join(cwd, 'uat', '.features-gen'),
@@ -32,23 +32,12 @@ class CustomJsonReporter {
32
32
  attachments: result.attachments,
33
33
  startTime: result.startTime,
34
34
  retry: result.retry,
35
- stderr: result.stderr.map(err => ({
36
- text: err
37
- })),
38
- stdout: result.stdout.map(out => ({
39
- text: out
40
- })),
35
+ stderr: result.stderr.map(err => stdioEntry(err)),
36
+ stdout: result.stdout.map(out => stdioEntry(out)),
41
37
  workerIndex: result.workerIndex,
42
38
  duration: result.duration,
43
- errors: ((_result$errors = result.errors) === null || _result$errors === void 0 ? void 0 : _result$errors.map(({
44
- message,
45
- stack,
46
- snippet
47
- }) => ({
48
- message,
49
- stack,
50
- snippet
51
- }))) ?? [],
39
+ error: result.error,
40
+ errors: (_result$errors = result.errors) === null || _result$errors === void 0 ? void 0 : _result$errors.map(processError),
52
41
  steps: ((_result$steps = result.steps) === null || _result$steps === void 0 ? void 0 : _result$steps.map(step => extractMergedSteps(this.report.config.rootDir, step))) ?? []
53
42
  };
54
43
  const existingResults = this.testResultsById.get(key) ?? [];
@@ -60,7 +49,22 @@ class CustomJsonReporter {
60
49
  const extracted = suite.suites.map(suite => extractMergedSuite(this.report.config.rootDir, suite, this.testResultsById));
61
50
  this.report.suites.push(...extracted);
62
51
  });
63
- _fs.default.writeFileSync(this.outputFile, JSON.stringify(this.report, null, 2));
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();
64
68
  console.log(`Custom JSON report written to: ${this.outputFile}`);
65
69
  }
66
70
  }
@@ -163,4 +167,125 @@ const parseLocation = (rootDir, {
163
167
  file: isRelative ? _path.default.relative(rootDir, file) : file,
164
168
  line,
165
169
  column
166
- } : {};
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
+ };