@zohodesk/testinglibrary 2.9.7 → 2.9.8
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/build/core/playwright/builtInFixtures/page.js +2 -1
- package/build/core/playwright/constants/fileMutexConfig.js +3 -9
- package/build/core/playwright/helpers/auth/loginSteps.js +2 -6
- package/build/core/playwright/helpers/fileMutex.js +45 -22
- package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +64 -39
- package/npm-shrinkwrap.json +10 -25
- package/package.json +1 -2
|
@@ -78,7 +78,8 @@ var _default = exports.default = {
|
|
|
78
78
|
if (!isAuthMode) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
const projectName = testInfo.project.name;
|
|
82
|
+
if (testPortalDetails && projectName !== 'setup' && projectName !== 'cleanup') {
|
|
82
83
|
await context.clearCookies();
|
|
83
84
|
await (0, _auth.performLoginSteps)(testDetails, async testInfo => {
|
|
84
85
|
return await verifyPageIsLoaded(testInfo);
|
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
retries: {
|
|
10
|
-
retries: 10,
|
|
11
|
-
factor: 1,
|
|
12
|
-
minTimeout: 10000,
|
|
13
|
-
maxTimeout: 20000
|
|
14
|
-
}
|
|
6
|
+
exports.fileDeletionTimeoutConfig = void 0;
|
|
7
|
+
const fileDeletionTimeoutConfig = exports.fileDeletionTimeoutConfig = {
|
|
8
|
+
timeout: 45000
|
|
15
9
|
};
|
|
@@ -21,7 +21,7 @@ async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
|
|
|
21
21
|
authFilePrefix = authFilePrefix || email;
|
|
22
22
|
const authFile = _path.default.resolve(_path.default.join((0, _checkAuthCookies.getAuthFileDirectory)(), `${authFilePrefix}-cookies.json`));
|
|
23
23
|
const lockFileName = email.replace(/[@.]/g, '_');
|
|
24
|
-
const fileMutex = new _fileMutex.default((0, _checkAuthDirectory.getLockDirectoryPath)(), lockFileName, _fileMutexConfig.
|
|
24
|
+
const fileMutex = new _fileMutex.default((0, _checkAuthDirectory.getLockDirectoryPath)(), lockFileName, email, authFile, _fileMutexConfig.fileDeletionTimeoutConfig);
|
|
25
25
|
try {
|
|
26
26
|
await fileMutex.acquire();
|
|
27
27
|
await (0, _checkAuthCookies.loadCookiesIfPresent)(page, authFile);
|
|
@@ -36,11 +36,7 @@ async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
|
|
|
36
36
|
} catch (error) {
|
|
37
37
|
console.error(`Error during login for ${email}:`, error);
|
|
38
38
|
} finally {
|
|
39
|
-
|
|
40
|
-
await fileMutex.release();
|
|
41
|
-
} catch (releaseError) {
|
|
42
|
-
console.error(`Error releasing lock for ${email}:`, releaseError);
|
|
43
|
-
}
|
|
39
|
+
await fileMutex.release();
|
|
44
40
|
}
|
|
45
41
|
}
|
|
46
42
|
var _default = exports.default = performLoginSteps;
|
|
@@ -6,48 +6,71 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
var _properLockfile = _interopRequireDefault(require("proper-lockfile"));
|
|
10
9
|
var _fs = require("fs");
|
|
11
10
|
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
12
11
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
13
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"); }
|
|
14
13
|
var _FileMutex_brand = /*#__PURE__*/new WeakSet();
|
|
15
14
|
class FileMutex {
|
|
16
|
-
constructor(directory, lockFileName,
|
|
15
|
+
constructor(directory, lockFileName, email, authFile, fileDeletionTimeoutConfig) {
|
|
17
16
|
_classPrivateMethodInitSpec(this, _FileMutex_brand);
|
|
18
17
|
this.directory = directory;
|
|
19
18
|
this.lockFileName = lockFileName + ".lock";
|
|
20
|
-
this.
|
|
19
|
+
this.email = email;
|
|
20
|
+
this.authFile = authFile;
|
|
21
|
+
this.fileDeletionTimeout = fileDeletionTimeoutConfig.timeout;
|
|
22
|
+
this.createDirectoryIfNotExist();
|
|
23
|
+
this.lockFilePath = _assertClassBrand(_FileMutex_brand, this, _getLockFilePath).call(this);
|
|
21
24
|
}
|
|
22
25
|
async acquire() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!(0, _fs.existsSync)(lockFilePath)) {
|
|
27
|
-
console.log(`[DEBUG] Creating missing lock file:`, this.lockFileName);
|
|
28
|
-
(0, _fs.writeFileSync)(lockFilePath, 'locked');
|
|
29
|
-
}
|
|
30
|
-
await _properLockfile.default.lock(lockFilePath, this.options);
|
|
31
|
-
} catch (err) {
|
|
32
|
-
throw new Error(`Failed to acquire lock after ${this.options.retries.retries} attempts: ${err.message}`);
|
|
26
|
+
if ((0, _fs.existsSync)(this.authFile)) {
|
|
27
|
+
console.log(`${this.email} Cookie file exists. Loading cookies...`);
|
|
28
|
+
return;
|
|
33
29
|
}
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
if (!(0, _fs.existsSync)(this.lockFilePath)) {
|
|
32
|
+
(0, _fs.writeFileSync)(this.lockFilePath, 'locked');
|
|
33
|
+
console.log(`Lock file created: ${this.lockFilePath}`);
|
|
34
|
+
return resolve();
|
|
35
|
+
}
|
|
36
|
+
const timeout = setTimeout(() => {
|
|
37
|
+
watcher.close();
|
|
38
|
+
reject(new Error('Watch timeout exceeded'));
|
|
39
|
+
}, this.fileDeletionTimeout);
|
|
40
|
+
const watcher = (0, _fs.watch)(this.directory, (eventType, filename) => {
|
|
41
|
+
try {
|
|
42
|
+
if (eventType === 'rename' && filename === this.lockFileName) {
|
|
43
|
+
clearTimeout(timeout);
|
|
44
|
+
console.log(`Lock file deleted! Proceeding...`);
|
|
45
|
+
watcher.close();
|
|
46
|
+
resolve();
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error(`Error watching for lock file deletion: ${err.message}`);
|
|
50
|
+
watcher.close();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
34
54
|
}
|
|
35
55
|
async release() {
|
|
36
56
|
try {
|
|
37
|
-
|
|
57
|
+
if ((0, _fs.existsSync)(this.lockFilePath)) {
|
|
58
|
+
(0, _fs.unlinkSync)(this.lockFilePath);
|
|
59
|
+
console.log(`Lock file deleted: ${this.lockFilePath}`);
|
|
60
|
+
}
|
|
38
61
|
} catch (err) {
|
|
39
|
-
|
|
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
|
+
});
|
|
40
70
|
}
|
|
41
71
|
}
|
|
42
72
|
}
|
|
43
73
|
function _getLockFilePath() {
|
|
44
74
|
return _path.default.resolve(_path.default.join(this.directory, this.lockFileName));
|
|
45
75
|
}
|
|
46
|
-
function _createDirectoryIfNotExist() {
|
|
47
|
-
if (!(0, _fs.existsSync)(this.directory)) {
|
|
48
|
-
(0, _fs.mkdirSync)(this.directory, {
|
|
49
|
-
recursive: true
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
76
|
var _default = exports.default = FileMutex;
|
|
@@ -2,70 +2,95 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
var _fileMutex = _interopRequireDefault(require("../../../../../core/playwright/helpers/fileMutex"));
|
|
5
|
-
var _properLockfile = _interopRequireDefault(require("proper-lockfile"));
|
|
6
5
|
var _path = _interopRequireDefault(require("path"));
|
|
7
|
-
var _fs =
|
|
8
|
-
jest.mock('proper-lockfile');
|
|
6
|
+
var _fs = require("fs");
|
|
9
7
|
jest.mock('fs');
|
|
10
8
|
describe('FileMutex', () => {
|
|
11
9
|
const directory = '/tmp/locks';
|
|
12
10
|
const lockFileName = 'test-lock';
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
factor: 1,
|
|
18
|
-
minTimeout: 5000,
|
|
19
|
-
maxTimeout: 8000
|
|
20
|
-
}
|
|
11
|
+
const email = 'test@example.com';
|
|
12
|
+
const authFile = '/tmp/authFile';
|
|
13
|
+
const fileDeletionTimeoutConfig = {
|
|
14
|
+
timeout: 1000
|
|
21
15
|
};
|
|
22
16
|
const lockFilePath = _path.default.resolve(directory, lockFileName + '.lock');
|
|
23
17
|
let fileMutex;
|
|
24
18
|
beforeEach(() => {
|
|
25
|
-
fileMutex = new _fileMutex.default(directory, lockFileName, options);
|
|
26
19
|
jest.clearAllMocks();
|
|
20
|
+
fileMutex = new _fileMutex.default(directory, lockFileName, email, authFile, fileDeletionTimeoutConfig);
|
|
27
21
|
});
|
|
28
22
|
describe('acquire', () => {
|
|
29
|
-
it('should create
|
|
30
|
-
_fs.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
await fileMutex.acquire();
|
|
34
|
-
expect(_fs.default.existsSync).toHaveBeenCalledWith(directory);
|
|
35
|
-
expect(_fs.default.mkdirSync).toHaveBeenCalledWith(directory, {
|
|
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, {
|
|
36
27
|
recursive: true
|
|
37
28
|
});
|
|
38
29
|
});
|
|
39
30
|
it('should create the lock file if it does not exist', async () => {
|
|
40
|
-
_fs.
|
|
41
|
-
_fs.
|
|
42
|
-
|
|
31
|
+
_fs.existsSync.mockImplementation(filePath => filePath === authFile ? false : false);
|
|
32
|
+
_fs.writeFileSync.mockImplementation(() => {});
|
|
33
|
+
await fileMutex.acquire();
|
|
34
|
+
expect(_fs.writeFileSync).toHaveBeenCalledWith(fileMutex.lockFilePath, 'locked');
|
|
35
|
+
});
|
|
36
|
+
it('should resolve immediately if auth file exists', async () => {
|
|
37
|
+
_fs.existsSync.mockImplementation(filePath => filePath === authFile);
|
|
43
38
|
await fileMutex.acquire();
|
|
44
|
-
expect(_fs.
|
|
45
|
-
expect(_fs.default.writeFileSync).toHaveBeenCalledWith(lockFilePath, 'locked');
|
|
39
|
+
expect(_fs.existsSync).toHaveBeenCalledWith(authFile);
|
|
46
40
|
});
|
|
47
|
-
it('should
|
|
48
|
-
_fs.
|
|
49
|
-
|
|
41
|
+
it('should wait for lock file deletion if it exists', async () => {
|
|
42
|
+
_fs.existsSync.mockImplementation(filePath => filePath === fileMutex.lockFilePath);
|
|
43
|
+
_fs.watch.mockImplementation((dir, callback) => {
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
_fs.existsSync.mockImplementation(() => false);
|
|
46
|
+
callback('rename', fileMutex.lockFileName);
|
|
47
|
+
}, fileDeletionTimeoutConfig);
|
|
48
|
+
return {
|
|
49
|
+
close: jest.fn()
|
|
50
|
+
};
|
|
51
|
+
});
|
|
50
52
|
await fileMutex.acquire();
|
|
51
|
-
expect(
|
|
53
|
+
expect(_fs.watch).toHaveBeenCalledWith(directory, expect.any(Function));
|
|
52
54
|
});
|
|
53
|
-
it('should
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
it('should reject if watch timeout exceeds', async () => {
|
|
56
|
+
_fs.existsSync.mockImplementation(filePath => filePath === lockFilePath);
|
|
57
|
+
_fs.watch.mockImplementation(() => {
|
|
58
|
+
return {
|
|
59
|
+
close: jest.fn()
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
await expect(fileMutex.acquire()).rejects.toThrow('Watch timeout exceeded');
|
|
57
63
|
});
|
|
58
64
|
});
|
|
59
65
|
describe('release', () => {
|
|
60
|
-
it('should
|
|
61
|
-
|
|
66
|
+
it('should delete the lock file if it exists', async () => {
|
|
67
|
+
_fs.existsSync.mockReturnValue(true);
|
|
68
|
+
_fs.unlinkSync.mockImplementation(() => {});
|
|
62
69
|
await fileMutex.release();
|
|
63
|
-
expect(
|
|
70
|
+
expect(_fs.existsSync).toHaveBeenCalledWith(lockFilePath);
|
|
71
|
+
expect(_fs.unlinkSync).toHaveBeenCalledWith(lockFilePath);
|
|
64
72
|
});
|
|
65
|
-
it('should
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
await
|
|
73
|
+
it('should release lock by deleting lock file', async () => {
|
|
74
|
+
_fs.existsSync.mockReturnValue(true);
|
|
75
|
+
_fs.unlinkSync.mockImplementation(() => {});
|
|
76
|
+
await fileMutex.release();
|
|
77
|
+
expect(_fs.unlinkSync).toHaveBeenCalledWith(lockFilePath);
|
|
78
|
+
});
|
|
79
|
+
it('should not attempt to delete the lock file if it does not exist', async () => {
|
|
80
|
+
_fs.existsSync.mockReturnValue(false);
|
|
81
|
+
await fileMutex.release();
|
|
82
|
+
expect(_fs.existsSync).toHaveBeenCalledWith(lockFilePath);
|
|
83
|
+
expect(_fs.unlinkSync).not.toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
it('should log an error if deleting the lock file fails', async () => {
|
|
86
|
+
const errorMessage = 'Error deleting lock file';
|
|
87
|
+
_fs.existsSync.mockReturnValue(true);
|
|
88
|
+
_fs.unlinkSync.mockImplementation(() => {
|
|
89
|
+
throw new Error(errorMessage);
|
|
90
|
+
});
|
|
91
|
+
console.error = jest.fn();
|
|
92
|
+
await fileMutex.release();
|
|
93
|
+
expect(console.error).toHaveBeenCalledWith(`Error deleting lock file: ${errorMessage}`);
|
|
69
94
|
});
|
|
70
95
|
});
|
|
71
96
|
});
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/testinglibrary",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.8",
|
|
4
4
|
"lockfileVersion": 1,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"dependencies": {
|
|
@@ -2714,9 +2714,9 @@
|
|
|
2714
2714
|
"integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg=="
|
|
2715
2715
|
},
|
|
2716
2716
|
"caniuse-lite": {
|
|
2717
|
-
"version": "1.0.
|
|
2718
|
-
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.
|
|
2719
|
-
"integrity": "sha512-
|
|
2717
|
+
"version": "1.0.30001698",
|
|
2718
|
+
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001698.tgz",
|
|
2719
|
+
"integrity": "sha512-xJ3km2oiG/MbNU8G6zIq6XRZ6HtAOVXsbOrP/blGazi52kc5Yy7b6sDA5O+FbROzRrV7BSTllLHuNvmawYUJjw=="
|
|
2720
2720
|
},
|
|
2721
2721
|
"capital-case": {
|
|
2722
2722
|
"version": "1.0.4",
|
|
@@ -3137,9 +3137,9 @@
|
|
|
3137
3137
|
}
|
|
3138
3138
|
},
|
|
3139
3139
|
"electron-to-chromium": {
|
|
3140
|
-
"version": "1.5.
|
|
3141
|
-
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.
|
|
3142
|
-
"integrity": "sha512-
|
|
3140
|
+
"version": "1.5.95",
|
|
3141
|
+
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.95.tgz",
|
|
3142
|
+
"integrity": "sha512-XNsZaQrgQX+BG37BRQv+E+HcOZlWhqYaDoVVNCws/WrYYdbGrkR1qCDJ2mviBF3flCs6/BTa4O7ANfFTFZk6Dg=="
|
|
3143
3143
|
},
|
|
3144
3144
|
"emittery": {
|
|
3145
3145
|
"version": "0.13.1",
|
|
@@ -5479,9 +5479,9 @@
|
|
|
5479
5479
|
"integrity": "sha512-mxz6zclokgrke9p1vtdy/COWBH+eOZgYUVVU34C73M+4j4HLlQJHtfcqiqqxpP0o8HhMkflvfbquLX5dg6wlfA=="
|
|
5480
5480
|
},
|
|
5481
5481
|
"possible-typed-array-names": {
|
|
5482
|
-
"version": "1.
|
|
5483
|
-
"resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.
|
|
5484
|
-
"integrity": "sha512
|
|
5482
|
+
"version": "1.1.0",
|
|
5483
|
+
"resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.1.0.tgz",
|
|
5484
|
+
"integrity": "sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg=="
|
|
5485
5485
|
},
|
|
5486
5486
|
"pretty-format": {
|
|
5487
5487
|
"version": "29.7.0",
|
|
@@ -5514,16 +5514,6 @@
|
|
|
5514
5514
|
"sisteransi": "^1.0.5"
|
|
5515
5515
|
}
|
|
5516
5516
|
},
|
|
5517
|
-
"proper-lockfile": {
|
|
5518
|
-
"version": "4.1.2",
|
|
5519
|
-
"resolved": "https://registry.npmjs.org/proper-lockfile/-/proper-lockfile-4.1.2.tgz",
|
|
5520
|
-
"integrity": "sha512-TjNPblN4BwAWMXU8s9AEz4JmQxnD1NNL7bNOY/AKUzyamc379FWASUhc/K1pL2noVb+XmZKLL68cjzLsiOAMaA==",
|
|
5521
|
-
"requires": {
|
|
5522
|
-
"graceful-fs": "^4.2.4",
|
|
5523
|
-
"retry": "^0.12.0",
|
|
5524
|
-
"signal-exit": "^3.0.2"
|
|
5525
|
-
}
|
|
5526
|
-
},
|
|
5527
5517
|
"property-expr": {
|
|
5528
5518
|
"version": "2.0.6",
|
|
5529
5519
|
"resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.6.tgz",
|
|
@@ -5781,11 +5771,6 @@
|
|
|
5781
5771
|
"signal-exit": "^3.0.2"
|
|
5782
5772
|
}
|
|
5783
5773
|
},
|
|
5784
|
-
"retry": {
|
|
5785
|
-
"version": "0.12.0",
|
|
5786
|
-
"resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz",
|
|
5787
|
-
"integrity": "sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow=="
|
|
5788
|
-
},
|
|
5789
5774
|
"reusify": {
|
|
5790
5775
|
"version": "1.0.4",
|
|
5791
5776
|
"resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zohodesk/testinglibrary",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.8",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"jest-environment-jsdom": "29.6.2",
|
|
35
35
|
"msw": "1.2.3",
|
|
36
36
|
"playwright": "1.42.1",
|
|
37
|
-
"proper-lockfile": "4.1.2",
|
|
38
37
|
"supports-color": "8.1.1"
|
|
39
38
|
},
|
|
40
39
|
"bin": {
|