@zohodesk/testinglibrary 3.2.15 → 4.0.0
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 +0 -8
- package/build/core/jest/setup/index.js +1 -1
- package/build/core/playwright/configuration/ConfigurationHelper.js +7 -5
- package/build/core/playwright/constants/configConstants.js +17 -0
- package/build/core/playwright/custom-commands.js +1 -1
- package/build/core/playwright/env-initializer.js +10 -9
- package/build/core/playwright/helpers/auth/getUsers.js +14 -14
- package/build/core/playwright/helpers/configFileNameProvider.js +15 -8
- package/build/core/playwright/helpers/configPathResolver.js +38 -0
- package/build/core/playwright/readConfigFile.js +3 -2
- package/build/core/playwright/test-runner.js +4 -2
- package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +54 -13
- package/build/test/core/playwright/helpers/__tests__/configPathResolver.test.js +55 -0
- package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +29 -26
- package/build/utils/fileUtils.js +1 -1
- package/npm-shrinkwrap.json +2633 -3408
- package/package.json +25 -25
- package/test-results/.last-run.json +0 -4
- package/unit_reports/unit-report.html +0 -260
package/README.md
CHANGED
|
@@ -40,14 +40,6 @@
|
|
|
40
40
|
|
|
41
41
|
- 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
|
|
42
42
|
|
|
43
|
-
### Issue fix
|
|
44
|
-
- Custom teardown comment provided
|
|
45
|
-
|
|
46
|
-
### v3.2.10 - 09-10-2025
|
|
47
|
-
|
|
48
|
-
#### Enhancement
|
|
49
|
-
- A teardown option has been introduced in the configuration to manage and clean up login sessions stored in the NFS environment.
|
|
50
|
-
|
|
51
43
|
|
|
52
44
|
### v3.2.9 - 26-09-2025
|
|
53
45
|
|
|
@@ -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
|
-
|
|
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 =
|
|
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;
|
|
@@ -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/
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
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(
|
|
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(`${
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
32
|
+
return confFilePath;
|
|
26
33
|
}
|
|
27
|
-
return
|
|
34
|
+
return `${stagePath}/${_configConstants.default.DEFAULT_CONFIG_DIR}/${_configConstants.default.SETTINGS_FILE}`;
|
|
28
35
|
}
|
|
29
36
|
function getReportFileName() {
|
|
30
|
-
return
|
|
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
|
|
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);
|
|
@@ -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
|
-
|
|
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
|
|
23
|
+
test('should return pipeline-matched config path when file exists', () => {
|
|
24
|
+
const stage = 'uat';
|
|
17
25
|
const mode = 'cd';
|
|
18
|
-
|
|
26
|
+
_configPathResolver.getConfigPath.mockReturnValue(`${stage}/conf`);
|
|
19
27
|
_fs.existsSync.mockReturnValue(true);
|
|
20
|
-
|
|
21
|
-
const result = (0, _configFileNameProvider.getUATFileName)(mode);
|
|
22
|
-
expect(
|
|
23
|
-
expect(
|
|
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('
|
|
26
|
-
const mode = '
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
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(
|
|
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
|
+
});
|
|
@@ -1,80 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _fs = require("fs");
|
|
4
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
5
5
|
var _path = _interopRequireDefault(require("path"));
|
|
6
|
+
var _getUsers = require("../../../../../core/playwright/helpers/auth/getUsers");
|
|
7
|
+
var _configPathResolver = require("../../../../../core/playwright/helpers/configPathResolver");
|
|
6
8
|
jest.mock('fs');
|
|
7
9
|
jest.mock('path');
|
|
8
|
-
jest.mock('../../../../../core/playwright/
|
|
9
|
-
|
|
10
|
-
uatDirectory: '/test/directory'
|
|
11
|
-
})),
|
|
12
|
-
getRunMode: jest.fn(() => 'dev')
|
|
10
|
+
jest.mock('../../../../../core/playwright/helpers/configPathResolver', () => ({
|
|
11
|
+
getConfigPath: jest.fn()
|
|
13
12
|
}));
|
|
14
|
-
const {
|
|
15
|
-
getListOfActors
|
|
16
|
-
} = require('../../../../../core/playwright/helpers/auth/getUsers');
|
|
17
13
|
describe('getListOfActors', () => {
|
|
14
|
+
const stageConfig = 'uat/conf';
|
|
15
|
+
const mode = 'dev';
|
|
16
|
+
const stage = 'uat';
|
|
18
17
|
beforeEach(() => {
|
|
19
18
|
jest.clearAllMocks();
|
|
20
19
|
_path.default.join.mockImplementation((...args) => args.join('/'));
|
|
20
|
+
_path.default.resolve.mockImplementation((...args) => args.join('/'));
|
|
21
|
+
_configPathResolver.getConfigPath.mockReturnValue('uat/conf');
|
|
21
22
|
});
|
|
22
23
|
test('throws an error when config file cannot be loaded', () => {
|
|
23
|
-
_fs.existsSync.mockReturnValueOnce(true);
|
|
24
|
-
|
|
25
|
-
jest.mock('/test/directory/conf/dev/actors/index.js', () => {
|
|
24
|
+
_fs.default.existsSync.mockReturnValueOnce(true);
|
|
25
|
+
jest.mock('/uat/conf/dev/actors/index.js', () => {
|
|
26
26
|
throw new Error('Loading error');
|
|
27
27
|
}, {
|
|
28
28
|
virtual: true
|
|
29
29
|
});
|
|
30
|
-
expect(() => getListOfActors()).toThrow(
|
|
30
|
+
expect(() => (0, _getUsers.getListOfActors)()).toThrow(`Error loading actor configuration from ${_path.default.join(_path.default.resolve(process.cwd(), 'uat/conf/dev/actors/index.js'))}`);
|
|
31
31
|
});
|
|
32
32
|
test('throws an error when beta feature config does not exist', () => {
|
|
33
|
-
_fs.existsSync.mockReturnValueOnce(true) // Main config file exists
|
|
33
|
+
_fs.default.existsSync.mockReturnValueOnce(true) // Main config file exists
|
|
34
34
|
.mockReturnValueOnce(false); // Beta feature config does not exist in either path
|
|
35
35
|
|
|
36
36
|
const betaFeature = 'nonExistentFeature';
|
|
37
|
-
expect(() => getListOfActors(betaFeature)).toThrow(`There is no beta feature configured with the name "${betaFeature}"`);
|
|
37
|
+
expect(() => (0, _getUsers.getListOfActors)(betaFeature)).toThrow(`There is no beta feature configured with the name "${betaFeature}"`);
|
|
38
38
|
});
|
|
39
|
-
test('loads main configuration when betaFeature is not provided and main config
|
|
40
|
-
_fs.existsSync.mockReturnValueOnce(true);
|
|
41
|
-
|
|
39
|
+
test('loads main configuration when betaFeature is not provided and main config exists', () => {
|
|
40
|
+
_fs.default.existsSync.mockReturnValueOnce(true);
|
|
41
|
+
const file = _path.default.join(_path.default.resolve(process.cwd(), `${stageConfig}/${mode}/actors/index.js`));
|
|
42
|
+
jest.doMock(file, () => ({
|
|
42
43
|
actors: []
|
|
43
44
|
}), {
|
|
44
45
|
virtual: true
|
|
45
46
|
});
|
|
46
|
-
const result = getListOfActors();
|
|
47
|
+
const result = (0, _getUsers.getListOfActors)();
|
|
47
48
|
expect(result).toEqual({
|
|
48
49
|
actors: []
|
|
49
50
|
});
|
|
50
51
|
});
|
|
51
52
|
test('falls back to default configuration if main config file does not exist', () => {
|
|
52
|
-
_fs.existsSync.mockReturnValueOnce(false)
|
|
53
|
-
|
|
53
|
+
_fs.default.existsSync.mockReturnValueOnce(false) // Main config file missing
|
|
54
|
+
.mockReturnValueOnce(true); // Beta feature config exists
|
|
55
|
+
|
|
56
|
+
const defaultConfigFile = _path.default.join(_path.default.resolve(process.cwd(), `${stage}/conf/default/actors/index.js`));
|
|
57
|
+
jest.doMock(defaultConfigFile, () => ({
|
|
54
58
|
actors: []
|
|
55
59
|
}), {
|
|
56
60
|
virtual: true
|
|
57
61
|
});
|
|
58
|
-
const result = getListOfActors();
|
|
62
|
+
const result = (0, _getUsers.getListOfActors)();
|
|
59
63
|
expect(result).toEqual({
|
|
60
64
|
actors: []
|
|
61
65
|
});
|
|
62
66
|
});
|
|
63
67
|
test('loads beta feature configuration when betaFeature is provided', () => {
|
|
64
|
-
_fs.existsSync.mockReturnValueOnce(true) // Main config file exists
|
|
68
|
+
_fs.default.existsSync.mockReturnValueOnce(true) // Main config file exists
|
|
65
69
|
.mockReturnValueOnce(true); // Beta feature config exists
|
|
66
70
|
|
|
67
71
|
const betaFeature = 'parentchild';
|
|
68
|
-
const betaFeaturePath =
|
|
72
|
+
const betaFeaturePath = _path.default.join(_path.default.resolve(process.cwd(), `${stageConfig}/${mode}/actors/beta/${betaFeature}/index.js`));
|
|
69
73
|
jest.doMock(betaFeaturePath, () => ({
|
|
70
74
|
betaActors: []
|
|
71
75
|
}), {
|
|
72
76
|
virtual: true
|
|
73
77
|
});
|
|
74
|
-
const result = getListOfActors(betaFeature);
|
|
78
|
+
const result = (0, _getUsers.getListOfActors)(betaFeature);
|
|
75
79
|
expect(result).toEqual({
|
|
76
80
|
betaActors: []
|
|
77
81
|
});
|
|
78
|
-
expect(_path.default.join).toHaveBeenCalledWith('/test/directory', `conf/dev/actors/beta/${betaFeature}/index.js`);
|
|
79
82
|
});
|
|
80
83
|
});
|
package/build/utils/fileUtils.js
CHANGED