@zohodesk/testinglibrary 0.4.98-n18-experimental → 0.4.99-n18-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.
package/.gitlab-ci.yml CHANGED
@@ -188,19 +188,19 @@ uat-data_generator:
188
188
  paths:
189
189
  - examples/uat/playwright-report
190
190
 
191
- uat-search_indexing:
192
- stage: uat
193
- script:
194
- - cd examples
195
- - npm install $(npm pack ../../testing-framework | tail -1)
196
- - output=$(npm run uat-search_indexing)
197
- - echo "$output"
198
- - node ../ValidateUATReport.js examples
199
-
200
- artifacts:
201
- when: always
202
- paths:
203
- - examples/uat/playwright-report
191
+ # uat-search_indexing:
192
+ # stage: uat
193
+ # script:
194
+ # - cd examples
195
+ # - npm install $(npm pack ../../testing-framework | tail -1)
196
+ # - output=$(npm run uat-search_indexing)
197
+ # - echo "$output"
198
+ # - node ../ValidateUATReport.js examples
199
+
200
+ # artifacts:
201
+ # when: always
202
+ # paths:
203
+ # - examples/uat/playwright-report
204
204
 
205
205
 
206
206
 
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UAT_CONFIG_FILE = exports.TEST_SUMMARY_FILE = exports.STAGE_CONFIG_MAP_FILE = exports.SETTINGS_FILE = exports.INDEX_FILE = exports.DEFAULT_CONFIG_DIR = exports.BETA_DIR = exports.ACTOR_DIR = void 0;
7
+ const DEFAULT_CONFIG_DIR = exports.DEFAULT_CONFIG_DIR = 'default';
8
+ const BETA_DIR = exports.BETA_DIR = 'beta';
9
+ const ACTOR_DIR = exports.ACTOR_DIR = 'actors';
10
+ const UAT_CONFIG_FILE = exports.UAT_CONFIG_FILE = 'uat.config.js';
11
+ const INDEX_FILE = exports.INDEX_FILE = 'index.js';
12
+ const SETTINGS_FILE = exports.SETTINGS_FILE = 'settings.json';
13
+ const TEST_SUMMARY_FILE = exports.TEST_SUMMARY_FILE = 'test-summary.json';
14
+ const STAGE_CONFIG_MAP_FILE = exports.STAGE_CONFIG_MAP_FILE = 'uat/conf-path-map.properties';
@@ -21,17 +21,13 @@ function addHelperLogsForEnvInitialization() {
21
21
  _logger.Logger.log(_logger.Logger.INFO_TYPE, `Going to use default mode as dev`);
22
22
  }
