@zohodesk/testinglibrary 0.4.56-experimental → 0.4.57-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.
@@ -24,11 +24,7 @@ function getAuthFileDirectory() {
24
24
  return _path.default.resolve(_path.default.join(uatDirectory, 'playwright', '.auth'));
25
25
  }
26
26
  function verifyIfCookieFileExists(authFile) {
27
- (0, _checkAuthDirectory.createAuthDirectoryIfNotExist)();
28
- if (!(0, _fs.existsSync)(authFile)) {
29
- console.log('creating auth file..');
30
- (0, _fs.writeFileSync)(authFile, JSON.stringify(authContent, null, 2));
31
- }
27
+ return (0, _fs.existsSync)(authFile);
32
28
  }
33
29
  function convertCookiesToParse(cookies, authFilePath) {
34
30
  try {
@@ -39,8 +35,11 @@ function convertCookiesToParse(cookies, authFilePath) {
39
35
  }
40
36
  }
41
37
  async function loadCookiesIfPresent(page, authFile) {
42
- verifyIfCookieFileExists(authFile);
43
- const cookies = (0, _fs.readFileSync)(authFile);
44
- const parsedCookies = convertCookiesToParse(cookies, authFile);
45
- await page.context().addCookies(parsedCookies.cookies === undefined ? [] : parsedCookies.cookies);
38
+ if (verifyIfCookieFileExists(authFile)) {
39
+ const fileContent = (0, _fs.readFileSync)(authFile);
40
+ const stroageState = convertCookiesToParse(fileContent, authFile);
41
+ if (stroageState.cookies) {
42
+ await page.context().addCookies(stroageState.cookies);
43
+ }
44
+ }
46
45
  }
@@ -10,6 +10,7 @@ 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");
13
14
  /* eslint-disable no-console */
14
15
 
15
16
  async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
@@ -20,23 +21,34 @@ async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
20
21
  } = testInfo;
21
22
  authFilePrefix = authFilePrefix || email;
22
23
  const authFile = _path.default.resolve(_path.default.join((0, _checkAuthCookies.getAuthFileDirectory)(), `${authFilePrefix}-cookies.json`));
24
+ const tempStoragePath = _path.default.resolve(_path.default.join((0, _checkAuthCookies.getAuthFileDirectory)(), `${authFilePrefix}-${Date.now()}-cookies.json`));
23
25
  const lockFileName = email.replace(/[@.]/g, '_');
24
- const fileMutex = new _fileMutex.default((0, _checkAuthDirectory.getLockDirectoryPath)(), lockFileName, email, authFile, _fileMutexConfig.fileDeletionTimeoutConfig);
26
+ const fileMutex = new _fileMutex.default((0, _checkAuthDirectory.getLockDirectoryPath)(), lockFileName, _fileMutexConfig.fileDeletionTimeoutConfig);
27
+ let loginUsingCookie = false;
25
28
  try {
26
- await fileMutex.acquire();
29
+ if ((0, _checkAuthCookies.verifyIfCookieFileExists)(authFile)) {
30
+ console.log(`${email} Cookie file exists. Loading cookies, worker index - ${process.env.TEST_WORKER_INDEX}`);
31
+ loginUsingCookie = true;
32
+ } else {
33
+ await fileMutex.acquire();
34
+ }
27
35
  await (0, _checkAuthCookies.loadCookiesIfPresent)(page, authFile);
28
36
  const isAlreadyLoggedIn = await isLoggedIn(testInfo);
29
37
  if (!isAlreadyLoggedIn) {
30
38
  await loginSteps(testInfo);
31
39
  await isLoggedIn(testInfo);
40
+ const isFileExists = (0, _fs.existsSync)(authFile);
41
+ const storageFilePath = isFileExists ? tempStoragePath : authFile;
32
42
  await page.context().storageState({
33
- path: authFile
43
+ path: storageFilePath
34
44
  });
35
45
  }
36
46
  } catch (error) {
37
47
  console.error(`Error during login for ${email}:`, error);
38
48
  } finally {
39
- await fileMutex.release();
49
+ if (!loginUsingCookie) {
50
+ await fileMutex.release();
51
+ }
40
52
  }
41
53
  }
42
54
  var _default = exports.default = performLoginSteps;
