@zohodesk/testinglibrary 0.1.8-eslint-18 → 0.1.8-eslint-20

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 @@
1
+ {}
package/build/lib/cli.js CHANGED
@@ -59,9 +59,11 @@ switch (option) {
59
59
  case 'lint':
60
60
  {
61
61
  _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'Linting Started ...');
62
- (0, _eslintLintStage.runEslintForDiff)(otherOptions).finally(result => {
63
- (0, _startSeverSonarQube.runSonarAnalysis)(otherOptions);
64
- });
62
+ (async () => {
63
+ await (0, _eslintLintStage.runEslintForDiff)(otherOptions).finally(result => {
64
+ (0, _startSeverSonarQube.runSonarAnalysis)(otherOptions);
65
+ });
66
+ })();
65
67
  break;
66
68
  }
67
69
  case 'help':
@@ -17,6 +17,7 @@ var _logger = require("../utils/logger");
17
17
  var _cliArgsToObject = require("../utils/cliArgsToObject");
18
18
  var _fileUtils = require("../utils/fileUtils");
19
19
  var _requestJarAPI = require("./requestJarAPI");
20
+ var _console = require("console");
20
21
  async function runEslintForDiff(cliParams, options = {}) {
21
22
  // $(git diff --name-only HEAD HEAD~1 | grep -E '\.(js|jsx)$' | xargs)
22
23
  // await requestJAR(cliParams);
@@ -35,49 +36,60 @@ async function runEslintForDiff(cliParams, options = {}) {
35
36
  return await new Promise(resolve => {
36
37
  const command = ['eslint', lintFiles.join(' '), `--format=${format}`, '-o', `${reportPath}`];
37
38
  try {
38
- const lint_process = (0, _child_process.spawnSync)('npx', command, {
39
+ const lint_process = (0, _child_process.spawn)('npx', command, {
39
40
  shell: true,
40
41
  cwd: process.cwd()
41
42
  });
42
- if (lint_process.stderr) {
43
- _logger.Logger.log(_logger.Logger.FAILURE_TYPE, lint_process.stderr.toString());
44
- }
45
- if (lint_process.error) {
46
- throw lintFiles.error;
47
- }
43
+ lint_process.stdout.on('data', data => {
44
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, data);
45
+ });
46
+ lint_process.stderr.on('error', err => {
47
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, err);
48
+ });
49
+ lint_process.on('error', errors => {
50
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, errors);
51
+ });
52
+ lint_process.on('close', async onclose => {
53
+ if (diffPath && !(filteredDiffFiles.length === 0)) {
54
+ const filteredJson = await filterReport_JSON(require(reportPath), diffJSON);
55
+ (0, _fileUtils.writeFileContents)(reportPath, JSON.stringify(filteredJson));
56
+ }
57
+ resolve({
58
+ status: 'success'
59
+ });
60
+ });
48
61
  } catch (error) {
49
62
  _logger.Logger.log(_logger.Logger.INFO_TYPE, error);
50
63
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'Execution Failed');
51
- } finally {
52
- if (diffPath && !(filteredDiffFiles.length === 0)) {
53
- (0, _fileUtils.writeFileContents)(reportPath, filterReport_JSON(require(reportPath), diffJSON));
54
- }
55
- resolve({
56
- status: 'success'
57
- });
58
64
  }
59
65
  });
60
66
  }
61
67
  function filterReport_JSON(resultJson, diffJson) {
62
- const impactLineArray = filterDiffJson(diffJson);
63
- resultJson = resultJson.filter(result => {
64
- var _impactLineArray$get;
65
- const isImpactFile = getPathFromTestDir(result.filePath);
66
- if (!isImpactFile) {
67
- return false;
68
+ return new Promise(resolve => {
69
+ if (!diffJson) {
70
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'git diff json is not given ...');
71
+ resolve(false);
68
72
  }
69
- if (((_impactLineArray$get = impactLineArray.get(isImpactFile)) === null || _impactLineArray$get === void 0 ? void 0 : _impactLineArray$get.length) !== 0) {
70
- result.messages = result.messages.filter(errorMsg => {
71
- if (impactLineArray.get(isImpactFile).includes(errorMsg.line)) {
72
- return true;
73
- }
73
+ const impactLineArray = filterDiffJson(diffJson);
74
+ resultJson = resultJson.filter(result => {
75
+ var _impactLineArray$get;
76
+ const isImpactFile = getPathFromTestDir(result.filePath);
77
+ if (!isImpactFile) {
74
78
  return false;
75
- });
76
- return true;
77
- }
78
- return false;
79
+ }
80
+ if (((_impactLineArray$get = impactLineArray.get(isImpactFile)) === null || _impactLineArray$get === void 0 ? void 0 : _impactLineArray$get.length) !== 0) {
81
+ result.messages = result.messages.filter(errorMsg => {
82
+ if (impactLineArray.get(isImpactFile).includes(errorMsg.line)) {
83
+ return true;
84
+ }
85
+ return false;
86
+ });
87
+ return true;
88
+ }
89
+ return false;
90
+ });
91
+ resolve(resultJson);
79
92
  });
80
- return JSON.stringify(resultJson);
81
93
  }
82
94
  function filterDiffJson(diffJson) {
83
95
  var _diffJson$diffs;
@@ -130,8 +142,9 @@ function getDiffFiles(diffJson) {
130
142
  if (!diffJson) {
131
143
  return null;
132
144
  }
145
+ const rootPath = getRootLintPath();
133
146
  return diffJson === null || diffJson === void 0 ? void 0 : diffJson.diffs.map(diff => {
134
- return diff === null || diff === void 0 ? void 0 : diff.new_path;
147
+ return _path.default.resolve(rootPath, diff === null || diff === void 0 ? void 0 : diff.new_path);
135
148
  });
136
149
  }
137
150
  function getReportPath(reportPath = null, reportOptions = {}) {
@@ -142,7 +155,7 @@ function getDiffJsonPath(diffJsonPath) {
142
155
  return _path.default.resolve(diffJsonPath);
143
156
  }
144
157
  function gitDiffFiles() {
145
- const command = 'git diff --cached -U0 HEAD';
158
+ const command = 'git diff --cached -U0 HEAD --name-only';
146
159
  const child = (0, _child_process.spawnSync)(command, {
147
160
  shell: true
148
161
  });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ const {
4
+ spawn
5
+ } = require('child_process');
@@ -18,8 +18,8 @@ function getSummaryOfLint(cliParams) {
18
18
  lintEnv
19
19
  } = (0, _cliArgsToObject.cliArgsToObject)(cliParams);
20
20
  return {
21
- projectNameL: lintEnv === 'pre-commit' ? (0, _startSeverSonarQube.getProjectNameFrmGit)() : `${repo}_${branch},${username}`,
22
- reportUrl: `https://serverlinter.zohodesk.csez.zohocorpin.com/project/issues?id=${repo}_${branch}_${username}&resolve=false`,
21
+ projectName: lintEnv === 'pre-commit' ? (0, _startSeverSonarQube.getProjectNameFrmGit)() : `${repo}_${branch},${username}`,
22
+ reportUrl: `https://serverlinter-np.zohodesk.csez.zohocorpin.com/project/issues?id=${repo}_${branch}_${username}&resolve=false`,
23
23
  jsonReportPath: (0, _eslintLintStage.getReportPath)().toString()
24
24
  };
25
25
  }
@@ -14,6 +14,7 @@ var _cliArgsToObject = require("../utils/cliArgsToObject");
14
14
  var _sonarReportSummary = require("./sonarReportSummary");
15
15
  var _logger = require("../utils/logger");
16
16
  var _rootPath = require("../utils/rootPath");
17
+ var _fileUtils = require("../utils/fileUtils");
17
18
  // Js script to start sonar Server
18
19
 
19
20
  /**
@@ -22,7 +23,7 @@ var _rootPath = require("../utils/rootPath");
22
23
  */
23
24
 
24
25
  function runSonarAnalysis(cliParams) {
25
- var _getFilePathFrmReport, _getFilePathFrmReport2;
26
+ var _getFilePathFrmReport;
26
27
  const {
27
28
  diffPath,
28
29
  repo,
@@ -42,8 +43,9 @@ function runSonarAnalysis(cliParams) {
42
43
  if (lintEnv === 'pre-commit') {
43
44
  project_name = getProjectNameFrmGit();
44
45
  }
45
- var resultFilesPath = diffPath && !(lintEnv == 'pre-commit') ? (_getFilePathFrmReport = getFilePathFrmReport(require((0, _eslintLintStage.getReportPath)()))) === null || _getFilePathFrmReport === void 0 ? void 0 : _getFilePathFrmReport.stepFilesPath.join(',') : [`${_path.default.resolve(process.cwd(), 'uat', 'modules')}`].join(',');
46
- const source_directories = ((_getFilePathFrmReport2 = getFilePathFrmReport(require((0, _eslintLintStage.getReportPath)()))) === null || _getFilePathFrmReport2 === void 0 ? void 0 : _getFilePathFrmReport2.featureFilesPath) || [' '];
46
+ var resultFilesPath = diffPath ? (0, _eslintLintStage.getDiffFiles)(require((0, _eslintLintStage.getDiffJsonPath)(diffPath))).join(',') : [`${_path.default.resolve(process.cwd(), 'uat', 'modules')}`].join(',');
47
+ console.log('&&', (0, _fileUtils.checkIfFileExists)((0, _eslintLintStage.getReportPath)()));
48
+ const source_directories = ((_getFilePathFrmReport = getFilePathFrmReport(require((0, _eslintLintStage.getReportPath)()))) === null || _getFilePathFrmReport === void 0 ? void 0 : _getFilePathFrmReport.featureFilesPath) || [' '];
47
49
  const source_directories_str = lintEnv == 'pre-commit' ? ' ' : source_directories.join(',');
48
50
  if (lintEnv == 'pre-commit') {
49
51
  resultFilesPath = (0, _eslintLintStage.gitDiffFiles)().join(',');
@@ -88,7 +90,7 @@ function getRepoName() {
88
90
  return repoName.pop().split('/').pop().split('.')[0];
89
91
  }
90
92
  function getBranchName() {
91
- const branchName = getSpwanOutput('git', ['branch'])[1];
93
+ const branchName = getSpwanOutput('git', ['branch']).shift();
92
94
  if (branchName.startsWith('*')) {
93
95
  return branchName.replace('*', ' ').trim();
94
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.1.8-eslint-18",
3
+ "version": "0.1.8-eslint-20",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {