@zohodesk/testinglibrary 0.5.10-n18-experimental → 0.5.12-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.
Files changed (28) hide show
  1. package/.gitlab-ci.yml +11 -11
  2. package/README.md +0 -8
  3. package/build/core/playwright/clear-caches.js +5 -2
  4. package/build/core/playwright/configuration/ConfigurationHelper.js +7 -5
  5. package/build/core/playwright/constants/configConstants.js +14 -0
  6. package/build/core/playwright/constants/reporterConstants.js +6 -2
  7. package/build/core/playwright/custom-commands.js +1 -1
  8. package/build/core/playwright/env-initializer.js +10 -9
  9. package/build/core/playwright/helpers/auth/getUsers.js +14 -14
  10. package/build/core/playwright/helpers/auth/index.js +8 -1
  11. package/build/core/playwright/helpers/auth/loginDefaultStepsHelper.js +0 -2
  12. package/build/core/playwright/helpers/auth/loginSteps.js +5 -13
  13. package/build/core/playwright/helpers/configFileNameProvider.js +15 -8
  14. package/build/core/playwright/helpers/configPathResolver.js +38 -0
  15. package/build/core/playwright/readConfigFile.js +8 -9
  16. package/build/core/playwright/setup/ProjectConfiguration.js +9 -26
  17. package/build/core/playwright/setup/config-creator.js +8 -5
  18. package/build/core/playwright/setup/config-utils.js +7 -3
  19. package/build/core/playwright/setup/qc-custom-reporter.js +4 -1
  20. package/build/core/playwright/test-runner.js +4 -6
  21. package/build/index.js +6 -0
  22. package/build/test/core/playwright/helpers/__tests__/configFileNameProvider.test.js +54 -13
  23. package/build/test/core/playwright/helpers/__tests__/configPathResolver.test.js +55 -0
  24. package/build/test/core/playwright/helpers/__tests__/getUsers_ListOfActors.test.js +29 -26
  25. package/build/utils/commonUtils.js +4 -1
  26. package/npm-shrinkwrap.json +146 -194
  27. package/package.json +2 -1
  28. package/playwright.config.js +10 -7
@@ -16,11 +16,14 @@ var _playwrightBdd = require("playwright-bdd");
16
16
  var _logger = require("../../../utils/logger");
17
17
  var _browserTypes = require("../constants/browserTypes");
18
18
  var _fileUtils = require("../../../utils/fileUtils");
19
+ var _ConfigurationHelper = require("../configuration/ConfigurationHelper");
20
+ var _configConstants = _interopRequireDefault(require("../constants/configConstants"));
19
21
  /**
20
22
  ** Playwright project configuration
21
23
  * @returns {import('@playwright/test').Project}
22
24
  */
23
25
 
