@zohodesk/testinglibrary 0.0.2 → 0.0.3

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/changelog.md CHANGED
@@ -4,6 +4,10 @@
4
4
 
5
5
  # 0.0.2
6
6
 
7
+ - Added Support for custom config generator based on user preferences
8
+
9
+ # 0.0.2
10
+
7
11
  - Fix for Finding directories inside node_modules folder
8
12
 
9
13
  # 0.0.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -28,4 +28,4 @@
28
28
  "bin": {
29
29
  "ZDTestingFramework": "./bin/cli.js"
30
30
  }
31
- }
31
+ }
@@ -1,7 +1,7 @@
1
1
  const { existsSync } = require('fs');
2
2
  const path = require('path');
3
3
 
4
- const fileName = 'test.config.js';
4
+ const fileName = 'uat.config.js';
5
5
 
6
6
  function generateConfigFromFile() {
7
7
  const filePath = path.resolve(process.cwd(), fileName);
@@ -14,5 +14,17 @@ function generateConfigFromFile() {
14
14
  return {};
15
15
  }
16
16
 
17
+ function isUserConfigFileAvailable() {
18
+ const filePath = path.resolve(process.cwd(), fileName);
19
+ if (existsSync(filePath)) {
20
+ return true;
21
+ }
22
+ return false;
23
+ }
24
+
17
25
 
18
- module.exports = generateConfigFromFile;
26
+ module.exports = {
27
+ fileName,
28
+ isUserConfigFileAvailable,
29
+ generateConfigFromFile
30
+ };
@@ -0,0 +1,79 @@
1
+ // @ts-check
2
+ const { defineConfig, devices } = require('@playwright/test');
3
+ const path = require('path');
4
+ const { generateConfigFromFile } = require('../readConfigFile');
5
+ const numCPUs = require('os').cpus().length;
6
+
7
+ const defaultBrowser = ['Chrome']
8
+
9
+ const { browsers = defaultBrowser, isAuthMode, trace = false, video = false } = generateConfigFromFile();
10
+
11
+
12
+ let projects = browsers.map(browser => {
13
+ if (browser === 'Chrome') {
14
+ return {
15
+ name: 'chromium',
16
+ use: {
17
+ ...devices['Desktop Chrome'],
18
+ storageState: isAuthMode ? path.resolve(process.cwd(), 'playwright/.auth/user.json') : null
19
+ },
20
+ dependencies: isAuthMode ? ['setup'] : [],
21
+ };
22
+ } else if (browser === 'Firefox') {
23
+ return {
24
+ name: 'firefox',
25
+ timeout: 4 * 60 * 1000,
26
+ expect: {
27
+ timeout: 80 * 1000,
28
+ },
29
+ use: {
30
+ ...devices['Desktop Firefox'],
31
+ storageState: isAuthMode ? path.resolve(process.cwd(), 'playwright/.auth/user.json') : null
32
+ },
33
+ dependencies: isAuthMode ? ['setup'] : [],
34
+ };
35
+ } else if (browser === 'safari') {
36
+ return {
37
+ name: 'webkit',
38
+ timeout: 2 * 60 * 1000,
39
+ expect: {
40
+ timeout: 80 * 1000,
41
+ },
42
+ use: {
43
+ ...devices['Desktop Safari'],
44
+ storageState: isAuthMode ? path.resolve(process.cwd(), 'playwright/.auth/user.json') : null
45
+ },
46
+ dependencies: isAuthMode ? ['setup'] : null,
47
+ }
48
+ }
49
+ }).filter(Boolean);
50
+
51
+ console.log(projects);
52
+
53
+ module.exports = defineConfig({
54
+ testDir: path.join(path.resolve(process.cwd()), 'uat'),
55
+ outputDir: path.join(process.cwd(), 'test-results'),
56
+ fullyParallel: true,
57
+ forbidOnly: !!process.env.CI,
58
+ retries: process.env.CI ? 2 : 0,
59
+ workers: process.env.CI ? 1 : 1,
60
+ reporter: [['html', { outputFolder: path.join(process.cwd(), 'playwright-report'), open: "always" }]],
61
+ timeout: 60 * 1000,
62
+ expect: {
63
+ timeout: 5 * 1000,
64
+ },
65
+
66
+ use: {
67
+ trace: trace ? 'on' : 'off',
68
+ video: video ? {
69
+ mode: 'on',
70
+ size: { width: 640, height: 480 }
71
+ } : 'off'
72
+ },
73
+
74
+ projects: isAuthMode ? [
75
+ { name: 'setup', testMatch: /.*\.setup\.js/ },
76
+ ...projects
77
+ ] : [...projects]
78
+ });
79
+
@@ -4,8 +4,7 @@ const { CUSTOM_COMMANDS } = require('./custom-commands');
4
4
  const { cliArgsToObject, objectToCliArgs } = require('../../utils/cliArgsToObject');
5
5
  const { initializeEnvConfig } = require('./env-initializer');
6
6
  const { Logger } = require('../../utils/logger');
7
- const getFilePathWithExtension = require('../../utils/getFilePath');
8
- const generateConfigFromFile = require('./readConfigFile');
7
+ const { isUserConfigFileAvailable } = require('./readConfigFile');
9
8
  const { getExecutableBinaryPath } = require('../../utils/rootPath');
10
9
 
11
10
 
@@ -15,11 +14,9 @@ const userArgs = process.argv.slice(2);
15
14
 
16
15
  const userArgsObject = cliArgsToObject(userArgs);
17
16
 
18
- initializeEnvConfig(userArgsObject.mode ? userArgsObject.mode : 'dev');
19
-
20
-
21
- generateConfigFromFile();
22
17
 
18
+ // Environment variables Initialization
19
+ initializeEnvConfig(userArgsObject.mode ? userArgsObject.mode : 'dev');
23
20
 
24
21
 
25
22
  const playwrightArgs = objectToCliArgs(userArgsObject, (key) => !CUSTOM_COMMANDS.includes(key));
@@ -28,7 +25,10 @@ const playwrightArgs = objectToCliArgs(userArgsObject, (key) => !CUSTOM_COMMANDS
28
25
  const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));
29
26
 
30
27
  const command = playwrightPath;
31
- const args = ['test', '--config', require.resolve('../../../playwright.config.js')].concat(playwrightArgs);
28
+
29
+ const configPath = isUserConfigFileAvailable() ? require.resolve('./setup/config-creator.js') : require.resolve('../../../playwright.config.js');
30
+
31
+ const args = ['test', '--config', configPath].concat(playwrightArgs);
32
32
 
33
33
 
34
34
  function createTestRunner() {