23
23
  function initializeEnvConfig(stage, mode, isAuthMode) {
24
+ if (!mode) {
25
+ addHelperLogsForEnvInitialization();
26
+ mode = 'dev';
27
+ }
28
+ const configFilePath = (0, _fs.readFileSync)(_path.default.resolve(process.cwd(), `./${(0, _configFileNameProvider.getEnvConfigFilePath)(stage, mode)}`));
24
29
  try {
25
- if (!mode) {
26
- addHelperLogsForEnvInitialization();
27
- mode = 'dev';
28
- }
29
- if (!stage) {
30
- stage = 'uat';
31
- _logger.Logger.log(_logger.Logger.INFO_TYPE, `No stage specified. Using default stage as 'uat'`);
32
- }
33
- const configFile = (0, _fs.readFileSync)(_path.default.resolve(process.cwd(), `./${(0, _configFileNameProvider.getEnvConfigFilePath)(stage, mode)}`));
34
- const configJSON = JSON.parse(configFile);
30
+ const configJSON = JSON.parse(configFilePath);
35
31
  setEnvironmentVariables({
36
32
  ...configJSON,
37
33
  stage,
@@ -43,6 +39,6 @@ function initializeEnvConfig(stage, mode, isAuthMode) {
43
39
  }
44
40
  } catch (err) {
45
41
  _logger.Logger.error(err);
46
- throw new Error(`Config File Not Exists. Please provide a config file to initialize the environment variables`);
42
+ throw new Error(`Config File Not Exists. Please provide a ${configFilePath} to initialize the environment variables`);
47
43
  }
48
44
  }
@@ -13,8 +13,9 @@ exports.isCI = isCI;
13
13
  exports.isDevelopmentSetup = isDevelopmentSetup;
14
14
  var _path = _interopRequireDefault(require("path"));
15
15
  var _fs = require("fs");
16
- var _resolveStageConfigPath = require("./../resolveStageConfigPath");
16
+ var _configPathResolver = require("../configPathResolver");
17
17
  var _ConfigurationHelper = require("./../../configuration/ConfigurationHelper");
18
+ var _configFiles = require("../../constants/configFiles");
18
19
  /* eslint-disable global-require */
19
20
  function getRunMode() {
20
21
  let {
@@ -32,12 +33,12 @@ function isDevelopmentSetup() {
32
33
  }
33
34
  function getDefaultActorConf() {
34
35
  const stage = (0, _ConfigurationHelper.getRunStage)();
35
- const stageConfig = (0, _resolveStageConfigPath.resolveStageConfigPath)(stage);
36
- const modeSettingsFile = `${stageConfig}/${getRunMode()}/settings.json`;
36
+ const stagePath = (0, _configPathResolver.getConfigPath)(stage);
37
+ const modeSettingsFile = `${stagePath}/${getRunMode()}/${_configFiles.SETTINGS_FILE}`;
37
38
  const filePath = _path.default.join(_path.default.resolve(process.cwd(), modeSettingsFile));
38
39
  try {
39
40
  if (!(0, _fs.existsSync)(filePath)) {
40
- const defaultSettingsFile = _path.default.join(_path.default.resolve(process.cwd(), `${stage}/conf/default/settings.json`));
41
+ const defaultSettingsFile = _path.default.join(_path.default.resolve(process.cwd(), `${stagePath}/${_configFiles.DEFAULT_CONFIG_DIR}/${_configFiles.SETTINGS_FILE}`));
41
42
  return require(defaultSettingsFile);
42
43
  }
43
44
  return require(filePath);
@@ -55,15 +56,15 @@ function getDefaultActor() {
55
56
  function getListOfActors(betaFeature) {
56
57
  const mode = getRunMode();
57
58
  const stage = (0, _ConfigurationHelper.getRunStage)();
58
- const stageConfig = (0, _resolveStageConfigPath.resolveStageConfigPath)(stage);
59
- let configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stageConfig}/${mode}/actors/index.js`));
59
+ const stagePath = (0, _configPathResolver.getConfigPath)(stage);
60
+ let configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stagePath}/${mode}/${_configFiles.ACTOR_DIR}/${_configFiles.INDEX_FILE}`));
60
61
  let betaReference = mode;
61
62
  if (!(0, _fs.existsSync)(configFile)) {
62
- configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stage}/conf/default/actors/index.js`));
63
+ configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stagePath}/${_configFiles.DEFAULT_CONFIG_DIR}/${_configFiles.ACTOR_DIR}/${_configFiles.INDEX_FILE}`));
63
64
  betaReference = "default";
64
65
  }
65
66
  if (betaFeature) {
66
- configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stageConfig}/${betaReference}/actors/beta/${betaFeature}/index.js`));
67
+ configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stagePath}/${betaReference}/${_configFiles.ACTOR_DIR}/${_configFiles.BETA_DIR}/${betaFeature}/${_configFiles.INDEX_FILE}`));
67
68
  if (!(0, _fs.existsSync)(configFile)) {
68
69
  throw new Error(`There is no beta feature configured with the name "${betaFeature}"`);
69
70
  }
