@zohodesk/testinglibrary 0.0.3 → 0.0.5

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.
@@ -0,0 +1,99 @@
1
+ const { readFileSync, existsSync, writeFileSync, mkdirSync } = require('fs');
2
+ const path = require('path');
3
+ const { Logger } = require('../utils/logger');
4
+
5
+
6
+ function getScriptsToBeAdded() {
7
+ return {
8
+ "ua-test": "ZDTestingFramework test --mode=prod --headed",
9
+ "ua-test-debug": "ZDTestingFramework test --mode=prod --debug",
10
+ "ua-report": "ZDTestingFramework report --port=9009",
11
+ "codegen": "ZDTestingFramework codegen deskclientapp.localzoho.com/agent"
12
+ }
13
+ }
14
+
15
+ function updatePackageJSONScripts() {
16
+ const packageJsonPath = path.resolve(process.cwd(), './package.json')
17
+ if (existsSync(packageJsonPath)) {
18
+ const packageContents = readFileSync(packageJsonPath);
19
+ const configJSON = JSON.parse(packageContents);
20
+ const { scripts = {} } = configJSON;
21
+ const modifiedScripts = { ...scripts, ...getScriptsToBeAdded() };
22
+ const modifiedConfigJSON = { ...configJSON, scripts: modifiedScripts };
23
+ writeFileSync(packageJsonPath, JSON.stringify(modifiedConfigJSON, null, 2));
24
+ } else {
25
+ Logger.log(Logger.FAILURE_TYPE, 'Unable to find package json. Run init command in the root path of the project.');
26
+ process.exit();
27
+ }
28
+ }
29
+
30
+
31
+ function createFolderForUAT() {
32
+ const uatFolder = path.resolve(process.cwd(), 'uat');
33
+
34
+ if (existsSync(uatFolder)) {
35
+ Logger.log(Logger.INFO_TYPE, 'Uat Folder already Exists.');
36
+ process.exit();
37
+ } else {
38
+ Logger.log(Logger.INFO_TYPE, 'Creating Uat Folder');
39
+ mkdirSync(uatFolder);
40
+ }
41
+ }
42
+
43
+ function getSetupFileAsString(fileName) {
44
+ return readFileSync(path.resolve(__dirname, './', fileName)).toString();
45
+ }
46
+
47
+ function createUatConfig() {
48
+ const uatConfigPath = path.resolve(process.cwd(), 'uat.config.js');
49
+ if (existsSync(uatConfigPath)) {
50
+ Logger.log(Logger.INFO_TYPE, 'Uat Config already Exists.');
51
+ process.exit();
52
+ } else {
53
+ Logger.log(Logger.INFO_TYPE, 'Creating Uat config file...');
54
+ writeFileSync(uatConfigPath, getSetupFileAsString('uat-config-sample.js'), null, 2)
55
+ }
56
+ }
57
+
58
+ function createAuthenticationFile() {
59
+ const isUATexist = path.resolve(process.cwd(), 'uat')
60
+ if (existsSync(isUATexist)) {
61
+ Logger.log(Logger.INFO_TYPE, 'Creating Authentication File ....')
62
+ try {
63
+ mkdirSync(path.resolve(process.cwd(), 'playwright'), { recursive: true })
64
+ mkdirSync(path.resolve(process.cwd(), 'playwright', '.auth'), { recursive: true })
65
+ const authFilePath = path.resolve(process.cwd(), 'playwright', '.auth', 'user.json')
66
+ writeFileSync(authFilePath, getSetupFileAsString('user-example.json'), null, 2)
67
+ } catch (err) {
68
+ Logger.log(Logger.FAILURE_TYPE, 'Something went wrong ! Folder not Created. Please re-initialize npm init-uat')
69
+ }
70
+ } else {
71
+ Logger.log(Logger.INFO_TYPE, 'Something went wrong. Please re-initialize the @zohodesk/testinglibrary');
72
+ }
73
+ }
74
+
75
+ function createConfigJson() {
76
+ const uatFolder = path.resolve(process.cwd(), 'uat');
77
+ if (existsSync(uatFolder)) {
78
+ Logger.log(Logger.INFO_TYPE, 'Creating env-config file inside UAT Folder');
79
+ writeFileSync(path.resolve(uatFolder, './env-config.json'), getSetupFileAsString('env-config-sample.json'), null, 2)
80
+ } else {
81
+ Logger.log(Logger.INFO_TYPE, 'Something went wrong. Please re-initialize the @zohodesk/testinglibrary');
82
+ }
83
+ }
84
+
85
+ function setupProject() {
86
+ updatePackageJSONScripts();
87
+ createUatConfig();
88
+ createFolderForUAT();
89
+ createConfigJson();
90
+ createAuthenticationFile()
91
+ // Create folder for playwright . Inside .auth folder needs to be created. user.json
92
+ // Add playwright and test-results to .gitignore
93
+ }
94
+
95
+ setTimeout(() => {
96
+ Logger.log(Logger.SUCCESS_TYPE, 'Setup Project is Ready ..')
97
+ }, 2000)
98
+
99
+ module.exports = setupProject;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Represents the user configuration object.
3
+ * @typedef {Object} UserConfig
4
+ * @property {string} headless - Headless Browsers mode.
5
+ * @property {number} trace - trace for test cases.
6
+ * @property {boolean} video - video for test cases,
7
+ * @property {boolean} debug - debug mode
8
+ * @property {string} mode: mode in which the test cases needs to run
9
+ * @property {boolean} isAuthMode - Auth Mode
10
+ * @property {any} browsers: List of browsers
11
+ */
12
+ /**
13
+ * @type {UserConfig}
14
+ */
15
+ module.exports = {
16
+ headed: true,
17
+ browsers: ['Chrome', 'Firefox'],
18
+ mode: 'dev',
19
+ isAuthMode: true,
20
+ trace: true,
21
+ video: true,
22
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "cookies": []
3
+ }
@@ -1,35 +1,63 @@
1
- function cliArgsToObject(cliArgs, isKeyNeedToBeAdded) {
2
- const processEnv = {};
3
- cliArgs.forEach(option => {
4
- if (/^--./.test(option)) {
5
- const equIndex = option.indexOf('=');
6
- let key = option.slice(2, equIndex);
7
- let value = option.slice(equIndex + 1);
8
- if (equIndex === -1) {
9
- key = option.slice(2);
10
- value = true;
11
- }
12
- processEnv[key] = value;
13
- }
14
- });
15
- return processEnv;
16
- }
17
-
18
- function objectToCliArgs(objectToBeConverted, isKeyNeedToBeAdded) {
19
- const argsArray = [];
20
-
21
- Object.keys(objectToBeConverted).forEach(key => {
22
- if (isKeyNeedToBeAdded(key)) {
23
- if (typeof objectToBeConverted[key] === 'boolean' && objectToBeConverted[key]) {
24
- argsArray.push(`--${key}`)
25
- } else {
26
- argsArray.push(`--${key}=${objectToBeConverted[key]}`)
27
- }
28
- }
29
- })
30
-
31
- return argsArray;
32
- }
33
-
34
-
1
+ /**
2
+ * Converts an array of command-line arguments into an object.
3
+ *
4
+ * @param {string[]} cliArgs - An array of command-line arguments.
5
+ * @param {boolean} [isKeyNeedToBeAdded=true] - Indicates whether the keys should be added to the resulting object.
6
+ * @returns {Object} An object representing the command-line arguments, where keys are argument names (without '--') and values are argument values.
7
+ * If `isKeyNeedToBeAdded` is set to `false`, only values are included in the object with numeric indexes as keys.
8
+ *
9
+ * @example
10
+ * // Example usage:
11
+ * const args = ['--port=8080', '--verbose', 'input.txt'];
12
+ * const result = cliArgsToObject(args);
13
+ * // result will be: { port: '8080', verbose: true }
14
+ */
15
+ function cliArgsToObject(cliArgs, isKeyNeedToBeAdded) {
16
+ const processEnv = {};
17
+ cliArgs.forEach(option => {
18
+ if (/^--./.test(option)) {
19
+ const equIndex = option.indexOf('=');
20
+ let key = option.slice(2, equIndex);
21
+ let value = option.slice(equIndex + 1);
22
+ if (equIndex === -1) {
23
+ key = option.slice(2);
24
+ value = true;
25
+ }
26
+ processEnv[key] = value;
27
+ }
28
+ });
29
+ return processEnv;
30
+ }
31
+
32
+
33
+ /**
34
+ * Converts an object to an array of command-line arguments.
35
+ *
36
+ * @param {Object} objectToBeConverted - The object to be converted to command-line arguments.
37
+ * @param {(string|function(string): boolean)} [isKeyNeedToBeAdded=true] - A string representing a key, or a function that determines whether a key should be added to the resulting array.
38
+ * @returns {string[]} An array of command-line arguments generated from the object's key-value pairs. Keys are transformed into argument names (with '--') and values are added as argument values.
39
+ *
40
+ * @example
41
+ * // Example usage:
42
+ * const options = { port: 8080, verbose: true, input: 'input.txt' };
43
+ * const args = objectToCliArgs(options);
44
+ * // args will be: ['--port=8080', '--verbose', '--input=input.txt']
45
+ */
46
+ function objectToCliArgs(objectToBeConverted, isKeyNeedToBeAdded) {
47
+ const argsArray = [];
48
+
49
+ Object.keys(objectToBeConverted).forEach(key => {
50
+ if (isKeyNeedToBeAdded(key)) {
51
+ if (typeof objectToBeConverted[key] === 'boolean' && objectToBeConverted[key]) {
52
+ argsArray.push(`--${key}`)
53
+ } else {
54
+ argsArray.push(`--${key}=${objectToBeConverted[key]}`)
55
+ }
56
+ }
57
+ })
58
+
59
+ return argsArray;
60
+ }
61
+
62
+
35
63
  module.exports = { cliArgsToObject, objectToCliArgs };
