@zohodesk/testinglibrary 0.3.2-experimental → 0.3.4-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.
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ var _ConfigurationHelper = require("./ConfigurationHelper");
4
+ class Configuration {
5
+ properties = {};
6
+ constructor(props) {
7
+ this.properties = props;
8
+ }
9
+ add(key, value) {
10
+ this.properties[key] = value;
11
+ }
12
+ addAll(newConfig) {
13
+ this.properties = (0, _ConfigurationHelper.combineConfiguration)(this.properties, newConfig.getAll());
14
+ }
15
+ get(key) {
16
+ return this.properties[key];
17
+ }
18
+ getAll() {
19
+ return this.properties;
20
+ }
21
+ }
22
+ module.exports = Configuration;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.combineConfiguration = combineConfiguration;
8
+ exports.getApplicationConfig = getApplicationConfig;
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _logger = require("../../../utils/logger");
11
+ var _configFileNameProvider = require("../helpers/configFileNameProvider");
12
+ var _mergeObjects = require("../helpers/mergeObjects");
13
+ var _fs = require("fs");
14
+ const Configuration = require("./Configuration");
15
+ function checkForDeprecatedKeys(configKey) {
16
+ let deprecatedConfigInUatConfigFile = ['mode'];
17
+ if (deprecatedConfigInUatConfigFile.includes(configKey)) {
18
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `key ${configKey} is deprecated. Please use other options`);
19
+ }
20
+ }
21
+ function combineConfiguration(defaultConfig, userConfiguration) {
22
+ let configurationObj = {};
23
+ Object.keys(userConfiguration).forEach(configKey => {
24
+ checkForDeprecatedKeys(configKey);
25
+ let configValue = userConfiguration[configKey];
26
+ if (configValue !== null && configValue !== undefined) {
27
+ configurationObj[configKey] = configValue;
28
+ } else if (defaultConfig[configKey]) {
29
+ configurationObj[configKey] = defaultConfig[configKey];
30
+ } else {
31
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `key - ${configKey} is not yet supported in uat configuration. This will not be used while creating playwright configuration`);
32
+ }
33
+ });
34
+ return (0, _mergeObjects.mergeObjects)(defaultConfig, configurationObj);
35
+ }
36
+ function getApplicationConfig() {
37
+ let filePath = "";
38
+ try {
39
+ filePath = _path.default.resolve(process.cwd(), (0, _configFileNameProvider.getUATFileName)());
40
+ if (!(0, _fs.existsSync)(filePath)) {
41
+ throw new Error("catch error");
42
+ }
43
+ const config = require(filePath);
44
+ return config;
45
+ } catch (err) {
46
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Founded Path - ${filePath} Application config file not Exist ...`);
47
+ _logger.Logger.error(err);
48
+ return {};
49
+ }
50
+ }
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ var _cliArgsToObject = require("../../../utils/cliArgsToObject");
4
+ class UserArgs {
5
+ static parseToObject(config) {
6
+ return (0, _cliArgsToObject.cliArgsToObject)(config);
7
+ }
8
+ static parseToArgs(object) {
9
+ return (0, _cliArgsToObject.objectToCliArgs)(object);
10
+ }
11
+ }
12
+ module.exports = UserArgs;
@@ -3,9 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.parseUserArgs = parseUserArgs;
7
7
  var _cliArgsToObject = require("../../../utils/cliArgsToObject");
8
8
  function parseUserArgs() {
9
9
  return (0, _cliArgsToObject.cliArgsToObject)(process.argv.slice(2));
10
- }
11
- var _default = exports.default = parseUserArgs;
10
+ }
@@ -5,13 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.generateConfigFromFile = generateConfigFromFile;
8
+ exports.getApplicationConfig = getApplicationConfig;
8
9
  exports.getAuthFilePath = getAuthFilePath;
10
+ exports.getDefaultConfig = getDefaultConfig;
9
11
  exports.isUserConfigFileAvailable = isUserConfigFileAvailable;
10
12
  var _fs = require("fs");
11
13
  var _path = _interopRequireDefault(require("path"));
12
14
  var _logger = require("../../utils/logger");
13
15
  var _configFileNameProvider = require("./helpers/configFileNameProvider");
14
16
  var _mergeObjects = require("./helpers/mergeObjects");
17
+ var _Configuration = require("./configuration/Configuration");
15
18
  let cachedConfig = null;
16
19
  function getDefaultConfig() {
17
20
  return {
@@ -124,6 +127,14 @@ function generateConfigFromFile() {
124
127
  }
125
128
  return {};
126
129
  }
130
+ function getApplicationConfig() {
131
+ const filePath = _path.default.resolve(process.cwd(), (0, _configFileNameProvider.getUATFileName)());
132
+ if ((0, _fs.existsSync)(filePath)) {
133
+ const config = require(filePath);
134
+ return config;
135
+ }
136
+ return {};
137
+ }
127
138
  function isUserConfigFileAvailable() {
128
139
  const filePath = _path.default.resolve(process.cwd(), (0, _configFileNameProvider.getUATFileName)());
129
140
  if ((0, _fs.existsSync)(filePath)) {
@@ -16,7 +16,9 @@ var _rootPath = require("../../utils/rootPath");
16
16
  var _tagProcessor = require("./tag-processor");
17
17
  var _configUtils = require("./setup/config-utils");
18
18
  var _browserTypes = require("./constants/browserTypes");
19
- var _parseUserArgs = _interopRequireDefault(require("./helpers/parseUserArgs"));
19
+ var _ConfigurationHelper = require("./configuration/ConfigurationHelper");
20
+ var _Configuration = _interopRequireDefault(require("./configuration/Configuration"));
21
+ var _UserArgs = _interopRequireDefault(require("./configuration/UserArgs"));
20
22
  function getPlaywrightArgs(userArgsObject, debug, bddMode, tagArgs, headless) {
21
23
  const {
22
24
  browsers = null
@@ -97,17 +99,30 @@ function runPlaywright(command, args) {
97
99
  });
98
100
  }
99
101
  function main() {
100
- const userArgsObject = (0, _parseUserArgs.default)();
101
- const uatConfig = (0, _readConfigFile.generateConfigFromFile)();
102
+ // Getting the default config's from framework
103
+ const uatConfig = new _Configuration.default((0, _readConfigFile.getDefaultConfig)());
104
+
105
+ // overriding the application config's from project
106
+ uatConfig.addAll(new _Configuration.default((0, _ConfigurationHelper.getApplicationConfig)()));
107
+ const {
108
+ isAuthMode,
109
+ mode,
110
+ editionOrder
111
+ } = uatConfig.getAll();
112
+ (0, _envInitializer.initializeEnvConfig)(mode, isAuthMode);
113
+
114
+ // overriding the user config's from CLI
115
+ const userArgConfig = new _Configuration.default(_UserArgs.default.parseToObject(process.argv.slice(2)));
116
+ uatConfig.addAll(userArgConfig);
117
+
118
+ //This is only used for pass the user arguments to need places in legacy code. We need to rewamp that also.
119
+ const userArgsObject = userArgConfig.getAll();
120
+ const tagArgs = (0, _tagProcessor.tagProcessor)(userArgsObject, editionOrder);
102
121
  const {
103
122
  debug,
104
123
  bddMode = false,
105
- headless = false,
106
- editionOrder,
107
- isAuthMode
108
- } = uatConfig;
109
- (0, _envInitializer.initializeEnvConfig)(userArgsObject.mode, isAuthMode);
110
- const tagArgs = (0, _tagProcessor.tagProcessor)(userArgsObject, editionOrder);
124
+ headless = false
125
+ } = uatConfig.getAll();
111
126
  const playwrightArgs = getPlaywrightArgs(userArgsObject, debug, bddMode, tagArgs, headless);
112
127
  const playwrightPath = _path.default.resolve((0, _rootPath.getExecutableBinaryPath)('playwright'));
113
128
  const command = playwrightPath;
@@ -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
+ });
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.3.2-experimental",
3
+ "version": "0.2.7",
4
4
  "lockfileVersion": 1,
5
5
  "requires": true,
6
6
  "dependencies": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.3.2-experimental",
3
+ "version": "0.3.4-experimental",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {