@zohodesk/testinglibrary 0.4.57-n18-experimental → 0.4.58-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.
@@ -21,7 +21,6 @@ async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
21
21
  } = testInfo;
22
22
  authFilePrefix = authFilePrefix || email;
23
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`));
25
24
  const lockFileName = email.replace(/[@.]/g, '_');
26
25
  const fileMutex = new _fileMutex.default((0, _checkAuthDirectory.getLockDirectoryPath)(), lockFileName, _fileMutexConfig.fileDeletionTimeoutConfig);
27
26
  let loginUsingCookie = false;
@@ -34,14 +33,22 @@ async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
34
33
  }
35
34
  await (0, _checkAuthCookies.loadCookiesIfPresent)(page, authFile);
36
35
  const isAlreadyLoggedIn = await isLoggedIn(testInfo);
36
+ let storage = {};
37
37
  if (!isAlreadyLoggedIn) {
38
38
  await loginSteps(testInfo);
39
39
  await isLoggedIn(testInfo);
40
- const isFileExists = (0, _fs.existsSync)(authFile);
41
- const storageFilePath = isFileExists ? tempStoragePath : authFile;
42
40
  await page.context().storageState({
43
- path: storageFilePath
41
+ path: authFile
44
42
  });
43
+ if ((0, _fs.existsSync)(authFile)) {
44
+ const fileContent = await (0, _fs.readFileSync)(authFile, 'utf-8');
45
+ storage = JSON.parse(fileContent);
46
+ }
47
+ const modifiedStorage = {
48
+ ...storage,
49
+ domain: page.url()
50
+ };
51
+ (0, _fs.writeFileSync)(authFile, JSON.stringify(modifiedStorage), null, 2);
45
52
  }
46
53
  } catch (error) {
47
54
  console.error(`Error during login for ${email}:`, error);
@@ -54,6 +54,7 @@ class FileMutex {
54
54
  }
55
55
  } catch (err) {
56
56
  console.error(`Error deleting lock file: ${err.message}, worker index - ${process.env.TEST_WORKER_INDEX}`);
57
+ throw err;
57
58
  }
58
59
  }
59
60
  }
@@ -8,8 +8,6 @@ jest.mock('fs');
8
8
  describe('FileMutex', () => {
9
9
  const directory = '/tmp/locks';
10
10
  const lockFileName = 'test-lock';
11
- const email = 'test@example.com';
12
- const authFile = '/tmp/authFile';
13
11
  const fileDeletionTimeoutConfig = {
14
12
  timeout: 1000
15
13
  };
@@ -17,27 +15,14 @@ describe('FileMutex', () => {
17
15
  let fileMutex;
18
16
  beforeEach(() => {
19
17
  jest.clearAllMocks();
20
- fileMutex = new _fileMutex.default(directory, lockFileName, email, authFile, fileDeletionTimeoutConfig);
18
+ fileMutex = new _fileMutex.default(directory, lockFileName, fileDeletionTimeoutConfig);
21
19
  });
22
20
  describe('acquire', () => {
23
- it('should create directory if it does not exist', async () => {
24
- _fs.existsSync.mockReturnValue(false);
25
- await fileMutex.createDirectoryIfNotExist();
26
- expect(_fs.mkdirSync).toHaveBeenCalledWith(directory, {
27
- recursive: true
28
- });
29
- });
30
21
  it('should create the lock file if it does not exist', async () => {
31
- _fs.existsSync.mockImplementation(filePath => filePath === authFile ? false : false);
32
22
  _fs.writeFileSync.mockImplementation(() => {});
33
23
  await fileMutex.acquire();
34
24
  expect(_fs.writeFileSync).toHaveBeenCalledWith(fileMutex.lockFilePath, 'locked');
35
25
  });
36
- it('should resolve immediately if auth file exists', async () => {
37
- _fs.existsSync.mockImplementation(filePath => filePath === authFile);
38
- await fileMutex.acquire();
39
- expect(_fs.existsSync).toHaveBeenCalledWith(authFile);
40
- });
41
26
  it('should wait for lock file deletion if it exists', async () => {
42
27
  _fs.existsSync.mockImplementation(filePath => filePath === fileMutex.lockFilePath);
43
28
  _fs.watch.mockImplementation((dir, callback) => {
@@ -88,9 +73,7 @@ describe('FileMutex', () => {
88
73
  _fs.unlinkSync.mockImplementation(() => {
89
74
  throw new Error(errorMessage);
90
75
  });
91
- console.error = jest.fn();
92
- await fileMutex.release();
93
- expect(console.error).toHaveBeenCalledWith(`Error deleting lock file: ${errorMessage}`);
76
+ await expect(fileMutex.release()).rejects.toThrow(errorMessage);
94
77
  });
95
78
  });
96
79
  });
@@ -61,7 +61,7 @@ function deleteFile(filePath) {
61
61
  function deleteFolder(folderPath) {
62
62
  if (_fs.default.existsSync(folderPath)) {
63
63
  try {
64
- _fs.default.rmdirSync(folderPath, {
64
+ _fs.default.rmSync(folderPath, {
65
65
  recursive: true
66
66
  });
67
67
  } catch (err) {