@zohodesk/testinglibrary 0.0.3 → 0.0.4-n20-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.
Files changed (130) hide show
  1. package/.babelrc +24 -0
  2. package/.eslintrc.js +31 -0
  3. package/.gitlab-ci.yml +175 -0
  4. package/.prettierrc +6 -0
  5. package/README.md +151 -1
  6. package/bin/cli.js +1 -1
  7. package/bin/postinstall.js +1 -16
  8. package/build/common/data-generator/steps/DataGenerator.spec.js +19 -0
  9. package/build/common/data-generator/steps/DataGeneratorStepsHelper.js +19 -0
  10. package/build/common/multi-actor/steps/multiActorHandling.spec.js +26 -0
  11. package/build/common/searchFake/helpers/rpcRequestHelper.js +41 -0
  12. package/build/common/searchFake/steps/searchFake.spec.js +26 -0
  13. package/build/core/dataGenerator/DataGenerator.js +94 -0
  14. package/build/core/dataGenerator/DataGeneratorHelper.js +49 -0
  15. package/{src → build}/core/jest/preprocessor/jsPreprocessor.js +4 -6
  16. package/{src → build}/core/jest/runner/jest-runner.js +17 -15
  17. package/build/core/jest/setup/index.js +3 -0
  18. package/build/core/playwright/builtInFixtures/actorContext.js +75 -0
  19. package/build/core/playwright/builtInFixtures/addTags.js +19 -0
  20. package/build/core/playwright/builtInFixtures/cacheLayer.js +13 -0
  21. package/build/core/playwright/builtInFixtures/context.js +32 -0
  22. package/build/core/playwright/builtInFixtures/executionContext.js +17 -0
  23. package/build/core/playwright/builtInFixtures/i18N.js +41 -0
  24. package/build/core/playwright/builtInFixtures/index.js +46 -0
  25. package/build/core/playwright/builtInFixtures/page.js +38 -0
  26. package/build/core/playwright/builtInFixtures/unauthenticatedPage.js +18 -0
  27. package/build/core/playwright/clear-caches.js +49 -0
  28. package/build/core/playwright/codegen.js +55 -0
  29. package/build/core/playwright/configuration/Configuration.js +25 -0
  30. package/build/core/playwright/configuration/ConfigurationHelper.js +43 -0
  31. package/build/core/playwright/configuration/UserArgs.js +12 -0
  32. package/build/core/playwright/constants/browserTypes.js +12 -0
  33. package/build/core/playwright/constants/fileMutexConfig.js +9 -0
  34. package/build/core/playwright/custom-commands.js +7 -0
  35. package/build/core/playwright/env-initializer.js +43 -0
  36. package/build/core/playwright/fixtures.js +24 -0
  37. package/build/core/playwright/helpers/additionalProfiles.js +25 -0
  38. package/build/core/playwright/helpers/auth/accountLogin.js +21 -0
  39. package/build/core/playwright/helpers/auth/checkAuthCookies.js +41 -0
  40. package/build/core/playwright/helpers/auth/getUrlOrigin.js +13 -0
  41. package/build/core/playwright/helpers/auth/getUsers.js +118 -0
  42. package/build/core/playwright/helpers/auth/index.js +76 -0
  43. package/build/core/playwright/helpers/auth/loginDefaultStepsHelper.js +54 -0
  44. package/build/core/playwright/helpers/auth/loginSteps.js +50 -0
  45. package/build/core/playwright/helpers/checkAuthDirectory.js +27 -0
  46. package/build/core/playwright/helpers/configFileNameProvider.js +31 -0
  47. package/build/core/playwright/helpers/customFixturesHelper.js +58 -0
  48. package/build/core/playwright/helpers/fileMutex.js +71 -0
  49. package/build/core/playwright/helpers/getUserFixtures.js +23 -0
  50. package/build/core/playwright/helpers/mergeObjects.js +13 -0
  51. package/build/core/playwright/helpers/parseUserArgs.js +10 -0
  52. package/build/core/playwright/index.js +24 -0
  53. package/build/core/playwright/readConfigFile.js +147 -0
  54. package/build/core/playwright/report-generator.js +42 -0
  55. package/build/core/playwright/runner/Runner.js +22 -0
  56. package/build/core/playwright/runner/RunnerHelper.js +43 -0
  57. package/build/core/playwright/runner/RunnerTypes.js +17 -0
  58. package/build/core/playwright/runner/SpawnRunner.js +113 -0
  59. package/build/core/playwright/setup/config-creator.js +117 -0
  60. package/build/core/playwright/setup/config-utils.js +188 -0
  61. package/build/core/playwright/setup/custom-reporter.js +136 -0
  62. package/build/core/playwright/setup/qc-custom-reporter.js +291 -0
  63. package/build/core/playwright/tagProcessor.js +69 -0
  64. package/build/core/playwright/test-runner.js +116 -0
  65. package/build/core/playwright/types.js +44 -0
  66. package/build/core/playwright/validateFeature.js +28 -0
  67. package/build/decorators.d.ts +1 -0
  68. package/build/decorators.js +16 -0
  69. package/build/index.d.ts +78 -0
  70. package/build/index.js +105 -0
  71. package/build/lib/cli.js +78 -0
  72. package/build/lib/post-install.js +25 -0
  73. package/build/lint/index.js +4 -0
  74. package/build/parser/parser.js +205 -0
  75. package/build/parser/sample.feature +34 -0
  76. package/build/parser/sample.spec.js +37 -0
  77. package/build/parser/verifier.js +130 -0
  78. package/build/setup-folder-structure/helper.js +37 -0
  79. package/build/setup-folder-structure/reportEnhancement/addonScript.html +25 -0
  80. package/build/setup-folder-structure/reportEnhancement/reportAlteration.js +25 -0
  81. package/build/setup-folder-structure/samples/accountLogin-sample.js +19 -0
  82. package/build/setup-folder-structure/samples/actors-index.js +2 -0
  83. package/build/setup-folder-structure/samples/auth-setup-sample.js +15 -0
  84. package/build/setup-folder-structure/samples/editions-index.js +3 -0
  85. package/build/setup-folder-structure/samples/free-sample.json +25 -0
  86. package/build/setup-folder-structure/samples/git-ignore.sample.js +37 -0
  87. package/build/setup-folder-structure/samples/settings.json +7 -0
  88. package/build/setup-folder-structure/samples/testSetup-sample.js +14 -0
  89. package/build/setup-folder-structure/samples/uat-config-sample.js +46 -0
  90. package/build/setup-folder-structure/setupProject.js +122 -0
  91. package/build/test/core/playwright/__tests__/tagProcessor.test.js +94 -0
  92. package/build/test/core/playwright/__tests__/validateFeature.test.js +69 -0
  93. package/build/test/core/playwright/buildInFixtures/__tests__/executionContext.test.js +27 -0
  94. package/build/test/core/playwright/configuration/__tests__/Configuration.test.js +53 -0
  95. package/build/test/core/playwright/helpers/__tests__/additionalProfiles.test.js +45 -0
  96. package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +34 -0
  97. package/build/test/core/playwright/helpers/__tests__/customFixturesHelper.test.js +51 -0
  98. package/build/test/core/playwright/helpers/__tests__/fileMutex.test.js +79 -0
  99. package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +80 -0
  100. package/build/test/core/playwright/runner/__tests__/RunnerHelper.test.js +16 -0
  101. package/build/test/core/playwright/runner/__tests__/SpawnRunner.test.js +27 -0
  102. package/build/utils/cliArgsToObject.js +72 -0
  103. package/build/utils/commonUtils.js +17 -0
  104. package/build/utils/fileUtils.js +109 -0
  105. package/build/utils/getFilePath.js +11 -0
  106. package/build/utils/logger.js +28 -0
  107. package/build/utils/rootPath.js +53 -0
  108. package/build/utils/stepDefinitionsFormatter.js +11 -0
  109. package/changelog.md +153 -1
  110. package/jest.config.js +29 -11
  111. package/npm-shrinkwrap.json +10902 -4825
  112. package/package.json +47 -17
  113. package/playwright.config.js +6 -56
  114. package/test-results/.last-run.json +4 -0
  115. package/unit_reports/unit-report.html +260 -0
  116. package/src/core/jest/setup/index.js +0 -165
  117. package/src/core/playwright/codegen.js +0 -60
  118. package/src/core/playwright/custom-commands.js +0 -3
  119. package/src/core/playwright/env-initializer.js +0 -24
  120. package/src/core/playwright/index.js +0 -82
  121. package/src/core/playwright/readConfigFile.js +0 -30
  122. package/src/core/playwright/report-generator.js +0 -43
  123. package/src/core/playwright/setup/config-creator.js +0 -79
  124. package/src/core/playwright/test-runner.js +0 -64
  125. package/src/index.js +0 -9
  126. package/src/lib/cli.js +0 -35
  127. package/src/utils/cliArgsToObject.js +0 -35
  128. package/src/utils/getFilePath.js +0 -9
  129. package/src/utils/logger.js +0 -28
  130. package/src/utils/rootPath.js +0 -51