@@ -11,27 +11,28 @@ var _path = _interopRequireDefault(require("path"));
11
11
  var _fs = _interopRequireDefault(require("fs"));
12
12
  var _auth = require("./auth");
13
13
  var _ConfigurationHelper = require("./../configuration/ConfigurationHelper");
14
- var _resolveStageConfigPath = require("./resolveStageConfigPath");
14
+ var _configPathResolver = require("./configPathResolver");
15
+ var _configFiles = require("../constants/configFiles");
15
16
  function getUATFileName(stage, mode) {
16
17
  stage = stage || (0, _ConfigurationHelper.getRunStage)();
17
18
  mode = mode || (0, _auth.getRunMode)();
18
- const stageConfig = (0, _resolveStageConfigPath.resolveStageConfigPath)(stage);
19
- const uatConfFilePath = _path.default.resolve(process.cwd(), `${stageConfig}/${mode}/uat.config.js`);
19
+ const stagePath = (0, _configPathResolver.getConfigPath)(stage);
20
+ const uatConfFilePath = _path.default.resolve(process.cwd(), `${stagePath}/${mode}/${_configFiles.UAT_CONFIG_FILE}`);
20
21
  if (_fs.default.existsSync(uatConfFilePath)) {
21
22
  return uatConfFilePath;
22
23
  }
23
24
  ;
24
- return _path.default.resolve(process.cwd(), `${stage}/conf/default/uat.config.js`);
25
+ return _path.default.resolve(process.cwd(), `${stagePath}/${_configFiles.DEFAULT_CONFIG_DIR}/${_configFiles.UAT_CONFIG_FILE}`);
25
26
  }
26
27
  function getEnvConfigFilePath(stage, mode) {
27
- const stageConfig = (0, _resolveStageConfigPath.resolveStageConfigPath)(stage);
28
- const confFilePath = `${stageConfig}/${mode}/settings.json`;
28
+ const stagePath = (0, _configPathResolver.getConfigPath)(stage);
29
+ const confFilePath = `${stagePath}/${mode}/${_configFiles.SETTINGS_FILE}`;
29
30
  // TODO: Actors Mode as config
30
31
  if (_fs.default.existsSync(confFilePath)) {
31
32
  return confFilePath;
32
33
  }
33
- return `${stage}/conf/default/settings.json`;
34
+ return `${stagePath}/${_configFiles.DEFAULT_CONFIG_DIR}/${_configFiles.SETTINGS_FILE}`;
34
35
  }
