@zohodesk/testinglibrary 0.0.1-exp.2 → 0.0.1-exp.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.0.1-exp.2",
3
+ "version": "0.0.1-exp.3",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -14,10 +14,9 @@
14
14
 
15
15
  const { spawn } = require('child_process');
16
16
  const path = require('path');
17
- const getFilePathWithExtension = require('../../../utils/getFilePath');
18
- const { getBinPath } = require('../../../utils/rootPath');
17
+ const { getExecutableBinaryPath } = require('../../../utils/rootPath');
19
18
 
20
- const jestPath = path.resolve(getBinPath(), getFilePathWithExtension('jest'));
19
+ const jestPath = path.resolve(getExecutableBinaryPath('jest'));
21
20
 
22
21
  // Command and arguments for npx playwright test
23
22
  const command = jestPath;
@@ -1,13 +1,12 @@
1
1
  const { spawn } = require('child_process')
2
2
  const path = require('path');
3
- const getFilePathWithExtension = require('../../utils/getFilePath');
4
3
  const { chromium } = require('@playwright/test');
5
4
  const { Logger } = require('../../utils/logger');
6
- const { getBinPath } = require('../../utils/rootPath');
5
+ const { getExecutableBinaryPath } = require('../../utils/rootPath');
7
6
 
8
7
  const userArgs = process.argv.slice(3);
9
8
 
10
- const playwrightPath = path.resolve(getBinPath(), getFilePathWithExtension('playwright'));
9
+ const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));
11
10
  const command = playwrightPath;
12
11
 
13
12
  const args = ['codegen'].concat(userArgs);
@@ -1,13 +1,12 @@
1
1
  const { spawn } = require('child_process');
2
2
  const path = require('path');
3
3
  const { Logger } = require('../../utils/logger');
4
- const getFilePathWithExtension = require('../../utils/getFilePath');
5
- const { getBinPath } = require('../../utils/rootPath');
4
+ const { getExecutableBinaryPath } = require('../../utils/rootPath');
6
5
 
7
6
 
8
7
  const userArgs = process.argv.slice(3);
9
8
 
10
- const playwrightPath = path.resolve(getBinPath(), getFilePathWithExtension('playwright'));;
9
+ const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));;
11
10
  const command = playwrightPath;
12
11
  const reportPath = path.resolve(process.cwd(), './playwright-report');
13
12
 
@@ -6,7 +6,7 @@ const { initializeEnvConfig } = require('./env-initializer');
6
6
  const { Logger } = require('../../utils/logger');
7
7
  const getFilePathWithExtension = require('../../utils/getFilePath');
8
8
  const generateConfigFromFile = require('./readConfigFile');
9
- const { getBinPath } = require('../../utils/rootPath');
9
+ const { getExecutableBinaryPath } = require('../../utils/rootPath');
10
10
 
11
11
 
12
12
 
@@ -25,7 +25,7 @@ generateConfigFromFile();
25
25
  const playwrightArgs = objectToCliArgs(userArgsObject, (key) => !CUSTOM_COMMANDS.includes(key));
26
26
 
27
27
  // Command and arguments for npx playwright test
28
- const playwrightPath = path.resolve(getBinPath(), getFilePathWithExtension('playwright'));
28
+ const playwrightPath = path.resolve(getExecutableBinaryPath('playwright'));
29
29
 
30
30
  const command = playwrightPath;
31
31
  const args = ['test', '--config', require.resolve('../../../playwright.config.js')].concat(playwrightArgs);
@@ -1,19 +1,21 @@
1
1
  const path = require('path')
2
2
  const fs = require('fs');
3
+ const { Logger } = require('./logger');
4
+ const getFilePathWithExtension = require('./getFilePath');
3
5
 
4
- function findBinaryPath(directory) {
5
- const binaryPath = path.join(directory, '.bin');
6
+ function findBinaryPath(directory, command) {
7
+ const binaryPath = path.join(directory, '.bin', getFilePathWithExtension(command));
6
8
  if (fs.existsSync(binaryPath)) {
7
9
  return binaryPath;
8
10
  }
9
11
 
10
- // Recursively search parent directories
12
+ // Recursively search parent directories. Might be time-consuming ?? Can we look for npm module like which?
11
13
  const parentDir = path.dirname(directory);
12
- if (parentDir !== directory) {
13
- return findBinaryPath(parentDir);
14
+ if (parentDir === directory) {
15
+ return null;
14
16
  }
15
17
 
16
- return null;
18
+ return findBinaryPath(parentDir);
17
19
  }
18
20
 
19
21
  function getRootPath() {
@@ -24,13 +26,26 @@ function getRootNodeModulesPath() {
24
26
  return path.resolve(getRootPath(), 'node_modules');
25
27
  }
26
28
 
27
- function getBinPath() {
29
+ function getBinPath(command) {
28
30
  const packageNodeModulesPath = getRootNodeModulesPath();
29
- return findBinaryPath(packageNodeModulesPath)
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
+ }
30
44
  }
31
45
 
32
46
  module.exports = {
33
47
  getRootPath,
34
48
  getBinPath,
35
- getRootNodeModulesPath
49
+ getRootNodeModulesPath,
50
+ getExecutableBinaryPath
36
51
  }