26
+ const stage = (0, _ConfigurationHelper.getRunStage)();
24
27
  function getBrowserConfig({
25
28
  browserName,
26
29
  isAuthMode,
@@ -142,7 +145,8 @@ function getPathsForFeatureFiles(cwd) {
142
145
  const {
143
146
  failed = []
144
147
  } = JSON.parse(testSummary);
145
- const casesToRun = failed.map(filePath => _path.default.join(cwd, 'uat', filePath.replace(/\.spec\.js$|\.js$/, '')));
148
+ const casesToRun = failed.map(filePath => _path.default.join(cwd, _configConstants.default.TEST_SLICE_FOLDER, filePath.replace(/\.spec\.js$|\.js$/, '')));
149
+ ;
146
150
  return casesToRun;
147
151
  } else {
148
152
  _logger.Logger.log(_logger.Logger.INFO_TYPE, `Unable to read test summary from the ${reportPath}. Verify If File Exists in the path`);
@@ -153,12 +157,12 @@ function getPathsForFeatureFiles(cwd) {
153
157
  let moduleList = modules.split(',');
154
158
  return getModulePathForFeatureFiles(moduleList);
155
159
  }
156
- return [_path.default.join(cwd, 'uat', 'modules', '**', '*.feature')];
160
+ return [_path.default.join(cwd, _configConstants.default.TEST_SLICE_FOLDER, stage, 'modules', '**', 'feature-files', '*.feature')];
157
161
  }
158
162
  function getModulePathForFeatureFiles(moduleList) {
159
163
  let validModuleList = [];
160
164
  moduleList.forEach(moduleName => {
161
- let modulePath = _path.default.join(process.cwd(), 'uat', 'modules', '**', `${moduleName}`);
165
+ let modulePath = _path.default.join(process.cwd(), _configConstants.default.TEST_SLICE_FOLDER, '**', 'modules', '**', `${moduleName}`);
162
166
  if ((0, _fileUtils.checkIfFolderExistsWithPattern)(modulePath)) {
163
167
  validModuleList.push(_path.default.join(modulePath, '**', '*.feature'));
164
168
  } else {
@@ -8,11 +8,14 @@ exports.default = void 0;
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
  var _path = _interopRequireDefault(require("path"));
10
10
  var _codeFrame = require("@babel/code-frame");
11
+ var _configConstants = _interopRequireDefault(require("../constants/configConstants"));
12
+ var _ConfigurationHelper = require("../configuration/ConfigurationHelper");
13
+ const stage = (0, _ConfigurationHelper.getRunStage)();
11
14
  class CustomJsonReporter {
12
15
  constructor({
13
16
  outputFile = 'test-results.json'
14
17
  } = {}) {
15
- this.outputFile = _path.default.resolve(process.cwd(), 'uat/test-results/', outputFile);
18
+ this.outputFile = _path.default.resolve(process.cwd(), _configConstants.default.TEST_SLICE_FOLDER, stage, 'test-results/', outputFile);
16
19
  this.rootSuite = null;
17
20
  this.report = {
18
21
  config: {},
@@ -8,15 +8,11 @@ exports.default = void 0;
8
8
  exports.runPreprocessing = runPreprocessing;
9
9
  var _child_process = require("child_process");
10
10
  var _path = _interopRequireDefault(require("path"));
11
- var _customCommands = require("./custom-commands");
12
- var _cliArgsToObject = require("../../utils/cliArgsToObject");
13
11
  var _envInitializer = require("./env-initializer");
14
12
  var _logger = require("../../utils/logger");
15
13
  var _readConfigFile = require("./readConfigFile");
16
14
  var _rootPath = require("../../utils/rootPath");
17
15
  var _tagProcessor = _interopRequireDefault(require("./tagProcessor"));
18
- var _configUtils = require("./setup/config-utils");
19
- var _browserTypes = require("./constants/browserTypes");
20
16
  var _ConfigurationHelper = require("./configuration/ConfigurationHelper");
21
17
  var _Configuration = _interopRequireDefault(require("./configuration/Configuration"));
22
18
  var _UserArgs = _interopRequireDefault(require("./configuration/UserArgs"));
@@ -86,7 +82,8 @@ function main() {
86
82
  // overriding the application config's from project
87
83
  const userArgConfig = new _Configuration.default(_UserArgs.default.parseToObject(process.argv.slice(2)));
88
84
  const mode = userArgConfig.get("mode");
89
- uatConfig.addAll(new _Configuration.default((0, _ConfigurationHelper.getApplicationConfig)(mode)));
85
+ const stage = userArgConfig.get("stage");
86
+ uatConfig.addAll(new _Configuration.default((0, _ConfigurationHelper.getApplicationConfig)(stage, mode)));
90
87
  // overriding the user config's from CLI
91
88
  uatConfig.addAll(userArgConfig);
92
89
  const modules = uatConfig.get('modules');
@@ -95,6 +92,7 @@ function main() {
95
92
  //We need to change this process.env variable to pass the module name in future.
96
93
  process.env.modules = modules;
97
94
  process.env.tearDown = tearDown;
95
+ process.env.stage = stage;
98
96
  const {
99
97
  isAuthMode,
100
98
  editionOrder,
@@ -102,7 +100,7 @@ function main() {
102
100
  bddMode = false,
103
101
  headless = false
104
102
  } = uatConfig.getAll();
105
- (0, _envInitializer.initializeEnvConfig)(mode, isAuthMode);
103
+ (0, _envInitializer.initializeEnvConfig)(stage, mode, isAuthMode);
106
104
 
107
105
  //This is only used for pass the user arguments to need places in legacy code. We need to rewamp that also.
108
106
  const userArgsObject = userArgConfig.getAll();
package/build/index.js CHANGED
@@ -40,6 +40,12 @@ Object.defineProperty(exports, "getRunMode", {
40
40
  return _index.getRunMode;
41
41
  }
42
42
  });
43
+ Object.defineProperty(exports, "getRunStage", {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _index.getRunStage;
47
+ }
48
+ });
43
49
  Object.defineProperty(exports, "getUserForSelectedEditionAndProfile", {
44
50
  enumerable: true,
45
51
  get: function () {
@@ -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
+ });
@@ -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/readConfigFile', () => ({
9
- generateConfigFromFile: jest.fn(() => ({
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); // Main config file exists
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('Error loading actor configuration from /test/directory/conf/dev/actors/index.js');
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 file exists', () => {
40
- _fs.existsSync.mockReturnValueOnce(true);
41
- jest.doMock('/test/directory/conf/dev/actors/index.js', () => ({
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).mockReturnValueOnce(true);
53
- jest.doMock('/test/directory/conf/default/actors/index.js', () => ({
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 = `/test/directory/conf/dev/actors/beta/${betaFeature}/index.js`;
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
  });
@@ -7,11 +7,14 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.copyCommonSpecs = copyCommonSpecs;
8
8
  var _fileUtils = require("./fileUtils");
9
9
  var _path = _interopRequireDefault(require("path"));
10
+ var _configConstants = _interopRequireDefault(require("../core/playwright/constants/configConstants"));
11
+ var _ConfigurationHelper = require("../core/playwright/configuration/ConfigurationHelper");
12
+ const stage = (0, _ConfigurationHelper.getRunStage)();
10
13
  function copyCommonSpecs() {
11
14
  const libraryPath = require.resolve("@zohodesk/testinglibrary");
12
15
  // libraryPath will be build/index.js to go to the common specs we need to go one level up
13
16
  const commonSpecPath = _path.default.resolve(libraryPath, '../', 'common');
14
- const destDirectory = _path.default.resolve(process.cwd(), 'uat', 'modules', '.testingLib-common');
17
+ const destDirectory = _path.default.resolve(process.cwd(), _configConstants.default.TEST_SLICE_FOLDER, stage, 'modules', '.testingLib-common');
15
18
  (0, _fileUtils.deleteFolder)(destDirectory);
16
19
  (0, _fileUtils.copyDirectory)(commonSpecPath, destDirectory);
17
20
  }