@zohodesk/testinglibrary 3.0.9 → 3.1.0
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 +51 -28
- package/build/core/playwright/tagProcessor.js +28 -18
- package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +64 -39
- package/npm-shrinkwrap.json +2352 -3277
- package/package.json +2 -3
|
@@ -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
|
-
function _classPrivateMethodInitSpec(
|
|
12
|
-
function _checkPrivateRedeclaration(
|
|
13
|
-
function
|
|
14
|
-
var
|
|
10
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
11
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
12
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
13
|
+
var _getLockFilePath = /*#__PURE__*/new WeakSet();
|
|
15
14
|
class FileMutex {
|
|
16
|
-
constructor(directory, lockFileName,
|
|
17
|
-
_classPrivateMethodInitSpec(this,
|
|
15
|
+
constructor(directory, lockFileName, email, authFile, fileDeletionTimeoutConfig) {
|
|
16
|
+
_classPrivateMethodInitSpec(this, _getLockFilePath);
|
|
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 = _classPrivateMethodGet(this, _getLockFilePath, _getLockFilePath2).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
|
-
function
|
|
73
|
+
function _getLockFilePath2() {
|
|
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;
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _logger = require("../../utils/logger");
|
|
4
|
-
function _classPrivateMethodInitSpec(
|
|
5
|
-
function _checkPrivateRedeclaration(
|
|
6
|
-
function
|
|
7
|
-
var
|
|
4
|
+
function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
|
|
5
|
+
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
6
|
+
function _classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return fn; }
|
|
7
|
+
var _buildTagsString = /*#__PURE__*/new WeakSet();
|
|
8
|
+
var _parseEdition = /*#__PURE__*/new WeakSet();
|
|
9
|
+
var _processSingleEdition = /*#__PURE__*/new WeakSet();
|
|
10
|
+
var _processMultipleEditions = /*#__PURE__*/new WeakSet();
|
|
11
|
+
var _getEditionArgs = /*#__PURE__*/new WeakSet();
|
|
12
|
+
var _buildEditionTags = /*#__PURE__*/new WeakSet();
|
|
8
13
|
class TagProcessor {
|
|
9
14
|
constructor(editionOrder) {
|
|
10
|
-
_classPrivateMethodInitSpec(this,
|
|
15
|
+
_classPrivateMethodInitSpec(this, _buildEditionTags);
|
|
16
|
+
_classPrivateMethodInitSpec(this, _getEditionArgs);
|
|
17
|
+
_classPrivateMethodInitSpec(this, _processMultipleEditions);
|
|
18
|
+
_classPrivateMethodInitSpec(this, _processSingleEdition);
|
|
19
|
+
_classPrivateMethodInitSpec(this, _parseEdition);
|
|
20
|
+
_classPrivateMethodInitSpec(this, _buildTagsString);
|
|
11
21
|
this.editionOrder = editionOrder;
|
|
12
22
|
}
|
|
13
23
|
processTags(userArgs) {
|
|
@@ -15,36 +25,36 @@ class TagProcessor {
|
|
|
15
25
|
const edition = userArgs['edition'] || null;
|
|
16
26
|
if (!edition) return tagArgs;
|
|
17
27
|
const editionsArray = edition.split(',');
|
|
18
|
-
const editionTags = editionsArray.length === 1 ?
|
|
28
|
+
const editionTags = editionsArray.length === 1 ? _classPrivateMethodGet(this, _processSingleEdition, _processSingleEdition2).call(this, editionsArray[0], tagArgs) : _classPrivateMethodGet(this, _processMultipleEditions, _processMultipleEditions2).call(this, editionsArray, tagArgs);
|
|
19
29
|
return editionTags;
|
|
20
30
|
}
|
|
21
31
|
}
|
|
22
|
-
function
|
|
32
|
+
function _buildTagsString2(tags, editionTags) {
|
|
23
33
|
return tags && tags !== '' ? `${tags} and not (${editionTags})` : `not (${editionTags})`;
|
|
24
34
|
}
|
|
25
|
-
function
|
|
35
|
+
function _parseEdition2(edition) {
|
|
26
36
|
if (edition.startsWith('<=')) return ['<=', edition.slice(2)];
|
|
27
37
|
if (edition.startsWith('>=')) return ['>=', edition.slice(2)];
|
|
28
38
|
if (edition.startsWith('<')) return ['<', edition.slice(1)];
|
|
29
39
|
if (edition.startsWith('>')) return ['>', edition.slice(1)];
|
|
30
40
|
return [null, edition];
|
|
31
41
|
}
|
|
32
|
-
function
|
|
33
|
-
const editionArgs =
|
|
42
|
+
function _processSingleEdition2(selectedEdition, tagArgs) {
|
|
43
|
+
const editionArgs = _classPrivateMethodGet(this, _getEditionArgs, _getEditionArgs2).call(this, selectedEdition);
|
|
34
44
|
if (editionArgs && editionArgs.length > 0) {
|
|
35
|
-
const editionTags =
|
|
36
|
-
return
|
|
45
|
+
const editionTags = _classPrivateMethodGet(this, _buildEditionTags, _buildEditionTags2).call(this, editionArgs, 'or');
|
|
46
|
+
return _classPrivateMethodGet(this, _buildTagsString, _buildTagsString2).call(this, tagArgs, editionTags);
|
|
37
47
|
}
|
|
38
48
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, `No matching editions for ${selectedEdition} found. Running with default edition`);
|
|
39
49
|
return tagArgs;
|
|
40
50
|
}
|
|
41
|
-
function
|
|
51
|
+
function _processMultipleEditions2(editionsArray, tagArgs) {
|
|
42
52
|
const filteredEditions = this.editionOrder.filter(edition => !editionsArray.includes(edition));
|
|
43
|
-
const editionTags =
|
|
44
|
-
return
|
|
53
|
+
const editionTags = _classPrivateMethodGet(this, _buildEditionTags, _buildEditionTags2).call(this, filteredEditions, 'or');
|
|
54
|
+
return _classPrivateMethodGet(this, _buildTagsString, _buildTagsString2).call(this, tagArgs, editionTags);
|
|
45
55
|
}
|
|
46
|
-
function
|
|
47
|
-
const [operator, editionValue] =
|
|
56
|
+
function _getEditionArgs2(selectedEdition) {
|
|
57
|
+
const [operator, editionValue] = _classPrivateMethodGet(this, _parseEdition, _parseEdition2).call(this, selectedEdition.toLowerCase());
|
|
48
58
|
const index = this.editionOrder.findIndex(edition => edition.toLowerCase() === editionValue);
|
|
49
59
|
if (index === -1) {
|
|
50
60
|
_logger.Logger.log(_logger.Logger.INFO_TYPE, `No matching editions for ${selectedEdition} found. Running with default edition`);
|
|
@@ -63,7 +73,7 @@ function _getEditionArgs(selectedEdition) {
|
|
|
63
73
|
return this.editionOrder.filter((_, i) => i !== index);
|
|
64
74
|
}
|
|
65
75
|
}
|
|
66
|
-
function
|
|
76
|
+
function _buildEditionTags2(editionArgs, operator = 'or') {
|
|
67
77
|
return editionArgs.map(edition => `@edition_${edition}`).join(` ${operator} `);
|
|
68
78
|
}
|
|
69
79
|
module.exports = TagProcessor;
|
|
@@ -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
|
});
|