@@ -12,25 +12,19 @@ function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("C
12
12
  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"); }
13
13
  var _FileMutex_brand = /*#__PURE__*/new WeakSet();
14
14
  class FileMutex {
15
- constructor(directory, lockFileName, email, authFile, fileDeletionTimeoutConfig) {
15
+ constructor(directory, lockFileName, fileDeletionTimeoutConfig) {
16
16
  _classPrivateMethodInitSpec(this, _FileMutex_brand);
17
17
  this.directory = directory;
18
18
  this.lockFileName = lockFileName + ".lock";
19
- this.email = email;
20
- this.authFile = authFile;
21
19
  this.fileDeletionTimeout = fileDeletionTimeoutConfig.timeout;
22
- this.createDirectoryIfNotExist();
23
20
  this.lockFilePath = _assertClassBrand(_FileMutex_brand, this, _getLockFilePath).call(this);
21
+ _assertClassBrand(_FileMutex_brand, this, _createDirectoryIfNotExist).call(this);
24
22
  }
25
23
  async acquire() {
26
- if ((0, _fs.existsSync)(this.authFile)) {
27
- console.log(`${this.email} Cookie file exists. Loading cookies...`);
28
- return;
29
- }
30
24
  return new Promise((resolve, reject) => {
31
25
  if (!(0, _fs.existsSync)(this.lockFilePath)) {
32
26
  (0, _fs.writeFileSync)(this.lockFilePath, 'locked');
33
- console.log(`Lock file created: ${this.lockFilePath}`);
27
+ console.log(`Lock file created: ${this.lockFilePath}, worker index - ${process.env.TEST_WORKER_INDEX}`);
34
28
  return resolve();
35
29
  }
36
30
  const timeout = setTimeout(() => {
@@ -41,7 +35,7 @@ class FileMutex {
41
35
  try {
42
36
  if (eventType === 'rename' && filename === this.lockFileName) {
43
37
  clearTimeout(timeout);
44
- console.log(`Lock file deleted! Proceeding...`);
38
+ console.log(`Lock file deleted! Proceeding, worker index - ${process.env.TEST_WORKER_INDEX}`);
45
39
  watcher.close();
46
40
  resolve();
47
41
  }
@@ -56,21 +50,21 @@ class FileMutex {
56
50
  try {
57
51
  if ((0, _fs.existsSync)(this.lockFilePath)) {
58
52
  (0, _fs.unlinkSync)(this.lockFilePath);
59
- console.log(`Lock file deleted: ${this.lockFilePath}`);
53
+ console.log(`Lock file deleted: ${this.lockFilePath}, worker index - ${process.env.TEST_WORKER_INDEX}`);
60
54
  }
61
55
  } catch (err) {
62
- console.error(`Error deleting lock file: ${err.message}`);
63
- }
64
- }
65
- async createDirectoryIfNotExist() {
66
- if (!(0, _fs.existsSync)(this.directory)) {
67
- (0, _fs.mkdirSync)(this.directory, {
68
- recursive: true
69
- });
56
+ console.error(`Error deleting lock file: ${err.message}, worker index - ${process.env.TEST_WORKER_INDEX}`);
70
57
  }
71
58
  }
72
59
  }
73
60
  function _getLockFilePath() {
74
61
  return _path.default.resolve(_path.default.join(this.directory, this.lockFileName));
75
62
  }
63
+ async function _createDirectoryIfNotExist() {
64
+ if (!(0, _fs.existsSync)(this.directory)) {
65
+ (0, _fs.mkdirSync)(this.directory, {
66
+ recursive: true
67
+ });
68
+ }
69
+ }
76
70
  var _default = exports.default = FileMutex;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _page = require("../../../../../core/playwright/builtInFixtures/page");
5
+ var _executionContext = _interopRequireDefault(require("../../../../../core/playwright/builtInFixtures/executionContext"));
6
+ jest.mock('../../../../../core/playwright/builtInFixtures/page');
7
+ describe('executionContext', () => {
8
+ test('should pass actorInfo with details from getCustomAccountDetails to use', async () => {
9
+ const mockTags = ['tag1', 'tag2'];
10
+ const mockActorInfo = {
11
+ id: '1',
12
+ edition: 'enterprise',
13
+ orgName: 'orgName',
14
+ profile: 'admin',
15
+ email: 'xxx.x+uat@zohotest.com'
16
+ };
17
+ _page.getCustomAccountDetails.mockReturnValue(mockActorInfo);
18
+ const use = jest.fn();
19
+ await _executionContext.default.executionContext({
20
+ $tags: mockTags
21
+ }, use);
22
+ expect(_page.getCustomAccountDetails).toHaveBeenCalledWith(mockTags);
23
+ expect(use).toHaveBeenCalledWith({
24
+ actorInfo: mockActorInfo
25
+ });
26
+ });
27
+ });