@zohodesk/testinglibrary 3.2.14 → 3.2.16

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/README.md CHANGED
@@ -17,20 +17,41 @@
17
17
 
18
18
  - npm run report
19
19
 
20
- ### v3.2.11 - 13-10-2025
21
-
22
- ### Feature
20
+ ### v4.0.0 - 04-12-2025
21
+
22
+ #### Features
23
23
 
24
- - New step a search entity using {string} provided for search indexing, This step will use run time data generation response as input for the indexing
24
+ - Supported node 20 for the testing-framework
25
+
26
+ - Below package versions are updated in this release.
27
+ - playwright - 1.56.1,
28
+ - playwright-bdd - 8.4.2,
29
+ - @playwright/test - 1.56.1,
30
+ - @cucumber/cucumber - 12.2.0
31
+
32
+ ### v3.2.15 - 14-11-2025
33
+
34
+ #### Enhancement
35
+
36
+ - Aborted test results are now merged into the `.last-run.json` file.
37
+ This ensures that any timed-out tests are included in the next retry cycle.
38
+
39
+ ### v3.2.13 - 30-10-2025
25
40
 
41
+ #### Enhancement
42
+
43
+ - A teardown option has been introduced in the configuration to manage and clean up login sessions stored in the NFS environment.
44
+
26
45
  ### Issue fix
46
+
27
47
  - Custom teardown comment provided
48
+
49
+ ### v3.2.11 - 13-10-2025
28
50
 
29
- ### v3.2.10 - 09-10-2025
51
+ ### Feature
52
+
53
+ - New step a search entity using {string} provided for search indexing, This step will use run time data generation response as input for the indexing
30
54
 
31
- #### Enhancement
32
- - A teardown option has been introduced in the configuration to manage and clean up login sessions stored in the NFS environment.
33
-
34
55
 
35
56
  ### v3.2.9 - 26-09-2025
36
57
 
@@ -60,6 +81,7 @@
60
81
  - Multi-actor execution support – now possible to switch between multiple profile agents within scenarios using the predefined step: - `access the {string} profile page`
61
82
 
62
83
  ### Bug fix
84
+
63
85
  - Fixed the issue where localapp and hcapp UAT were not running properly.
64
86
 
65
87
  ### v3.2.5 - 28-08-2025
@@ -1,17 +1,15 @@
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.combineConfiguration = combineConfiguration;
8
7
  exports.getApplicationConfig = getApplicationConfig;
9
- var _path = _interopRequireDefault(require("path"));
8
+ exports.getRunStage = getRunStage;
10
9
  var _logger = require("../../../utils/logger");
11
10
  var _configFileNameProvider = require("../helpers/configFileNameProvider");
12
11
  var _mergeObjects = require("../helpers/mergeObjects");
13
12
  var _fs = require("fs");