@@ -1,9 +1,9 @@
1
- const { platform } = require('os');
2
-
3
- const isWindows = platform().toLowerCase() === 'win32';
4
-
5
- function getFilePathWithExtension(binName) {
6
- return isWindows ? `${binName}.cmd` : binName;
7
- }
8
-
1
+ const { platform } = require('os');
2
+
3
+ const isWindows = platform().toLowerCase() === 'win32';
4
+
5
+ function getFilePathWithExtension(binName) {
6
+ return isWindows ? `${binName}.cmd` : binName;
7
+ }
8
+
9
9
  module.exports = getFilePathWithExtension;
@@ -1,28 +1,28 @@
1
- const SUCCESS_TYPE = 'success';
2
- const FAILURE_TYPE = 'failure';
3
- const INFO_TYPE = 'info';
4
-
5
- function logger() {
6
- this.colors = {
7
- 'success': ['\x1b[36m', '\x1b[0m'],
8
- 'failure': ['\x1b[31m', '\x1b[0m'],
9
- 'info': ['\x1b[33m', '\x1b[0m']
10
- }
11
- this.consoleLogger = console;
12
- return {
13
- SUCCESS_TYPE,
14
- FAILURE_TYPE,
15
- INFO_TYPE,
16
- error: () => { },
17
- info: () => { },
18
- log: (type, message) => {
19
- const color = this.colors[type];
20
- this.consoleLogger.log(`${color[0]}${message}${color[1]}`)
21
- }
22
- }
23
- }
24
-
25
-
26
- module.exports = {
27
- Logger: logger()
1
+ const SUCCESS_TYPE = 'success';
2
+ const FAILURE_TYPE = 'failure';
3
+ const INFO_TYPE = 'info';
4
+
5
+ function logger() {
6
+ this.colors = {
7
+ 'success': ['\x1b[36m', '\x1b[0m'],
8
+ 'failure': ['\x1b[31m', '\x1b[0m'],
9
+ 'info': ['\x1b[33m', '\x1b[0m']
10
+ }
11
+ this.consoleLogger = console;
12
+ return {
13
+ SUCCESS_TYPE,
14
+ FAILURE_TYPE,
15
+ INFO_TYPE,
16
+ error: () => { },
17
+ info: () => { },
18
+ log: (type, message) => {
19
+ const color = this.colors[type];
20
+ this.consoleLogger.log(`${color[0]}${message}${color[1]}`)
21
+ }
22
+ }
23
+ }
24
+
25
+
26
+ module.exports = {
27
+ Logger: logger()
28
28
  }
@@ -1,51 +1,51 @@
1
- const path = require('path')
2
- const fs = require('fs');
3
- const { Logger } = require('./logger');
4
- const getFilePathWithExtension = require('./getFilePath');
5
-
6
- function findBinaryPath(directory, command) {
7
- const binaryPath = path.join(directory, '.bin', getFilePathWithExtension(command));
8
- if (fs.existsSync(binaryPath)) {
9
- return binaryPath;
10
- }
11
-
12
- // Recursively search parent directories. Might be time-consuming ?? Can we look for npm module like which?
13
- const parentDir = path.dirname(directory);
14
- if (parentDir === directory) {
15
- return null;
16
- }
17
-
18
- return findBinaryPath(parentDir, command);
19
- }
20
-
21
- function getRootPath() {
22
- return path.resolve(__dirname, '../', '../');
23
- }
24
-
25
- function getRootNodeModulesPath() {
26
- return path.resolve(getRootPath(), 'node_modules');
27
- }
28
-
29
- function getBinPath(command) {
30
- const packageNodeModulesPath = getRootNodeModulesPath();
31
- return findBinaryPath(packageNodeModulesPath, command);
32
-
33
- }
34
-
35
-
36
- function getExecutableBinaryPath(command) {
37
- const binPath = getBinPath(command);
38
- if (binPath !== null) {
39
- return binPath;
40
- } else {
41
- Logger.log(Logger.FAILURE_TYPE, `Error: Could not find executable bin file. Make sure to npm install before proceeding`);
42
- process.exit();
43
- }
44
- }
45
-
46
- module.exports = {
47
- getRootPath,
48
- getBinPath,
49
- getRootNodeModulesPath,
50
- getExecutableBinaryPath
1
+ const path = require('path')
2
+ const fs = require('fs');
3
+ const { Logger } = require('./logger');
4
+ const getFilePathWithExtension = require('./getFilePath');
5
+
6
+ function findBinaryPath(directory, command) {
7
+ const binaryPath = path.join(directory, '.bin', getFilePathWithExtension(command));
8
+ if (fs.existsSync(binaryPath)) {
9
+ return binaryPath;
10
+ }
11
+
12
+ // Recursively search parent directories. Might be time-consuming ?? Can we look for npm module like which?
13
+ const parentDir = path.dirname(directory);
14
+ if (parentDir === directory) {
15
+ return null;
16
+ }
17
+
18
+ return findBinaryPath(parentDir, command);
19
+ }
20
+
21
+ function getRootPath() {
22
+ return path.resolve(__dirname, '../', '../');
23
+ }
24
+
25
+ function getRootNodeModulesPath() {
26
+ return path.resolve(getRootPath(), 'node_modules');
27
+ }
28
+
29
+ function getBinPath(command) {
30
+ const packageNodeModulesPath = getRootNodeModulesPath();
31
+ return findBinaryPath(packageNodeModulesPath, command);
32
+
33
+ }
34
+
35
+
36
+ function getExecutableBinaryPath(command) {
37
+ const binPath = getBinPath(command);
38
+ if (binPath !== null) {
39
+ return binPath;
40
+ } else {
41
+ Logger.log(Logger.FAILURE_TYPE, `Error: Could not find executable bin file. Make sure to npm install before proceeding`);
42
+ process.exit();
43
+ }
44
+ }
45
+
46
+ module.exports = {
47
+ getRootPath,
48
+ getBinPath,
49
+ getRootNodeModulesPath,
50
+ getExecutableBinaryPath
51
51
  }