@@ -0,0 +1,46 @@
1
+ const testSetup = require('../../fixtures/testSetup');
2
+ /**
3
+ * @typedef {Object|null} viewportConfig
4
+ * @property {number} width - width of the viewport
5
+ * @property {number} height - height of the viewport
6
+ */
7
+ /**
8
+ * Represents the user configuration object.
9
+ * @typedef {Object} UserConfig
10
+ * @property {string} headless - Headless Browsers mode.
11
+ * @property {number} trace - trace for test cases.
12
+ * @property {boolean} video - video for test cases,
13
+ * @property {boolean} debug - debug mode
14
+ * @property {string} mode: mode in which the test cases needs to run
15
+ * @property {boolean} isAuthMode - Auth Mode. config whether authentication step needed before running test cases
16
+ * @property {string} authFilePath - File Path where the cookies stored
17
+ * @property {any} browsers: List of browsers
18
+ * @property {string} openReportOn: default Option value (never, on-failure and always)
19
+ * @property {any} reportPath : directory where report is generate
20
+ * @property {boolean} bddMode: Feature files needs to be processed
21
+ * @property {number} expectTimeout: time in milliseconds which the expect condition should fail
22
+ * @property {number} testTimeout: time in milliseconds which the test should fail
23
+ * @property {Object} additionalPages: custom pages configuration
24
+ * @property {string} featureFilesFolder: folder name under which feature-files will be placed. Default is feature-files
25
+ * @property {string} stepDefinitionsFolder: folder name under which step implementations will be placed. Default is steps
26
+ * @property {viewportConfig} viewport: viewport configuration for the browser. Default is { width: 1280, height: 720 }
27
+ * @property {string} testIdAttribute: Change the default data-testid attribute. configure what attribute to search while calling getByTestId
28
+ */
29
+
30
+ /**
31
+ * @type {UserConfig}
32
+ */
33
+ module.exports = {
34
+ headless: false,
35
+ browsers: ['Chrome', 'Firefox', 'Safari', 'Edge'],
36
+ mode: 'dev',
37
+ isAuthMode: true,
38
+ authFilePath: 'uat/playwright/.auth/user.json',
39
+ trace: true,
40
+ video: true,
41
+ bddMode: true,
42
+ featureFilesFolder: 'feature-files',
43
+ stepDefinitionsFolder: 'steps',
44
+ viewport: { width: 1280, height: 720 },
45
+ testSetup
46
+ }
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = setupProject;
8
+ var _fs = require("fs");
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _logger = require("../utils/logger");
11
+ function getScriptsToBeAdded() {
12
+ return {
13
+ "uat": "ZDTestingFramework test --mode=dev --headed",
14
+ "uat-debug": "ZDTestingFramework test --mode=dev --debug",
15
+ "uat-validate": "ZDTestingFramework validate",
16
+ "uat-report": "ZDTestingFramework report --port=9009",
17
+ "codegen": "ZDTestingFramework codegen deskclientapp.localzoho.com/agent"
18
+ };
19
+ }
20
+ function updatePackageJSONScripts() {
21
+ const packageJsonPath = _path.default.resolve(process.cwd(), './package.json');
22
+ if ((0, _fs.existsSync)(packageJsonPath)) {
23
+ const packageContents = (0, _fs.readFileSync)(packageJsonPath);
24
+ const configJSON = JSON.parse(packageContents);
25
+ const {
26
+ scripts = {}
27
+ } = configJSON;
28
+ const modifiedScripts = {
29
+ ...scripts,
30
+ ...getScriptsToBeAdded()
31
+ };
32
+ const modifiedConfigJSON = {
33
+ ...configJSON,
34
+ scripts: modifiedScripts
35
+ };
36
+ (0, _fs.writeFileSync)(packageJsonPath, JSON.stringify(modifiedConfigJSON, null, 2));
37
+ } else {
38
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Unable to find package json. Run init command in the root path of the project.');
39
+ }
40
+ }
41
+ function createFolderForUAT() {
42
+ const uatFolder = _path.default.resolve(process.cwd(), 'uat');
43
+ if ((0, _fs.existsSync)(uatFolder)) {
44
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Uat Folder already Exists.');
45
+ } else {
46
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Uat Folder');
47
+ (0, _fs.mkdirSync)(uatFolder);
48
+ }
49
+ }
50
+ function getSetupFileAsString(fileName) {
51
+ return (0, _fs.readFileSync)(_path.default.resolve(__dirname, './samples/', fileName)).toString();
52
+ }
53
+ function createUatConfig() {
54
+ const uatConfigPath = _path.default.resolve(process.cwd(), 'uat.config.js');
55
+ if ((0, _fs.existsSync)(uatConfigPath)) {
56
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Uat Config already Exists.');
57
+ } else {
58
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Uat config file...');
59
+ (0, _fs.writeFileSync)(uatConfigPath, getSetupFileAsString('uat-config-sample.js'), null, 2);
60
+ }
61
+ }
62
+ function createAuthenticationFile() {
63
+ const isUATexist = _path.default.resolve(process.cwd(), 'uat');
64
+ if ((0, _fs.existsSync)(isUATexist)) {
65
+ try {
66
+ if (!(0, _fs.existsSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures'))) {
67
+ (0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures'));
68
+ }
69
+ if (!(0, _fs.existsSync)(_path.default.resolve(process.cwd(), 'uat', 'playwright', '.auth'))) {
70
+ (0, _fs.mkdirSync)(_path.default.resolve(process.cwd(), 'uat', 'playwright', '.auth'), {
71
+ recursive: true
72
+ });
73
+ }
74
+ (0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'auth.setup.js'), getSetupFileAsString('auth-setup-sample.js'), null, 2);
75
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating Authentication File ....');
76
+ (0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'accountLogin.js'), getSetupFileAsString('accountLogin-sample.js'), null, 2);
77
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating login script File ....');
78
+ (0, _fs.writeFileSync)(_path.default.resolve(process.cwd(), 'uat', 'fixtures', 'testSetup.js'), getSetupFileAsString('testSetup-sample.js'), null, 2);
79
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating testSetup File ....');
80
+ } catch (err) {
81
+ _logger.Logger.error(err);
82
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Something went wrong ! Folder not Created. Please re-initialize npm init-uat');
83
+ }
84
+ } else {
85
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Something went wrong. Please re-initialize the @zohodesk/testinglibrary');
86
+ }
87
+ }
88
+ function createConfigJson() {
89
+ const uatFolder = _path.default.resolve(process.cwd(), 'uat');
90
+ if ((0, _fs.existsSync)(uatFolder)) {
91
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Creating settings.json file inside UAT Folder');
92
+ if (!(0, _fs.existsSync)(_path.default.resolve(uatFolder, 'conf', 'default'))) {
93
+ (0, _fs.mkdirSync)(_path.default.resolve(uatFolder, 'conf', 'default'), {
94
+ recursive: true
95
+ });
96
+ }
97
+ (0, _fs.writeFileSync)(_path.default.resolve(uatFolder, 'conf', 'default', './settings.json'), getSetupFileAsString('settings.json'), null, 2);
98
+ if (!(0, _fs.existsSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'editions'))) {
99
+ (0, _fs.mkdirSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'editions'), {
100
+ recursive: true
101
+ });
102
+ }
103
+ (0, _fs.writeFileSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'editions', 'free.json'), getSetupFileAsString('free-sample.json'), null, 2);
104
+ (0, _fs.writeFileSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'editions', 'index.js'), getSetupFileAsString('editions-index.js'), null, 2);
105
+ (0, _fs.writeFileSync)(_path.default.resolve(uatFolder, 'conf', 'default', 'actors', 'index.js'), getSetupFileAsString('actors-index.js'), null, 2);
106
+ } else {
107
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, 'Something went wrong. Please re-initialize the @zohodesk/testinglibrary');
108
+ }
109
+ }
110
+ function setupProject() {
111
+ updatePackageJSONScripts();
112
+ createUatConfig();
113
+ createFolderForUAT();
114
+ createConfigJson();
115
+ createAuthenticationFile();
116
+ //updateGitIgnore()
117
+ // Create folder for playwright . Inside .auth folder needs to be created. user.json
118
+ // Add playwright and test-results to .gitignore
119
+ setTimeout(() => {
120
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Setup Project is Ready ..');
121
+ }, 2000);
122
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _tagProcessor = _interopRequireDefault(require("../../../../../src/core/playwright/tagProcessor"));
5
+ var _logger = require("../../../../utils/logger");
6
+ jest.mock('../../../../utils/logger');
7
+ describe('TagProcessor', () => {
8
+ const editionOrder = ['edition1', 'edition2', 'edition3', 'edition4'];
9
+ beforeEach(() => {
10
+ jest.clearAllMocks();
11
+ });
12
+ test('should return tagArgs if no edition is provided', () => {
13
+ const tagProcessor = new _tagProcessor.default(editionOrder);
14
+ const userArgs = {
15
+ tags: 'tag1',
16
+ edition: null
17
+ };
18
+ const result = tagProcessor.processTags(userArgs);
19
+ expect(result).toBe('tag1');
20
+ });
21
+ test('should handle a single edition with <= operator', () => {
22
+ const tagProcessor = new _tagProcessor.default(editionOrder);
23
+ const userArgs = {
24
+ tags: 'tag1',
25
+ edition: '<=edition2'
26
+ };
27
+ const result = tagProcessor.processTags(userArgs);
28
+ expect(result).toBe('tag1 and not (@edition_edition3 or @edition_edition4)');
29
+ });
30
+ test('should handle a single edition with >= operator', () => {
31
+ const tagProcessor = new _tagProcessor.default(editionOrder);
32
+ const userArgs = {
33
+ tags: 'tag1',
34
+ edition: '>=edition2'
35
+ };
36
+ const result = tagProcessor.processTags(userArgs);
37
+ expect(result).toBe('tag1 and not (@edition_edition1)');
38
+ });
39
+ test('should handle a single edition with < operator', () => {
40
+ const tagProcessor = new _tagProcessor.default(editionOrder);
41
+ const userArgs = {
42
+ tags: 'tag1',
43
+ edition: '<edition3'
44
+ };
45
+ const result = tagProcessor.processTags(userArgs);
46
+ expect(result).toBe('tag1 and not (@edition_edition3 or @edition_edition4)');
47
+ });
48
+ test('should handle a single edition with > operator', () => {
49
+ const tagProcessor = new _tagProcessor.default(editionOrder);
50
+ const userArgs = {
51
+ tags: 'tag1',
52
+ edition: '>edition1'
53
+ };
54
+ const result = tagProcessor.processTags(userArgs);
55
+ expect(result).toBe('tag1 and not (@edition_edition1)');
56
+ });
57
+ test('should handle a single edition with no operator', () => {
58
+ const tagProcessor = new _tagProcessor.default(editionOrder);
59
+ const userArgs = {
60
+ tags: 'tag1',
61
+ edition: 'edition2'
62
+ };
63
+ const result = tagProcessor.processTags(userArgs);
64
+ expect(result).toBe('tag1 and not (@edition_edition1 or @edition_edition3 or @edition_edition4)');
65
+ });
66
+ test('should log a message if edition is not found', () => {
67
+ const tagProcessor = new _tagProcessor.default(editionOrder);
68
+ const userArgs = {
69
+ tags: 'tag1',
70
+ edition: 'nonexistentEdition'
71
+ };
72
+ const result = tagProcessor.processTags(userArgs);
73
+ expect(result).toBe('tag1');
74
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.INFO_TYPE, expect.stringContaining('No matching editions for nonexistentEdition found.'));
75
+ });
76
+ test('should handle multiple editions', () => {
77
+ const tagProcessor = new _tagProcessor.default(editionOrder);
78
+ const userArgs = {
79
+ tags: 'tag1',
80
+ edition: 'edition1,edition3'
81
+ };
82
+ const result = tagProcessor.processTags(userArgs);
83
+ expect(result).toBe('tag1 and not (@edition_edition2 or @edition_edition4)');
84
+ });
85
+ test('should build tags correctly when tags are empty', () => {
86
+ const tagProcessor = new _tagProcessor.default(editionOrder);
87
+ const userArgs = {
88
+ tags: '',
89
+ edition: 'edition1'
90
+ };
91
+ const result = tagProcessor.processTags(userArgs);
92
+ expect(result).toBe('not (@edition_edition2 or @edition_edition3 or @edition_edition4)');
93
+ });
94
+ });
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _validateFeature = _interopRequireDefault(require("../../../../core/playwright/validateFeature"));
5
+ var _parseUserArgs = _interopRequireDefault(require("../../../../core/playwright/helpers/parseUserArgs"));
6
+ var _readConfigFile = require("../../../../core/playwright/readConfigFile");
7
+ var _tagProcessor = _interopRequireDefault(require("../../../../core/playwright/tagProcessor"));
8
+ var _testRunner = require("../../../../core/playwright/test-runner");
9
+ var _logger = require("../../../../utils/logger");
10
+ jest.mock('../../../../core/playwright/helpers/parseUserArgs', () => ({
11
+ __esModule: true,
12
+ default: jest.fn()
13
+ }));
14
+ jest.mock('../../../../core/playwright/readConfigFile');
15
+ jest.mock('../../../../core/playwright/tagProcessor');
16
+ jest.mock('../../../../core/playwright/test-runner');
17
+ jest.mock('../../../../utils/logger', () => ({
18
+ __esModule: true,
19
+ Logger: {
20
+ log: jest.fn(),
21
+ SUCCESS_TYPE: 'success',
22
+ FAILURE_TYPE: 'failure'
23
+ }
24
+ }));
25
+ describe('validateFeatureFiles', () => {
26
+ let tagProcessorInstance;
27
+ beforeEach(() => {
28
+ jest.clearAllMocks();
29
+ tagProcessorInstance = {
30
+ processTags: jest.fn()
31
+ };
32
+ _tagProcessor.default.mockImplementation(() => tagProcessorInstance);
33
+ });
34
+ test('runPreprocessing with correct arguments and log success', async () => {
35
+ const mockUserArgs = {
36
+ mode: 'dev'
37
+ };
38
+ _parseUserArgs.default.mockReturnValue(mockUserArgs);
39
+ const mockConfig = {
40
+ editionOrder: ["beta", "enterprice"]
41
+ };
42
+ _readConfigFile.generateConfigFromFile.mockReturnValue(mockConfig);
43
+ _readConfigFile.isUserConfigFileAvailable.mockReturnValue(true);
44
+ const mockTagArgs = ['@beta_admin'];
45
+ tagProcessorInstance.processTags.mockReturnValue(mockTagArgs);
46
+ _testRunner.runPreprocessing.mockResolvedValueOnce();
47
+ await (0, _validateFeature.default)();
48
+ expect(_parseUserArgs.default).toHaveBeenCalled();
49
+ expect(_readConfigFile.generateConfigFromFile).toHaveBeenCalled();
50
+ expect(_readConfigFile.isUserConfigFileAvailable).toHaveBeenCalled();
51
+ expect(tagProcessorInstance.processTags).toHaveBeenCalledWith(mockUserArgs);
52
+ expect(_testRunner.runPreprocessing).toHaveBeenCalledWith(mockTagArgs, expect.stringContaining('config-creator.js'));
53
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.SUCCESS_TYPE, 'Feature files validated successfully.');
54
+ });
55
+ test('runPreprocessing with playwright conf', async () => {
56
+ const mockTagArgs = ['@beta_admin'];
57
+ tagProcessorInstance.processTags.mockReturnValue(mockTagArgs);
58
+ _readConfigFile.isUserConfigFileAvailable.mockReturnValue(false);
59
+ _testRunner.runPreprocessing.mockResolvedValueOnce();
60
+ await (0, _validateFeature.default)();
61
+ expect(_testRunner.runPreprocessing).toHaveBeenCalledWith(mockTagArgs, expect.stringContaining('playwright.config.js'));
62
+ });
63
+ test('error when runPreprocessing fails', async () => {
64
+ const mockError = new Error('Test error');
65
+ _testRunner.runPreprocessing.mockRejectedValueOnce(mockError);
66
+ await await (0, _validateFeature.default)();
67
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.FAILURE_TYPE, `Error while validating the feature files - ${mockError}`);
68
+ });
69
+ });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _customFixturesHelper = require("../../../../../core/playwright/helpers/customFixturesHelper");
5
+ var _executionContext = _interopRequireDefault(require("../../../../../core/playwright/builtInFixtures/executionContext"));
6
+ jest.mock('../../../../../core/playwright/helpers/customFixturesHelper');
7
+ describe('executionContext', () => {
8
+ test('should pass actorInfo with details from getCustomAccountDetails to use', async () => {
9
+ const mockTags = ['tag1', 'tag2'];
10
+ const mockMainActorInfo = {
11
+ id: '1',
12
+ edition: 'enterprise',
13
+ orgName: 'orgName',
14
+ profile: 'admin',
15
+ email: 'xxx.x+uat@zohotest.com'
16
+ };
17
+ _customFixturesHelper.getCustomAccountDetails.mockReturnValue(mockMainActorInfo);
18
+ const use = jest.fn();
19
+ await _executionContext.default.executionContext({
20
+ $tags: mockTags
21
+ }, use);
22
+ expect(_customFixturesHelper.getCustomAccountDetails).toHaveBeenCalledWith(mockTags);
23
+ expect(use).toHaveBeenCalledWith({
24
+ actorInfo: mockMainActorInfo
25
+ });
26
+ });
27
+ });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ const Configuration = require("../../../../../core/playwright/configuration/Configuration");
4
+ const {
5
+ combineConfiguration
6
+ } = require("../../../../../core/playwright/configuration/ConfigurationHelper");
7
+ jest.mock('../../../../../core/playwright/configuration/ConfigurationHelper', () => ({
8
+ combineConfiguration: jest.fn()
9
+ }));
10
+ describe('Configuration Class', () => {
11
+ let config;
12
+ let sampleData;
13
+ beforeEach(() => {
14
+ // Sample data as a JSON object
15
+ sampleData = {
16
+ headless: false,
17
+ trace: true,
18
+ video: true,
19
+ bddMode: true
20
+ };
21
+
22
+ // Initialize the Configuration instance with sample data
23
+ config = new Configuration(sampleData);
24
+ });
25
+ test('should add new key-value pair to the configuration', () => {
26
+ config.add('newKey', 'newValue');
27
+ expect(config.get('newKey')).toBe('newValue');
28
+ });
29
+ test('should combine configurations correctly using addAll', () => {
30
+ const newConfig = new Configuration({
31
+ newKey1: 'newValue1',
32
+ trace: false // existing key to test override
33
+ });
34
+ const combinedConfig = {
35
+ headless: false,
36
+ trace: false,
37
+ // trace overridden
38
+ video: true,
39
+ bddMode: true,
40
+ newKey1: 'newValue1'
41
+ };
42
+ combineConfiguration.mockReturnValue(combinedConfig);
43
+ config.addAll(newConfig);
44
+ expect(combineConfiguration).toHaveBeenCalledWith(sampleData, newConfig.getAll());
45
+ expect(config.getAll()).toEqual(combinedConfig);
46
+ });
47
+ test('should return correct value for a given key', () => {
48
+ expect(config.get('headless')).toBe(false);
49
+ expect(config.get('trace')).toBe(true);
50
+ expect(config.get('video')).toBe(true);
51
+ expect(config.get('bddMode')).toBe(true);
52
+ });
53
+ });
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ var _additionalProfiles = require("../../../../../core/playwright/helpers/additionalProfiles");
4
+ jest.mock('../../../../../core/playwright/helpers/auth/getUsers', () => ({
5
+ getUserForSelectedEditionAndProfile: jest.fn((edition, profile, betaFeature, portalInfo) => {
6
+ return {
7
+ email: 'manager.m@zohotest.com',
8
+ id: '1',
9
+ edition: edition || 'enterprise',
10
+ orgName: 'orgName',
11
+ profile: profile || 'admin',
12
+ betaFeature: betaFeature || null,
13
+ portalInfo: portalInfo || null
14
+ };
15
+ })
16
+ }));
17
+ const defaultTags = ['@profile_admin', '@edition_enterprise'];
18
+ const editionTags = ['@profile_admin', '@edition_enterprise', '@additional_profile_manager', '@additional_profile_agent'];
19
+ const editionAndPortalTags = ['@profile_admin', '@edition_enterprise', '@beta_parentchild', '@portal_clientuat2', '@additional_profile_manager'];
20
+ describe('additionalProfiles', () => {
21
+ beforeEach(() => {
22
+ jest.clearAllMocks();
23
+ });
24
+ test('should return empty object when no additional profile tags are present', () => {
25
+ const result = (0, _additionalProfiles.additionProfiles)(defaultTags);
26
+ expect(result).toEqual({});
27
+ });
28
+ test('should return additional profile actors when additional profile tags and editionInfo are present', () => {
29
+ const result = (0, _additionalProfiles.additionProfiles)(editionTags);
30
+ expect(Object.keys(result)).toEqual(['manager', 'agent']);
31
+ expect(result.manager).toHaveProperty('email');
32
+ expect(result.agent).toHaveProperty('email');
33
+ expect(result.manager.profile).toBe('manager');
34
+ expect(result.manager.betaFeature).toBe(null);
35
+ expect(result.agent.portalInfo).toBe(null);
36
+ });
37
+ test('should return additional profile actors when all actor details are present', () => {
38
+ const result = (0, _additionalProfiles.additionProfiles)(editionAndPortalTags);
39
+ expect(Object.keys(result)).toEqual(['manager']);
40
+ expect(result.manager).toHaveProperty('email');
41
+ expect(result.manager.profile).toBe('manager');
42
+ expect(result.manager.betaFeature).toBe("parentchild");
43
+ expect(result.manager.portalInfo).toBe("clientuat2");
44
+ });
45
+ });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _fs = require("fs");
5
+ var _path = _interopRequireDefault(require("path"));
6
+ var _configFileNameProvider = require("../../../../../core/playwright/helpers/configFileNameProvider");
7
+ jest.mock('fs');
8
+ jest.mock('path');
9
+ const mockCwd = '/mock/current/directory';
10
+ _path.default.resolve = jest.fn();
11
+ process.cwd = jest.fn(() => mockCwd);
12
+ describe('getUATFileName', () => {
13
+ beforeEach(() => {
14
+ jest.clearAllMocks();
15
+ });
16
+ test('return the pipeline matched config files for pipeline matched files exists', () => {
17
+ const mode = 'cd';
18
+ const mockPath = `${mockCwd}/uat/conf/${mode}/uat.config.js`;
19
+ _fs.existsSync.mockReturnValue(true);
20
+ _path.default.resolve.mockImplementation((...args) => args.join('/'));
21
+ const result = (0, _configFileNameProvider.getUATFileName)(mode);
22
+ expect(_fs.existsSync).toHaveBeenCalledWith(mockPath);
23
+ expect(result).toBe(mockPath);
24
+ });
25
+ test('return the default config files for pipeline matched files not exists', () => {
26
+ const mode = 'ci';
27
+ const defaultPath = `${mockCwd}/uat/conf/default/uat.config.js`;
28
+ _fs.existsSync.mockReturnValue(false);
29
+ _path.default.resolve.mockImplementation((...args) => args.join('/'));
30
+ const result = (0, _configFileNameProvider.getUATFileName)(mode);
31
+ expect(_fs.existsSync).toHaveBeenCalledWith(`${mockCwd}/uat/conf/${mode}/uat.config.js`);
32
+ expect(result).toBe(defaultPath);
33
+ });
34
+ });
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+
3
+ var _customFixturesHelper = require("../../../../../core/playwright/helpers/customFixturesHelper");
4
+ var _logger = require("../../../../../utils/logger");
5
+ var _getUsers = require("../../../../../core/playwright/helpers/auth/getUsers");
6
+ jest.mock('../../../../../core/playwright/helpers/auth/getUsers', () => ({
7
+ getUserForSelectedEditionAndProfile: jest.fn((edition, profile, betaFeature, portalInfo) => ({
8
+ email: 'manager.m@zohotest.com',
9
+ id: '1',
10
+ edition: edition || 'enterprise',
11
+ orgName: 'orgName',
12
+ profile: profile || 'admin',
13
+ betaFeature: betaFeature || null,
14
+ portalInfo: portalInfo || null
15
+ })),
16
+ getDefaultActor: jest.fn(() => ({
17
+ edition: 'enterprise',
18
+ profile: 'admin'
19
+ }))
20
+ }));
21
+ jest.mock('../../../../../utils/logger', () => ({
22
+ Logger: {
23
+ log: jest.fn(),
24
+ FAILURE_TYPE: 'FAILURE'
25
+ }
26
+ }));
27
+ const mockTags = ['@profile_admin', '@edition_enterprise', '@beta_feature', '@portal_clientuat'];
28
+ describe('getCustomAccountDetails', () => {
29
+ beforeEach(() => {
30
+ jest.clearAllMocks();
31
+ });
32
+ test('returns selected user when any tag info is present', () => {
33
+ const result = (0, _customFixturesHelper.getCustomAccountDetails)(mockTags);
34
+ expect(_getUsers.getUserForSelectedEditionAndProfile).toHaveBeenCalledWith('enterprise', 'admin', 'feature', 'clientuat');
35
+ expect(result).toHaveProperty('email', 'manager.m@zohotest.com');
36
+ });
37
+ test('logs and returns undefined if getCustomAccountDetails function throws', () => {
38
+ const error = new Error('failed to get user');
39
+ _getUsers.getUserForSelectedEditionAndProfile.mockImplementation(() => {
40
+ throw error;
41
+ });
42
+ const result = (0, _customFixturesHelper.getCustomAccountDetails)(mockTags);
43
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.FAILURE_TYPE, 'Error while getting accounts details:', error);
44
+ expect(result).toBeUndefined();
45
+ });
46
+ test('returns default actor when no tag info is not provided', () => {
47
+ const result = (0, _customFixturesHelper.getCustomAccountDetails)([]);
48
+ expect(_getUsers.getDefaultActor).toHaveBeenCalledTimes(1);
49
+ expect(result).toEqual((0, _getUsers.getDefaultActor)());
50
+ });
51
+ });
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _fileMutex = _interopRequireDefault(require("../../../../../core/playwright/helpers/fileMutex"));
5
+ var _path = _interopRequireDefault(require("path"));
6
+ var _fs = require("fs");
7
+ jest.mock('fs');
8
+ describe('FileMutex', () => {
9
+ const directory = '/tmp/locks';
10
+ const lockFileName = 'test-lock';
11
+ const fileDeletionTimeoutConfig = {
12
+ timeout: 1000
13
+ };
14
+ const lockFilePath = _path.default.resolve(directory, lockFileName + '.lock');
15
+ let fileMutex;
16
+ beforeEach(() => {
17
+ jest.clearAllMocks();
18
+ fileMutex = new _fileMutex.default(directory, lockFileName, fileDeletionTimeoutConfig);
19
+ });
20
+ describe('acquire', () => {
21
+ it('should create the lock file if it does not exist', async () => {
22
+ _fs.writeFileSync.mockImplementation(() => {});
23
+ await fileMutex.acquire();
24
+ expect(_fs.writeFileSync).toHaveBeenCalledWith(fileMutex.lockFilePath, 'locked');
25
+ });
26
+ it('should wait for lock file deletion if it exists', async () => {
27
+ _fs.existsSync.mockImplementation(filePath => filePath === fileMutex.lockFilePath);
28
+ _fs.watch.mockImplementation((dir, callback) => {
29
+ setTimeout(() => {
30
+ _fs.existsSync.mockImplementation(() => false);
31
+ callback('rename', fileMutex.lockFileName);
32
+ }, fileDeletionTimeoutConfig);
33
+ return {
34
+ close: jest.fn()
35
+ };
36
+ });
37
+ await fileMutex.acquire();
38
+ expect(_fs.watch).toHaveBeenCalledWith(directory, expect.any(Function));
39
+ });
40
+ it('should reject if watch timeout exceeds', async () => {
41
+ _fs.existsSync.mockImplementation(filePath => filePath === lockFilePath);
42
+ _fs.watch.mockImplementation(() => {
43
+ return {
44
+ close: jest.fn()
45
+ };
46
+ });
47
+ await expect(fileMutex.acquire()).rejects.toThrow('Watch timeout exceeded');
48
+ });
49
+ });
50
+ describe('release', () => {
51
+ it('should delete the lock file if it exists', async () => {
52
+ _fs.existsSync.mockReturnValue(true);
53
+ _fs.unlinkSync.mockImplementation(() => {});
54
+ await fileMutex.release();
55
+ expect(_fs.existsSync).toHaveBeenCalledWith(lockFilePath);
56
+ expect(_fs.unlinkSync).toHaveBeenCalledWith(lockFilePath);
57
+ });
58
+ it('should release lock by deleting lock file', async () => {
59
+ _fs.existsSync.mockReturnValue(true);
60
+ _fs.unlinkSync.mockImplementation(() => {});
61
+ await fileMutex.release();
62
+ expect(_fs.unlinkSync).toHaveBeenCalledWith(lockFilePath);
63
+ });
64
+ it('should not attempt to delete the lock file if it does not exist', async () => {
65
+ _fs.existsSync.mockReturnValue(false);
66
+ await fileMutex.release();
67
+ expect(_fs.existsSync).toHaveBeenCalledWith(lockFilePath);
68
+ expect(_fs.unlinkSync).not.toHaveBeenCalled();
69
+ });
70
+ it('should log an error if deleting the lock file fails', async () => {
71
+ const errorMessage = 'Error deleting lock file';
72
+ _fs.existsSync.mockReturnValue(true);
73
+ _fs.unlinkSync.mockImplementation(() => {
74
+ throw new Error(errorMessage);
75
+ });
76
+ await expect(fileMutex.release()).rejects.toThrow(errorMessage);
77
+ });
78
+ });
79
+ });