@zohodesk/testinglibrary 2.9.6 → 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 +15 -32
- package/build/core/playwright/constants/fileMutexConfig.js +3 -9
- package/build/core/playwright/helpers/auth/loginSteps.js +2 -9
- 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 +276 -255
- package/package.json +1 -2
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
var _auth = require("../helpers/auth");
|
|
9
|
-
var _getUrlOrigin = _interopRequireDefault(require("../helpers/auth/getUrlOrigin"));
|
|
10
8
|
var _readConfigFile = require("../readConfigFile");
|
|
11
9
|
/* eslint-disable global-require */
|
|
12
10
|
|
|
@@ -29,7 +27,7 @@ function getCustomAccountDetails(tags) {
|
|
|
29
27
|
const user = (0, _auth.getUserForSelectedEditionAndProfile)(editionInfo, profileInfo, betaFeature, portalInfo);
|
|
30
28
|
return user;
|
|
31
29
|
}
|
|
32
|
-
return
|
|
30
|
+
return (0, _auth.getDefaultActor)();
|
|
33
31
|
}
|
|
34
32
|
const {
|
|
35
33
|
testSetup
|
|
@@ -44,19 +42,9 @@ async function loginSteps(pageDetail) {
|
|
|
44
42
|
await page.goto(process.env.domain);
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
|
-
async function performDefaultPageSteps({
|
|
48
|
-
context,
|
|
49
|
-
$tags,
|
|
50
|
-
page
|
|
51
|
-
}) {
|
|
45
|
+
async function performDefaultPageSteps(testInfo) {
|
|
52
46
|
if (testSetup.page && typeof testSetup.page === 'function') {
|
|
53
|
-
await testSetup.page(
|
|
54
|
-
context,
|
|
55
|
-
$tags,
|
|
56
|
-
page
|
|
57
|
-
});
|
|
58
|
-
} else {
|
|
59
|
-
await page.goto(process.env.domain);
|
|
47
|
+
await testSetup.page(testInfo);
|
|
60
48
|
}
|
|
61
49
|
}
|
|
62
50
|
async function verifyPageIsLoaded(testInfo) {
|
|
@@ -70,7 +58,14 @@ var _default = exports.default = {
|
|
|
70
58
|
context,
|
|
71
59
|
$tags,
|
|
72
60
|
page
|
|
73
|
-
}, use) => {
|
|
61
|
+
}, use, testInfo) => {
|
|
62
|
+
let testPortalDetails = getCustomAccountDetails($tags);
|
|
63
|
+
let testDetails = {
|
|
64
|
+
page,
|
|
65
|
+
$tags,
|
|
66
|
+
context,
|
|
67
|
+
...testPortalDetails
|
|
68
|
+
};
|
|
74
69
|
try {
|
|
75
70
|
//This block is used to skip the login process if the @unauthenticated tag is added to the script
|
|
76
71
|
if ($tags.includes('@unauthenticated')) {
|
|
@@ -83,18 +78,10 @@ var _default = exports.default = {
|
|
|
83
78
|
if (!isAuthMode) {
|
|
84
79
|
return;
|
|
85
80
|
}
|
|
86
|
-
const
|
|
87
|
-
if (testPortalDetails) {
|
|
81
|
+
const projectName = testInfo.project.name;
|
|
82
|
+
if (testPortalDetails && projectName !== 'setup' && projectName !== 'cleanup') {
|
|
88
83
|
await context.clearCookies();
|
|
89
|
-
|
|
90
|
-
email
|
|
91
|
-
} = testPortalDetails;
|
|
92
|
-
await (0, _auth.performLoginSteps)({
|
|
93
|
-
page,
|
|
94
|
-
$tags,
|
|
95
|
-
context,
|
|
96
|
-
...testPortalDetails
|
|
97
|
-
}, async testInfo => {
|
|
84
|
+
await (0, _auth.performLoginSteps)(testDetails, async testInfo => {
|
|
98
85
|
return await verifyPageIsLoaded(testInfo);
|
|
99
86
|
}, loginSteps);
|
|
100
87
|
process.env.actorInfo = JSON.stringify(testPortalDetails);
|
|
@@ -102,11 +89,7 @@ var _default = exports.default = {
|
|
|
102
89
|
} catch (e) {
|
|
103
90
|
console.error('Error during page', e);
|
|
104
91
|
} finally {
|
|
105
|
-
await performDefaultPageSteps(
|
|
106
|
-
context,
|
|
107
|
-
$tags,
|
|
108
|
-
page
|
|
109
|
-
});
|
|
92
|
+
await performDefaultPageSteps(testDetails);
|
|
110
93
|
await use(page);
|
|
111
94
|
await context.close();
|
|
112
95
|
}
|
|
@@ -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,16 +21,13 @@ 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);
|
|
28
|
-
await page.goto(process.env.domain);
|
|
29
|
-
await Promise.race([page.waitForNavigation(), page.waitForLoadState('networkidle'), page.waitForTimeout(5000)]);
|
|
30
28
|
const isAlreadyLoggedIn = await isLoggedIn(testInfo);
|
|
31
29
|
if (!isAlreadyLoggedIn) {
|
|
32
30
|
await loginSteps(testInfo);
|
|
33
|
-
await page.goto(process.env.domain);
|
|
34
31
|
await isLoggedIn(testInfo);
|
|
35
32
|
await page.context().storageState({
|
|
36
33
|
path: authFile
|
|
@@ -39,11 +36,7 @@ async function performLoginSteps(testInfo, isLoggedIn, loginSteps) {
|
|
|
39
36
|
} catch (error) {
|
|
40
37
|
console.error(`Error during login for ${email}:`, error);
|
|
41
38
|
} finally {
|
|
42
|
-
|
|
43
|
-
await fileMutex.release();
|
|
44
|
-
} catch (releaseError) {
|
|
45
|
-
console.error(`Error releasing lock for ${email}:`, releaseError);
|
|
46
|
-
}
|
|
39
|
+
await fileMutex.release();
|
|
47
40
|
}
|
|
48
41
|
}
|
|
49
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
|
});
|