@zohodesk/testinglibrary 3.0.9 → 3.1.1
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/executionContext.js +17 -0
- package/build/core/playwright/builtInFixtures/index.js +3 -1
- package/build/core/playwright/builtInFixtures/page.js +6 -3
- 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/buildInFixtures/__tests__/executionContext.test.js +27 -0
- package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +64 -39
- package/npm-shrinkwrap.json +1149 -262
- package/package.json +2 -3
- package/unit_reports/unit-report.html +260 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _page = require("./page");
|
|
8
|
+
var _default = exports.default = {
|
|
9
|
+
executionContext: async ({
|
|
10
|
+
$tags
|
|
11
|
+
}, use) => {
|
|
12
|
+
let testPortalActorDetails = {
|
|
13
|
+
actorInfo: (0, _page.getCustomAccountDetails)($tags)
|
|
14
|
+
};
|
|
15
|
+
await use(testPortalActorDetails);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
@@ -11,6 +11,7 @@ var _cacheLayer = _interopRequireDefault(require("./cacheLayer"));
|
|
|
11
11
|
var _addTags = _interopRequireDefault(require("./addTags"));
|
|
12
12
|
var _i18N = _interopRequireDefault(require("./i18N"));
|
|
13
13
|
var _unauthenticatedPage = _interopRequireDefault(require("./unauthenticatedPage"));
|
|
14
|
+
var _executionContext = _interopRequireDefault(require("./executionContext"));
|
|
14
15
|
function extractTagsFromTitle(text) {
|
|
15
16
|
return text.match(/@\w+/g) || [];
|
|
16
17
|
}
|
|
@@ -20,7 +21,8 @@ function getBuiltInFixtures(bddMode) {
|
|
|
20
21
|
..._context.default,
|
|
21
22
|
..._cacheLayer.default,
|
|
22
23
|
..._i18N.default,
|
|
23
|
-
..._unauthenticatedPage.default
|
|
24
|
+
..._unauthenticatedPage.default,
|
|
25
|
+
..._executionContext.default
|
|
24
26
|
};
|
|
25
27
|
if (bddMode) {
|
|
26
28
|
builtInFixtures = {
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
+
exports.getCustomAccountDetails = getCustomAccountDetails;
|
|
7
8
|
var _auth = require("../helpers/auth");
|
|
8
9
|
var _readConfigFile = require("../readConfigFile");
|
|
9
10
|
/* eslint-disable global-require */
|
|
@@ -57,9 +58,10 @@ var _default = exports.default = {
|
|
|
57
58
|
page: async ({
|
|
58
59
|
context,
|
|
59
60
|
$tags,
|
|
60
|
-
page
|
|
61
|
+
page,
|
|
62
|
+
executionContext
|
|
61
63
|
}, use, testInfo) => {
|
|
62
|
-
let testPortalDetails =
|
|
64
|
+
let testPortalDetails = executionContext.actorInfo;
|
|
63
65
|
let testDetails = {
|
|
64
66
|
page,
|
|
65
67
|
$tags,
|
|
@@ -78,7 +80,8 @@ var _default = exports.default = {
|
|
|
78
80
|
if (!isAuthMode) {
|
|
79
81
|
return;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
const projectName = testInfo.project.name;
|
|
84
|
+
if (testPortalDetails && projectName !== 'setup' && projectName !== 'cleanup') {
|
|
82
85
|
await context.clearCookies();
|
|
83
86
|
await (0, _auth.performLoginSteps)(testDetails, async testInfo => {
|
|
84
87
|
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;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _page = require("../../../../../core/playwright/builtInFixtures/page");
|
|
5
|
+
var _executionContext = _interopRequireDefault(require("../../../../../core/playwright/builtInFixtures/executionContext"));
|
|
6
|
+
jest.mock('../../../../../core/playwright/builtInFixtures/page');
|
|
7
|
+
describe('executionContext', () => {
|
|
8
|
+
test('should pass actorInfo with details from getCustomAccountDetails to use', async () => {
|
|
9
|
+
const mockTags = ['tag1', 'tag2'];
|
|
10
|
+
const mockActorInfo = {
|
|
11
|
+
id: '1',
|
|
12
|
+
edition: 'enterprise',
|
|
13
|
+
orgName: 'orgName',
|
|
14
|
+
profile: 'admin',
|
|
15
|
+
email: 'xxx.x+uat@zohotest.com'
|
|
16
|
+
};
|
|
17
|
+
_page.getCustomAccountDetails.mockReturnValue(mockActorInfo);
|
|
18
|
+
const use = jest.fn();
|
|
19
|
+
await _executionContext.default.executionContext({
|
|
20
|
+
$tags: mockTags
|
|
21
|
+
}, use);
|
|
22
|
+
expect(_page.getCustomAccountDetails).toHaveBeenCalledWith(mockTags);
|
|
23
|
+
expect(use).toHaveBeenCalledWith({
|
|
24
|
+
actorInfo: mockActorInfo
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -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
|
});
|