14
- const Configuration = require("./Configuration");
15
13
  function combineConfiguration(defaultConfig, userConfiguration) {
16
14
  let configurationObj = {};
17
15
  Object.keys(userConfiguration).forEach(configKey => {
@@ -26,10 +24,10 @@ function combineConfiguration(defaultConfig, userConfiguration) {
26
24
  });
27
25
  return (0, _mergeObjects.mergeObjects)(defaultConfig, configurationObj);
28
26
  }
29
- function getApplicationConfig(mode) {
27
+ function getApplicationConfig(stage, mode) {
30
28
  let filePath = "";
31
29
  try {
32
- filePath = _path.default.resolve(process.cwd(), (0, _configFileNameProvider.getUATFileName)(mode));
30
+ filePath = (0, _configFileNameProvider.getUATFileName)(stage, mode);
33
31
  if (!(0, _fs.existsSync)(filePath)) {
34
32
  throw new Error("Exception while getting the uat file from the application - " + filePath);
35
33
  }
@@ -40,4 +38,8 @@ function getApplicationConfig(mode) {
40
38
  _logger.Logger.error(err);
41
39
  return {};
42
40
  }
41
+ }
42
+ function getRunStage() {
43
+ const stage = process.env.stage;
44
+ return stage || 'uat';
43
45
  }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ class configConstants {
8
+ static DEFAULT_CONFIG_DIR = 'default';
9
+ static BETA_DIR = 'beta';
10
+ static ACTOR_DIR = 'actors';
11
+ static UAT_CONFIG_FILE = 'uat.config.js';
12
+ static INDEX_FILE = 'index.js';
13
+ static SETTINGS_FILE = 'settings.json';
14
+ static TEST_SUMMARY_FILE = 'test-summary.json';
15
+ static STAGE_CONFIG_MAP_FILE = 'uat/conf_path_map.properties';
16
+ }
17
+ exports.default = configConstants;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ class ReporterConstants {
8
+ static DEFAULT_REPORTER_PATH = 'uat/test-results/playwright-test-results.json';
9
+ static LAST_RUN_REPORTER_PATH = 'uat/test-results/.last-run.json';
10
+ }
11
+ exports.default = ReporterConstants;
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CUSTOM_COMMANDS = void 0;
7
- const CUSTOM_COMMANDS = exports.CUSTOM_COMMANDS = ['mode', 'tags', 'edition', 'browsers', 'filePath', 'headless', 'modules', 'isTearDown'];
7
+ const CUSTOM_COMMANDS = exports.CUSTOM_COMMANDS = ['stage', 'mode', 'tags', 'edition', 'browsers', 'filePath', 'headless', 'modules', 'isTearDown'];
@@ -17,19 +17,20 @@ function setEnvironmentVariables(configJSON) {
17
17
  }
18
18
  function addHelperLogsForEnvInitialization() {
19
19
  _logger.Logger.log(_logger.Logger.INFO_TYPE, `Mode under which test cases should run has not been specified in args.`);
20
- _logger.Logger.log(_logger.Logger.INFO_TYPE, `Please specify --mode='dev/prod' while running ZDTestingFramework test`);
20
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Please specify --mode='dev/ci/cd/devautomation' while running ZDTestingFramework test`);
21
21
  _logger.Logger.log(_logger.Logger.INFO_TYPE, `Going to use default mode as dev`);
22
22
  }
23
- function initializeEnvConfig(mode, isAuthMode) {
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
- const configFile = (0, _fs.readFileSync)(_path.default.resolve(process.cwd(), `./${(0, _configFileNameProvider.getEnvConfigFilePath)(mode)}`));
30
- const configJSON = JSON.parse(configFile);
30
+ const configJSON = JSON.parse(configFilePath);
31
31
  setEnvironmentVariables({
32
32
  ...configJSON,
33
+ stage,
33
34
  mode
34
35
  });
35
36
  if (isAuthMode) {
@@ -38,6 +39,6 @@ function initializeEnvConfig(mode, isAuthMode) {
38
39
  }
39
40
  } catch (err) {
40
41
  _logger.Logger.error(err);
41
- throw new Error(`Config File Not Exists. Please provide a config file ${(0, _configFileNameProvider.getEnvConfigFilePath)(mode)} to intiailize the environment variables `);
42
+ throw new Error(`Config File Not Exists. Please provide a ${configFilePath} to initialize the environment variables`);
42
43
  }
43
44
  }
@@ -13,7 +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 _readConfigFile = require("../../readConfigFile");
16
+ var _configPathResolver = require("../configPathResolver");
17
+ var _ConfigurationHelper = require("./../../configuration/ConfigurationHelper");
18
+ var _configConstants = _interopRequireDefault(require("../../constants/configConstants"));
17
19
  /* eslint-disable global-require */
18
20
  function getRunMode() {
19
21
  let {
@@ -30,19 +32,18 @@ function isDevelopmentSetup() {
30
32
  return mode === 'DEV' || mode === 'dev';
31
33
  }
32
34
  function getDefaultActorConf() {
33
- const {
34
- uatDirectory
35
- } = (0, _readConfigFile.generateConfigFromFile)();
36
- const modeSettingsFile = `conf/${getRunMode()}/settings.json`;
37
- const filePath = _path.default.join(uatDirectory, modeSettingsFile);
35
+ const stage = (0, _ConfigurationHelper.getRunStage)();
36
+ const stagePath = (0, _configPathResolver.getConfigPath)(stage);
37
+ const modeSettingsFile = `${stagePath}/${getRunMode()}/${_configConstants.default.SETTINGS_FILE}`;
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(uatDirectory, `conf/default/settings.json`);
41
+ const defaultSettingsFile = _path.default.join(_path.default.resolve(process.cwd(), `${stagePath}/${_configConstants.default.DEFAULT_CONFIG_DIR}/${_configConstants.default.SETTINGS_FILE}`));
41
42
  return require(defaultSettingsFile);
42
43
  }
43
44
  return require(filePath);
44
45
  } catch (error) {
45
- throw new Error(`${defaultSettingFile} ${filePath} both files are missing.`);
46
+ throw new Error(`${filePath} file missing.`);
46
47
  }
47
48
  }
48
49
  function getDefaultActor() {
@@ -53,18 +54,17 @@ function getDefaultActor() {
53
54
  return getUserForSelectedEditionAndProfile(edition, profile);
54
55
  }
55
56
  function getListOfActors(betaFeature) {
56
- const {
57
- uatDirectory
58
- } = (0, _readConfigFile.generateConfigFromFile)();
59
57
  const mode = getRunMode();
60
- let configFile = _path.default.join(uatDirectory, `conf/${mode}/actors/index.js`);
58
+ const stage = (0, _ConfigurationHelper.getRunStage)();
59
+ const stagePath = (0, _configPathResolver.getConfigPath)(stage);
60
+ let configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stagePath}/${mode}/${_configConstants.default.ACTOR_DIR}/${_configConstants.default.INDEX_FILE}`));
61
61
  let betaReference = mode;
62
62
  if (!(0, _fs.existsSync)(configFile)) {
63
- configFile = _path.default.join(uatDirectory, `conf/default/actors/index.js`);
63
+ configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stagePath}/${_configConstants.default.DEFAULT_CONFIG_DIR}/${_configConstants.default.ACTOR_DIR}/${_configConstants.default.INDEX_FILE}`));
64
64
  betaReference = "default";
65
65
  }
66
66
  if (betaFeature) {
67
- configFile = _path.default.join(uatDirectory, `conf/${betaReference}/actors/beta/${betaFeature}/index.js`);
67
+ configFile = _path.default.join(_path.default.resolve(process.cwd(), `${stagePath}/${betaReference}/${_configConstants.default.ACTOR_DIR}/${_configConstants.default.BETA_DIR}/${betaFeature}/${_configConstants.default.INDEX_FILE}`));
68
68
  if (!(0, _fs.existsSync)(configFile)) {
69
69
  throw new Error(`There is no beta feature configured with the name "${betaFeature}"`);
70
70
  }
@@ -10,22 +10,29 @@ exports.getUATFileName = getUATFileName;
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
  var _fs = _interopRequireDefault(require("fs"));
12
12
  var _auth = require("./auth");
13
- function getUATFileName(mode) {
13
+ var _ConfigurationHelper = require("./../configuration/ConfigurationHelper");
14
+ var _configPathResolver = require("./configPathResolver");
15
+ var _configConstants = _interopRequireDefault(require("../constants/configConstants"));
16
+ function getUATFileName(stage, mode) {
17
+ stage = stage || (0, _ConfigurationHelper.getRunStage)();
14
18
  mode = mode || (0, _auth.getRunMode)();
15
- const uatConfFilePath = _path.default.resolve(process.cwd(), `uat/conf/${mode}/uat.config.js`);
19
+ const stagePath = (0, _configPathResolver.getConfigPath)(stage);
20
+ const uatConfFilePath = _path.default.resolve(process.cwd(), `${stagePath}/${mode}/${_configConstants.default.UAT_CONFIG_FILE}`);
16
21
  if (_fs.default.existsSync(uatConfFilePath)) {
17
22
  return uatConfFilePath;
18
23
  }
19
- return _path.default.resolve(process.cwd(), `uat/conf/default/uat.config.js`);
24
+ ;
25
+ return _path.default.resolve(process.cwd(), `${stagePath}/${_configConstants.default.DEFAULT_CONFIG_DIR}/${_configConstants.default.UAT_CONFIG_FILE}`);
20
26
  }
21
- function getEnvConfigFilePath(mode) {
22
- const confFilePath = _path.default.resolve(process.cwd(), `uat/conf/${mode}/settings.json`);
27
+ function getEnvConfigFilePath(stage, mode) {
28
+ const stagePath = (0, _configPathResolver.getConfigPath)(stage);
29
+ const confFilePath = `${stagePath}/${mode}/${_configConstants.default.SETTINGS_FILE}`;
23
30
  // TODO: Actors Mode as config
24
31
  if (_fs.default.existsSync(confFilePath)) {
25
- return `uat/conf/${mode}/settings.json`;
32
+ return confFilePath;
26
33
  }
27
- return `uat/conf/default/settings.json`;
34
+ return `${stagePath}/${_configConstants.default.DEFAULT_CONFIG_DIR}/${_configConstants.default.SETTINGS_FILE}`;
28
35
  }
29
36
  function getReportFileName() {
30
- return `test-summary.json`;
37
+ return `${_configConstants.default.TEST_SUMMARY_FILE}`;
31
38
  }
@@ -0,0 +1,38 @@
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 _configConstants = _interopRequireDefault(require("../constants/configConstants"));
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
+ let properties;
18
+ if (_fs.default.existsSync(filePath)) {
19
+ properties = (0, _propertiesReader.default)(filePath);
20
+ } else {
21
+ // we have to remove this logic after adding all the projects with proper config files
22
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Properties file ${filePath} not found. Using default configurations.`);
23
+ properties = (0, _propertiesReader.default)();
24
+ properties.set('uat', 'uat/conf');
25
+ }
26
+ return properties;
27
+ }
28
+
29
+ // This function return the value for the passed arguments key
30
+
31
+ function getConfigPath(stage) {
32
+ const props = readPropertiesFile(_configConstants.default.STAGE_CONFIG_MAP_FILE);
33
+ const configPath = props.get(stage);
34
+ if (!configPath) {
35
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `No config mapping found for stage: "${stage}"`);
36
+ }
37
+ return configPath;
38
+ }
@@ -111,15 +111,16 @@ function combineDefaultConfigWithUserConfig(userConfiguration) {
111
111
  */
112
112
 
113
113
  function getConfigFilePath() {
114
- return _path.default.resolve(process.cwd(), (0, _configFileNameProvider.getUATFileName)());
114
+ return (0, _configFileNameProvider.getUATFileName)();
115
115
  }
116
116
  function generateConfigFromFile() {
117
117
  if (cachedConfig === null) {
118
118
  // Getting the default config's from framework
119
119
  const uatConfig = new _Configuration.default(getDefaultConfig());
120
120
  // overriding the application config's from project
121
- const appConfig = new _Configuration.default((0, _ConfigurationHelper.getApplicationConfig)());
122
121
  const userArgConfig = new _Configuration.default(_UserArgs.default.parseToObject(process.argv.slice(2)));
122
+ const stage = userArgConfig.get("stage");
123
+ const appConfig = new _Configuration.default((0, _ConfigurationHelper.getApplicationConfig)(stage));
123
124
  // overriding the user config's from CLI
124
125
  uatConfig.addAll(appConfig);
125
126
  uatConfig.addAll(userArgConfig);
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = mergeAbortedTestsIntoLastRun;
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ var _path = _interopRequireDefault(require("path"));
10
+ var _logger = require("../../../../utils/logger");
11
+ var _fileUtils = require("../../../../utils/fileUtils");
12
+ var _reporterConstants = _interopRequireDefault(require("../../constants/reporterConstants"));
13
+ function mergeAbortedTestsIntoLastRun() {
14
+ let resultsFile = _path.default.resolve(process.cwd(), _reporterConstants.default.DEFAULT_REPORTER_PATH),
15
+ lastRunFile = _path.default.resolve(process.cwd(), _reporterConstants.default.LAST_RUN_REPORTER_PATH);
16
+ try {
17
+ let report;
18
+ try {
19
+ report = JSON.parse(_fs.default.readFileSync(resultsFile, 'utf-8'));
20
+ } catch (e) {
21
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Failed to parse results file: ${resultsFile}`, e);
22
+ return;
23
+ }
24
+ const abortedTests = collectAbortedSpecIds(report);
25
+ let lastRunData = {
26
+ status: 'passed',
27
+ failedTests: []
28
+ };
29
+ if (_fs.default.existsSync(lastRunFile)) {
30
+ try {
31
+ const parsed = JSON.parse(_fs.default.readFileSync(lastRunFile, 'utf-8'));
32
+ lastRunData.status = parsed.status || lastRunData.status;
33
+ lastRunData.failedTests = Array.isArray(parsed.failedTests) ? parsed.failedTests : [];
34
+ } catch (e) {
35
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Failed to parse existing last-run file: ${lastRunFile}`, e);
36
+ }
37
+ }
38
+
39
+ // Merge existing failed tests + aborted tests
40
+ const failedSet = new Set(lastRunData.failedTests);
41
+ for (const id of abortedTests) {
42
+ failedSet.add(id);
43
+ }
44
+ lastRunData.failedTests = [...failedSet];
45
+ lastRunData.status = failedSet.size > 0 ? 'failed' : lastRunData.status;
46
+ (0, _fileUtils.writeFileContents)(lastRunFile, JSON.stringify(lastRunData, null, 2));
47
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `Updated ${abortedTests.size} aborted tests in .last-run.json file \n`);
48
+ return lastRunData;
49
+ } catch (err) {
50
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, `Error updating .last-run.json: ${err.message}`);
51
+ }
52
+ }
53
+ function collectAbortedSpecIds(report) {
54
+ const aborted = new Set();
55
+ if (!Array.isArray(report.suites)) {
56
+ return aborted;
57
+ }
58
+ const isAbortedSpec = spec => {
59
+ var _spec$tests;
60
+ const tags = Array.isArray(spec.tags) ? spec.tags : [];
61
+ return (_spec$tests = spec.tests) === null || _spec$tests === void 0 ? void 0 : _spec$tests.some(t => !tags.includes('skip') && t.projectName === 'chromium' && t.status === 'skipped');
62
+ };
63
+ const testResultsObj = report.suites;
64
+ while (testResultsObj.length > 0) {
65
+ const suite = testResultsObj.pop();
66
+ if (Array.isArray(suite.specs)) {
67
+ for (const spec of suite.specs) {
68
+ if (spec && isAbortedSpec(spec)) {
69
+ aborted.add(spec.id);
70
+ }
71
+ }
72
+ }
73
+ if (Array.isArray(suite.suites)) {
74
+ for (const child of suite.suites) testResultsObj.push(child);
75
+ }
76
+ }
77
+ return aborted;
78
+ }
@@ -11,6 +11,7 @@ var _fileUtils = require("../../../utils/fileUtils");
11
11
  var _readConfigFile = require("../readConfigFile");
