@zohodesk/testinglibrary 0.4.75-n18-experimental → 0.4.77-n18-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.
@@ -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
+ }
@@ -13,6 +13,9 @@ async function accountLogin(page, useremail, password) {
13
13
  await page.locator('#nextbtn').click();
14
14
  const domainUrlOrigin = (0, _getUrlOrigin.default)(process.env.domain);
15
15
  await page.waitForNavigation();
16
- await Promise.race([page.waitForURL(`${domainUrlOrigin}/**`), page.waitForURL('**/announcement/**')]);
16
+ if (!page.url().includes(domainUrlOrigin)) {
17
+ await page.goto(domainUrlOrigin);
18
+ }
19
+ await page.waitForURL(`${domainUrlOrigin}/**`);
17
20
  }
18
21
  var _default = exports.default = accountLogin;
@@ -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) {
@@ -80,7 +80,7 @@ class SpawnRunner extends _Runner.default {
80
80
  const args = ['test', '--config', require.resolve(configPath)].concat(playwrightArgs);
81
81
  return new Promise((resolve, reject) => {
82
82
  const childProcessForRunningPlaywright = (0, _child_process.spawn)(command, args, {
83
- stdio: 'pipe',
83
+ stdio: 'inherit',
84
84
  env: {
85
85
  ...process.env
86
86
  }
@@ -88,14 +88,6 @@ class SpawnRunner extends _Runner.default {
88
88
  childProcessForRunningPlaywright.on('error', error => {
89
89
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, error);
90
90
  });
91
- childProcessForRunningPlaywright.stdout.on('data', data => {
92
- let stdoutData = data.toString();
93
- if (stdoutData.includes('failed') && stdoutData.includes('smokeTest')) {
94
- console.log(stdoutData);
95
- console.log("Smoke test execution failed, so the main execution was skipped");
96
- _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Smoke Test Failed');
97
- }
98
- });
99
91
  childProcessForRunningPlaywright.on('exit', (code, signal) => {
100
92
  if (code !== 0) {
101
93
  reject(`Child Process Exited with Code ${code} and Signal ${signal}`);
@@ -38,9 +38,17 @@ const projects = (0, _configUtils.getProjects)({
38
38
  testTimeout,
39
39
  viewport
40
40
  });
41
- const testDir = (0, _configUtils.getTestDir)(bddMode, process.cwd(), {
42
- featureFilesFolder,
43
- 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')
44
52
  });
45
53
  const use = {
46
54
  trace,
@@ -52,8 +60,8 @@ let reporter = [['html', {
52
60
  outputFolder: reportPath,
53
61
  open: openReportOn
54
62
  }], ['list'], ['json', {
55
- outputFile: _path.default.join(process.cwd(), 'uat', 'test-results', 'test-results.json')
56
- }], ['./custom-reporter.js']];
63
+ outputFile: _path.default.join(process.cwd(), 'uat', 'test-results', 'playwright-test-results.json')
64
+ }], ['./custom-reporter.js'], ['./qc-custom-reporter.js']];
57
65
  if (customReporter) {
58
66
  reporter = [customReporter, ...reporter];
59
67
  }
@@ -71,8 +79,7 @@ function getPlaywrightConfig() {
71
79
  const dependencies = isAuthMode ? ['setup'] : [];
72
80
  const smokeTestProject = {
73
81
  name: 'smokeTest',
74
- testMatch: /.*\.smokeTest\.js/,
75
- testDir: _path.default.join(process.cwd(), 'uat'),
82
+ testDir: smokeTestDir,
76
83
  use: {
77
84
  ...commonConfig
78
85
  },
@@ -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");
@@ -168,18 +169,21 @@ function getModulePathForFeatureFiles(moduleList) {
168
169
  });
169
170
  return validModuleList;
170
171
  }
171
- function getTestDir(bddMode, cwd, {
172
- stepDefinitionsFolder
172
+ function getTestDir(bddMode, {
173
+ featureFilesFolder,
174
+ stepDefinitionsFolder,
175
+ outputDir,
176
+ uatPath
173
177
  }) {
174
178
  return bddMode ? (0, _playwrightBdd.defineBddConfig)({
175
- features: getPathsForFeatureFiles(cwd),
176
- steps: [_path.default.join(cwd, 'uat', '**', stepDefinitionsFolder, '*.spec.js'), require.resolve('../fixtures.js')],
179
+ features: featureFilesFolder,
180
+ steps: [stepDefinitionsFolder, require.resolve('../fixtures.js')],
177
181
  importTestFrom: require.resolve('../fixtures.js'),
178
- featuresRoot: _path.default.join(cwd, 'uat'),
179
- outputDir: _path.default.join(cwd, 'uat', '.features-gen'),
182
+ featuresRoot: uatPath,
183
+ outputDir: outputDir,
180
184
  disableWarnings: {
181
185
  importTestFrom: true
182
186
  },
183
187
  publish: true
184
- }) : _path.default.join(cwd, 'uat');
188
+ }) : uatPath;
185
189
  }
@@ -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
+ };
@@ -105,7 +105,7 @@ function main() {
105
105
  //This is only used for pass the user arguments to need places in legacy code. We need to rewamp that also.
106
106
  const userArgsObject = userArgConfig.getAll();
107
107
  const tagProcessor = new _tagProcessor.default(editionOrder);
108
- const tagArgs = tagProcessor.processTags(userArgsObject);
108
+ const tagArgs = tagProcessor.processTags(uatConfig.getAll());
109
109
  const runnerObj = new _Runner.default();
110
110
  runnerObj.setTagArgs(tagArgs);
111
111
  runnerObj.setUserArgs(userArgsObject);
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ delete require.cache[require.resolve('../core/playwright/runner/Runner')];
4
+ function test() {
5
+ const inputString = "@hc";
6
+ const selectedTag = ["@hc_1234"].reverse().find(tag => tag.startsWith(inputString));
7
+ let tagInput = null;
8
+ if (selectedTag) {
9
+ tagInput = selectedTag.split(`${inputString}_`).pop().toLowerCase();
10
+ }
11
+ console.log(tagInput);
12
+ }
13
+ test();