@zohodesk/testinglibrary 0.4.57-n18-experimental → 0.4.59-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.
@@ -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;
@@ -37,10 +36,8 @@ async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
37
36
  if (!isAlreadyLoggedIn) {
38
37
  await loginSteps(testInfo);
39
38
  await isLoggedIn(testInfo);
40
- const isFileExists = (0, _fs.existsSync)(authFile);
41
- const storageFilePath = isFileExists ? tempStoragePath : authFile;
42
39
  await page.context().storageState({
43
- path: storageFilePath
40
+ path: authFile
44
41
  });
45
42
  }
46
43
  } catch (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
  });