12
12
  var _logger = require("../../../utils/logger");
13
13
  var _configFileNameProvider = require("../helpers/configFileNameProvider");
14
+ var _mergeAbortedTests = _interopRequireDefault(require("../reporter/helpers/mergeAbortedTests"));
14
15
  class JSONSummaryReporter {
15
16
  constructor() {
16
17
  this.durationInMS = -1;
@@ -123,6 +124,8 @@ class JSONSummaryReporter {
123
124
  (0, _fileUtils.writeFileContents)(_path.default.join(reportPath, './', (0, _configFileNameProvider.getReportFileName)()), JSON.stringify(this, null, ' '));
124
125
  }
125
126
  onExit() {
127
+ // Update .last-run.json with aborted tests due to timing out or interruption
128
+ (0, _mergeAbortedTests.default)();
126
129
  const shouldClearLastLine = this._open !== 'always' || this._open !== 'on-failure';
127
130
  if (shouldClearLastLine) {
128
131
  /**Below code is to replace the playwright default report commond with abstraction tool command */
@@ -86,7 +86,8 @@ function main() {
86
86
  // overriding the application config's from project
87
87
  const userArgConfig = new _Configuration.default(_UserArgs.default.parseToObject(process.argv.slice(2)));
88
88
  const mode = userArgConfig.get("mode");
89
- uatConfig.addAll(new _Configuration.default((0, _ConfigurationHelper.getApplicationConfig)(mode)));
89
+ const stage = userArgConfig.get("stage");
90
+ uatConfig.addAll(new _Configuration.default((0, _ConfigurationHelper.getApplicationConfig)(stage, mode)));
90
91
  // overriding the user config's from CLI
91
92
  uatConfig.addAll(userArgConfig);
92
93
  const modules = uatConfig.get('modules');
@@ -95,6 +96,7 @@ function main() {
95
96
  //We need to change this process.env variable to pass the module name in future.
96
97
  process.env.modules = modules;
97
98
  process.env.tearDown = tearDown;
99
+ process.env.stage = stage;
98
100
  const {
99
101
  isAuthMode,
100
102
  editionOrder,
@@ -102,7 +104,7 @@ function main() {
102
104
  bddMode = false,
103
105
  headless = false
104
106
  } = uatConfig.getAll();
105
- (0, _envInitializer.initializeEnvConfig)(mode, isAuthMode);
107
+ (0, _envInitializer.initializeEnvConfig)(stage, mode, isAuthMode);
106
108
 
107
109
  //This is only used for pass the user arguments to need places in legacy code. We need to rewamp that also.
108
110
  const userArgsObject = userArgConfig.getAll();
@@ -4,31 +4,72 @@ 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 _configPathResolver = require("../../../../../core/playwright/helpers/configPathResolver");
7
8
  jest.mock('fs');
8
- jest.mock('path');
9
+ jest.mock('path', () => ({
10
+ resolve: jest.fn()
11
+ }));
12
+ jest.mock("../../../../../core/playwright/helpers/configPathResolver", () => ({
13
+ getConfigPath: jest.fn()
14
+ }));
9
15
  const mockCwd = '/mock/current/directory';
10
16
  _path.default.resolve = jest.fn();
11
17
  process.cwd = jest.fn(() => mockCwd);
12
18
  describe('getUATFileName', () => {
13
19
  beforeEach(() => {
14
20
  jest.clearAllMocks();
21
+ _path.default.resolve.mockImplementation((...segments) => segments.join('/'));
15
22
  });
16
- test('return the pipeline matched config files for pipeline matched files exists', () => {
23
+ test('should return pipeline-matched config path when file exists', () => {
24
+ const stage = 'uat';
17
25
  const mode = 'cd';
18
- const mockPath = `${mockCwd}/uat/conf/${mode}/uat.config.js`;
26
+ _configPathResolver.getConfigPath.mockReturnValue(`${stage}/conf`);
19
27
  _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);
28
+ const expected = `${process.cwd()}/${stage}/conf/${mode}/uat.config.js`;
29
+ const result = (0, _configFileNameProvider.getUATFileName)(stage, mode);
30
+ expect(_configPathResolver.getConfigPath).toHaveBeenCalledWith(stage);
31
+ expect(_fs.existsSync).toHaveBeenCalledWith(expected);
32
+ expect(result).toBe(expected);
24
33
  });
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('/'));
34
+ test('should use default stage and mode when not provided', () => {
35
+ const mode = 'dev';
36
+ const stageConfigPath = 'uat/conf';
37
+ const expectedPath = `${mockCwd}/${stageConfigPath}/${mode}/uat.config.js`;
38
+ _fs.existsSync.mockReturnValue(true);
30
39
  const result = (0, _configFileNameProvider.getUATFileName)(mode);
31
40
  expect(_fs.existsSync).toHaveBeenCalledWith(`${mockCwd}/uat/conf/${mode}/uat.config.js`);
32
- expect(result).toBe(defaultPath);
41
+ expect(result).toBe(expectedPath);
42
+ });
43
+ test('should return the default config files for pipeline matched files not exists', () => {
44
+ const mockStage = 'uat';
45
+ const mockMode = 'ci';
46
+ const stageConfigPath = 'uat/conf';
47
+ const nonExistingPath = `${mockCwd}/${stageConfigPath}/${mockMode}/uat.config.js`;
48
+ const expectedDefaultPath = `${mockCwd}/${mockStage}/conf/default/uat.config.js`;
49
+ _configPathResolver.getConfigPath.mockReturnValue(stageConfigPath);
50
+ _fs.existsSync.mockReturnValue(false);
51
+ const result = (0, _configFileNameProvider.getUATFileName)(mockStage, mockMode);
52
+ expect(_fs.existsSync).toHaveBeenCalledWith(nonExistingPath);
53
+ expect(result).toBe(expectedDefaultPath);
54
+ });
55
+ });
56
+ describe('getEnvConfigFilePath', () => {
57
+ beforeEach(() => {
58
+ jest.clearAllMocks();
59
+ _path.default.resolve.mockImplementation((...segments) => segments.join('/'));
60
+ });
61
+ test('should return conf file path when file exists', () => {
62
+ _configPathResolver.getConfigPath.mockReturnValue('uat/conf');
63
+ _fs.existsSync.mockReturnValue(true);
64
+ const result = (0, _configFileNameProvider.getEnvConfigFilePath)('uat', 'cd');
65
+ expect(_configPathResolver.getConfigPath).toHaveBeenCalledWith('uat');
66
+ expect(_fs.existsSync).toHaveBeenCalled();
67
+ expect(result).toBe('uat/conf/cd/settings.json');
68
+ });
69
+ test('should return default path when file does not exist', () => {
70
+ _configPathResolver.getConfigPath.mockReturnValue('uat/conf');
71
+ _fs.existsSync.mockReturnValue(false);
72
+ const result = (0, _configFileNameProvider.getEnvConfigFilePath)('uat', 'ci');
73
+ expect(result).toBe('uat/conf/default/settings.json');
33
74
  });
34
75
  });
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _fs = _interopRequireDefault(require("fs"));
5
+ var _path = _interopRequireDefault(require("path"));
6
+ var _propertiesReader = _interopRequireDefault(require("properties-reader"));
7
+ var _configPathResolver = require("../../../../../core/playwright/helpers/configPathResolver");
8
+ var _logger = require("../../../../../utils/logger");
9
+ var _configConstants = _interopRequireDefault(require("../../../../../core/playwright/constants/configConstants"));
10
+ jest.mock('fs');
11
+ jest.mock('path');
12
+ jest.mock('properties-reader');
13
+ jest.mock('../../../../../utils/logger', () => ({
14
+ Logger: {
15
+ log: jest.fn(),
16
+ INFO_TYPE: 'info',
17
+ FAILURE_TYPE: 'failure'
18
+ }
19
+ }));
20
+ describe('getConfigPath', () => {
21
+ const mockProps = {
22
+ get: jest.fn(),
23
+ set: jest.fn()
24
+ };
25
+ beforeEach(() => {
26
+ jest.clearAllMocks();
27
+ _propertiesReader.default.mockReturnValue(mockProps);
28
+ _path.default.resolve.mockImplementation((...args) => args.join('/'));
29
+ });
30
+ test('should return config path when properties file exists and has mapping', () => {
31
+ _fs.default.existsSync.mockReturnValue(true);
32
+ mockProps.get.mockReturnValue('uat/conf');
33
+ const result = (0, _configPathResolver.getConfigPath)('uat');
34
+ expect(_fs.default.existsSync).toHaveBeenCalledWith(expect.stringContaining(_configConstants.default.STAGE_CONFIG_MAP_FILE));
35
+ expect(_propertiesReader.default).toHaveBeenCalled();
36
+ expect(mockProps.get).toHaveBeenCalledWith('uat');
37
+ expect(result).toBe('uat/conf');
38
+ expect(_logger.Logger.log).not.toHaveBeenCalledWith(_logger.Logger.FAILURE_TYPE, expect.any(String));
39
+ });
40
+ test('should log info and use default mapping if file does not exist', () => {
41
+ _fs.default.existsSync.mockReturnValue(false);
42
+ mockProps.get.mockImplementation(key => key === 'uat' ? 'uat/conf' : undefined);
43
+ const result = (0, _configPathResolver.getConfigPath)('uat');
44
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.INFO_TYPE, expect.stringContaining('not found'));
45
+ expect(mockProps.set).toHaveBeenCalledWith('uat', 'uat/conf');
46
+ expect(result).toBe('uat/conf');
47
+ });
48
+ test('should log failure if config mapping not found for stage', () => {
49
+ _fs.default.existsSync.mockReturnValue(true);
50
+ mockProps.get.mockReturnValue(undefined);
51
+ const result = (0, _configPathResolver.getConfigPath)('stageX');
52
+ expect(_logger.Logger.log).toHaveBeenCalledWith(_logger.Logger.FAILURE_TYPE, expect.stringContaining('stageX'));
53
+ expect(result).toBeUndefined();
54
+ });
55
+ });