@zohodesk/testinglibrary 3.2.14 → 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.
@@ -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
  });
@@ -65,7 +65,7 @@ function deleteFile(filePath) {
65
65
  function deleteFolder(folderPath) {
66
66
  if (_fs.default.existsSync(folderPath)) {
67
67
  try {
68
- _fs.default.rmdirSync(folderPath, {
68
+ _fs.default.rmSync(folderPath, {
69
69
  recursive: true
70
70
  });
71
71
  } catch (err) {
@@ -22,7 +22,7 @@ class LoggerImpl {
22
22
  info() {}
23
23
  log(type, message) {
24
24
  const color = this.colors[type];
25
- this.consoleLogger.log(`${color[0]}${message}${color[1]}`);
25
+ this.consoleLogger.log(`${color[0]}${message}${color[1]}\n`);
26
26
  }
27
27
  }
28
28
  const Logger = exports.Logger = new LoggerImpl();