35
36
  function getReportFileName() {
36
- return `test-summary.json`;
37
+ return `${_configFiles.TEST_SUMMARY_FILE}`;
37
38
  }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getConfigPath = getConfigPath;
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _propertiesReader = _interopRequireDefault(require("properties-reader"));
11
+ var _logger = require("../../../utils/logger");
12
+ var _configFiles = require("../constants/configFiles");
13
+ //This function reads a properties file and returns the entire properties
14
+
15
+ function readPropertiesFile(relativeFilePath) {
16
+ const filePath = _path.default.resolve(process.cwd(), relativeFilePath);
17
+ if (!_fs.default.existsSync(filePath)) {
18
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Properties file ${filePath} not found at path. Using default configurations.`);
19
+ return {
20
+ get: () => 'uat/conf'
21
+ };
22
+ }
23
+ const properties = (0, _propertiesReader.default)(filePath);
24
+ return properties;
25
+ }
26
+
27
+ // This function return the value for the passed arguments key
28
+
29
+ function getConfigPath(stage) {
30
+ const props = readPropertiesFile(_configFiles.STAGE_CONFIG_MAP_FILE);
31
+ const configPath = props.get(stage);
32
+ if (!configPath) {
33
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `No config mapping found for stage: "${stage}"`);
34
+ }
35
+ return configPath;
36
+ }
@@ -4,13 +4,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  var _fs = require("fs");
5
5
  var _path = _interopRequireDefault(require("path"));
6
6
  var _configFileNameProvider = require("../../../../../core/playwright/helpers/configFileNameProvider");
7
- var _resolveStageConfigPath = require("../../../../../core/playwright/helpers/resolveStageConfigPath");
7
+ var _configPathResolver = require("../../../../../core/playwright/helpers/configPathResolver");
8
8
  jest.mock('fs');
9
9
  jest.mock('path', () => ({
10
10
  resolve: jest.fn()
11
11
  }));
12
- jest.mock("../../../../../core/playwright/helpers/resolveStageConfigPath", () => ({
13
- resolveStageConfigPath: jest.fn()
12
+ jest.mock("../../../../../core/playwright/helpers/configPathResolver", () => ({
13
+ getConfigPath: jest.fn()
14
14
  }));
15
15
  const mockCwd = '/mock/current/directory';
16
16
  _path.default.resolve = jest.fn();
@@ -23,11 +23,11 @@ describe('getUATFileName', () => {
23
23
  test('should return pipeline-matched config path when file exists', () => {
24
24
  const stage = 'uat';
25
25
  const mode = 'cd';
26
- _resolveStageConfigPath.resolveStageConfigPath.mockReturnValue(`${stage}/conf`);
26
+ _configPathResolver.getConfigPath.mockReturnValue(`${stage}/conf`);
27
27
  _fs.existsSync.mockReturnValue(true);
28
28
  const expected = `${process.cwd()}/${stage}/conf/${mode}/uat.config.js`;
29
29
  const result = (0, _configFileNameProvider.getUATFileName)(stage, mode);
30
- expect(_resolveStageConfigPath.resolveStageConfigPath).toHaveBeenCalledWith(stage);
30
+ expect(_configPathResolver.getConfigPath).toHaveBeenCalledWith(stage);
31
31
  expect(_fs.existsSync).toHaveBeenCalledWith(expected);
32
32
  expect(result).toBe(expected);
33
33
  });
@@ -46,7 +46,7 @@ describe('getUATFileName', () => {
46
46
  const stageConfigPath = 'uat/conf';
47
47
  const nonExistingPath = `${mockCwd}/${stageConfigPath}/${mockMode}/uat.config.js`;
48
48
  const expectedDefaultPath = `${mockCwd}/${mockStage}/conf/default/uat.config.js`;
49
- _resolveStageConfigPath.resolveStageConfigPath.mockReturnValue(stageConfigPath);
49
+ _configPathResolver.getConfigPath.mockReturnValue(stageConfigPath);
50
50
  _fs.existsSync.mockReturnValue(false);
51
51
  const result = (0, _configFileNameProvider.getUATFileName)(mockStage, mockMode);
52
52
  expect(_fs.existsSync).toHaveBeenCalledWith(nonExistingPath);
@@ -59,15 +59,15 @@ describe('getEnvConfigFilePath', () => {
59
59
  _path.default.resolve.mockImplementation((...segments) => segments.join('/'));
60
60
  });
61
61
  test('should return conf file path when file exists', () => {
62
- _resolveStageConfigPath.resolveStageConfigPath.mockReturnValue('uat/conf');
62
+ _configPathResolver.getConfigPath.mockReturnValue('uat/conf');
63
63
  _fs.existsSync.mockReturnValue(true);
64
64
  const result = (0, _configFileNameProvider.getEnvConfigFilePath)('uat', 'cd');
65
- expect(_resolveStageConfigPath.resolveStageConfigPath).toHaveBeenCalledWith('uat');
65
+ expect(_configPathResolver.getConfigPath).toHaveBeenCalledWith('uat');
66
66
  expect(_fs.existsSync).toHaveBeenCalled();
67
67
  expect(result).toBe('uat/conf/cd/settings.json');
68
68
  });
69
69
  test('should return default path when file does not exist', () => {
70
- _resolveStageConfigPath.resolveStageConfigPath.mockReturnValue('uat/conf');
70
+ _configPathResolver.getConfigPath.mockReturnValue('uat/conf');
71
71
  _fs.existsSync.mockReturnValue(false);
72
72
  const result = (0, _configFileNameProvider.getEnvConfigFilePath)('uat', 'ci');
73
73
  expect(result).toBe('uat/conf/default/settings.json');
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _fs = _interopRequireDefault(require("fs"));
5
+ var _propertiesReader = _interopRequireDefault(require("properties-reader"));
6
+ var _configPathResolver = require("../../../../../core/playwright/helpers/configPathResolver");
7
+ var _logger = require("../../../../../utils/logger");
8
+ jest.mock('../../../../../utils/logger', () => ({
9
+ Logger: {
10
+ log: jest.fn(),
11
+ FAILURE_TYPE: 'FAILURE'
12
+ }
13
+ }));
14
+ jest.mock('fs');
15
+ jest.mock('path');
16
+ jest.mock('properties-reader');
17
+ describe('getConfigPath', () => {
18
+ beforeEach(() => {
19
+ jest.clearAllMocks();
20
+ });
21
+ test('should return correct stageConfig when mapping exists', () => {
22
+ const mockProps = {
23
+ get: jest.fn(() => 'uat/conf')
24
+ };
25
+ _propertiesReader.default.mockReturnValue(mockProps);
26
+ _fs.default.existsSync.mockReturnValue(true);
27
+ const result = (0, _configPathResolver.getConfigPath)('uat');
28
+ expect(mockProps.get).toHaveBeenCalledWith('uat');
29
+ expect(result).toBe('uat/conf');
30
+ expect(_logger.Logger.log).not.toHaveBeenCalled();
31
+ });
32
+ test('should log failure when stage mapping does not exist', () => {
33
+ const mockProps = {
34
+ get: jest.fn(() => undefined)
35
+ };
36
+ _propertiesReader.default.mockReturnValue(mockProps);
37
+ _fs.default.existsSync.mockReturnValue(true);
38
+ const result = (0, _configPathResolver.getConfigPath)('invalidStage');
39
+ expect(result).toEqual(undefined);
40
+ expect(_logger.Logger.log).toHaveBeenCalledWith('FAILURE', 'No config mapping found for stage: "invalidStage"');
41
+ });
42
+ });
@@ -4,11 +4,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  var _fs = _interopRequireDefault(require("fs"));
5
5
  var _path = _interopRequireDefault(require("path"));
6
6
  var _getUsers = require("../../../../../core/playwright/helpers/auth/getUsers");
7
- var _resolveStageConfigPath = require("../../../../../core/playwright/helpers/resolveStageConfigPath");
7
+ var _configPathResolver = require("../../../../../core/playwright/helpers/configPathResolver");
8
8
  jest.mock('fs');
9
9
  jest.mock('path');
10
- jest.mock('../../../../../core/playwright/helpers/resolveStageConfigPath', () => ({
11
- resolveStageConfigPath: jest.fn()
10
+ jest.mock('../../../../../core/playwright/helpers/configPathResolver', () => ({
11
+ getConfigPath: jest.fn()
12
12
  }));
13
13
  describe('getListOfActors', () => {
14
14
  const stageConfig = 'uat/conf';
@@ -18,7 +18,7 @@ describe('getListOfActors', () => {
18
18
  jest.clearAllMocks();
19
19
  _path.default.join.mockImplementation((...args) => args.join('/'));
20
20
  _path.default.resolve.mockImplementation((...args) => args.join('/'));
21
- _resolveStageConfigPath.resolveStageConfigPath.mockReturnValue('uat/conf');
21
+ _configPathResolver.getConfigPath.mockReturnValue('uat/conf');
22
22
  });
23
23
  test('throws an error when config file cannot be loaded', () => {
24
24
  _fs.default.existsSync.mockReturnValueOnce(true);