@zohodesk/testinglibrary 3.1.10-experimental → 3.1.14

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,14 +32,23 @@ 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,
37
39
  viewport
38
40
  });
39
- const testDir = (0, _configUtils.getTestDir)(bddMode, process.cwd(), {
40
- featureFilesFolder,
41
- stepDefinitionsFolder
41
+ const testDir = (0, _configUtils.getTestDir)(bddMode, {
42
+ featureFilesFolder: (0, _configUtils.getPathsForFeatureFiles)(process.cwd()),
43
+ stepDefinitionsFolder: _path.default.join(process.cwd(), 'uat', '**', 'steps', '*.spec.js'),
44
+ outputDir: _path.default.join(process.cwd(), 'uat', '.features-gen'),
45
+ uatPath: _path.default.join(process.cwd(), 'uat')
46
+ });
47
+ const smokeTestDir = (0, _configUtils.getTestDir)(bddMode, {
48
+ featureFilesFolder: _path.default.join(process.cwd(), 'uat', 'smokeTest', '**', '*.feature'),
49
+ stepDefinitionsFolder: _path.default.join(process.cwd(), 'uat', 'smokeTest', '**', '*smokeTest.spec.js'),
50
+ outputDir: _path.default.join(process.cwd(), 'uat', '.features-smoke-gen'),
51
+ uatPath: _path.default.join(process.cwd(), 'uat', 'smokeTest')
42
52
  });
43
53
  const use = {
44
54
  trace,
@@ -61,7 +71,20 @@ if (customReporter) {
61
71
  *
62
72
  * @returns {import('@playwright/test').PlaywrightTestConfig}
63
73
  */
74
+
64
75
  function getPlaywrightConfig() {
76
+ const commonConfig = {
77
+ storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), authFilePath)) : {}
78
+ };
79
+ const dependencies = isAuthMode ? ['setup'] : [];
80
+ const smokeTestProject = {
81
+ name: 'smokeTest',
82
+ testDir: smokeTestDir,
83
+ use: {
84
+ ...commonConfig
85
+ },
86
+ dependencies: dependencies
87
+ };
65
88
  const playwrightConfig = {
66
89
  testDir,
67
90
  globalTimeout: globalTimeout || 3600000,
@@ -78,11 +101,11 @@ function getPlaywrightConfig() {
78
101
  testMatch: /.*\.setup\.js/,
79
102
  testDir: _path.default.join(process.cwd(), 'uat'),
80
103
  teardown: 'cleanup'
81
- }, {
104
+ }, ...(isSmokeTest ? [smokeTestProject] : []), {
82
105
  name: 'cleanup',
83
106
  testMatch: /.*\.teardown\.js/,
84
107
  testDir: _path.default.join(process.cwd(), 'uat')
85
- }, ...projects] : [...projects],
108
+ }, ...projects] : [...projects, ...(isSmokeTest ? [smokeTestProject] : [])],
86
109
  ...uatConfig
87
110
  };
88
111
  return playwrightConfig;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.getBrowsersList = getBrowsersList;
8
8
  exports.getModulePathForFeatureFiles = getModulePathForFeatureFiles;
9
+ exports.getPathsForFeatureFiles = getPathsForFeatureFiles;
9
10
  exports.getProjects = getProjects;
10
11
  exports.getTestDir = getTestDir;
11
12
  var _test = require("@playwright/test");
@@ -19,9 +20,11 @@ var _fileUtils = require("../../../utils/fileUtils");
19
20
  ** Playwright project configuration
20
21
  * @returns {import('@playwright/test').Project}
21
22
  */
23
+
22
24
  function getBrowserConfig({
23
25
  browserName,
24
26
  isAuthMode,
27
+ isSmokeTest,
25
28
  authFilePath,
26
29
  expectTimeout,
27
30
  testTimeout,
@@ -32,7 +35,9 @@ function getBrowserConfig({
32
35
  viewport,
33
36
  storageState: isAuthMode ? (0, _readConfigFile.getAuthFilePath)(_path.default.resolve(process.cwd(), authFilePath)) : {}
34
37
  };
35
- const dependencies = isAuthMode ? ['setup'] : [];
38
+ // Determine dependencies based on the mode and smoke test status
39
+ let dependencies = isAuthMode ? ['setup'] : [];
40
+ dependencies = isSmokeTest ? [...dependencies, 'smokeTest'] : dependencies;
36
41
  if (browser === 'chrome') {
37
42
  return {
38
43
  name: _browserTypes.BROWSER_PROJECT_MAPPING.CHROME,
@@ -99,6 +104,7 @@ function getBrowserConfig({
99
104
  function getProjects({
100
105
  browsers,
101
106
  isAuthMode,
107
+ isSmokeTest,
102
108
  authFilePath,
103
109
  expectTimeout,
104
110
  testTimeout,
@@ -107,6 +113,7 @@ function getProjects({
107
113
  return browsers.map(browserName => getBrowserConfig({
108
114
  browserName,
109
115
  isAuthMode,
116
+ isSmokeTest,
110
117
  authFilePath,
111
118
  expectTimeout,
112
119
  testTimeout,
@@ -162,18 +169,21 @@ function getModulePathForFeatureFiles(moduleList) {
162
169
  });
163
170
  return validModuleList;
164
171
  }
165
- function getTestDir(bddMode, cwd, {
166
- stepDefinitionsFolder
172
+ function getTestDir(bddMode, {
173
+ featureFilesFolder,
174
+ stepDefinitionsFolder,
175
+ outputDir,
176
+ uatPath
167
177
  }) {
168
178
  return bddMode ? (0, _playwrightBdd.defineBddConfig)({
169
- 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')],
179
+ features: featureFilesFolder,
180
+ steps: [stepDefinitionsFolder, require.resolve('../fixtures.js')],
171
181
  importTestFrom: require.resolve('../fixtures.js'),
172
- featuresRoot: _path.default.join(cwd, 'uat'),
173
- outputDir: _path.default.join(cwd, 'uat', '.features-gen'),
182
+ featuresRoot: uatPath,
183
+ outputDir: outputDir,
174
184
  disableWarnings: {
175
185
  importTestFrom: true
176
186
  },
177
187
  publish: true
178
- }) : _path.default.join(cwd, 'uat');
188
+ }) : uatPath;
179
189
  }
@@ -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
+ };