@zohodesk/testinglibrary 0.1.8-eslint-23 → 0.1.8-eslint-25

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.
@@ -50,7 +50,7 @@ async function runEslintForDiff(cliParams, options = {}) {
50
50
  });
51
51
  lint_process.on('close', async onclose => {
52
52
  if (diffPath && !(filteredDiffFiles.length === 0)) {
53
- const filteredJson = await filterReport_JSON(require(reportPath), diffJSON);
53
+ const filteredJson = await filterReportBasedDiff(require(reportPath), diffJSON);
54
54
  (0, _fileUtils.writeFileContents)(reportPath, JSON.stringify(filteredJson));
55
55
  }
56
56
  resolve({
@@ -63,29 +63,31 @@ async function runEslintForDiff(cliParams, options = {}) {
63
63
  }
64
64
  });
65
65
  }
66
- function filterReport_JSON(resultJson, diffJson) {
66
+ function filterReportBasedDiff(resultJson, diffJson) {
67
67
  return new Promise(resolve => {
68
68
  if (!diffJson) {
69
69
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'git diff json is not given ...');
70
70
  resolve(false);
71
71
  }
72
- const impactLineArray = filterDiffJson(diffJson);
72
+ const impactLineMap = filterDiffJson(diffJson);
73
73
  resultJson = resultJson.filter(result => {
74
- var _impactLineArray$get;
75
- const isImpactFile = getPathFromTestDir(result.filePath);
74
+ var _impactLineMap$get;
75
+ const isImpactFile = result.filePath;
76
+ if (isImpactFile.includes('.feature')) {
77
+ return false;
78
+ }
76
79
  if (!isImpactFile) {
77
80
  return false;
78
81
  }
79
- if (((_impactLineArray$get = impactLineArray.get(isImpactFile)) === null || _impactLineArray$get === void 0 ? void 0 : _impactLineArray$get.length) !== 0) {
82
+ if (((_impactLineMap$get = impactLineMap.get(isImpactFile)) === null || _impactLineMap$get === void 0 ? void 0 : _impactLineMap$get.length) !== 0) {
80
83
  result.messages = result.messages.filter(errorMsg => {
81
- if (impactLineArray.get(isImpactFile).includes(errorMsg.line)) {
84
+ if (impactLineMap.get(isImpactFile).includes(`${errorMsg.line}`)) {
82
85
  return true;
83
86
  }
84
87
  return false;
85
88
  });
86
89
  return true;
87
90
  }
88
- return false;
89
91
  });
90
92
  resolve(resultJson);
91
93
  });
@@ -100,7 +102,7 @@ function filterDiffJson(diffJson) {
100
102
  while ((match = regex.exec(diff.diff)) !== null) {
101
103
  diffMatch.push(...splitFilterNumber(match[1]));
102
104
  }
103
- const diffPathKey = getPathFromTestDir(diff.new_path);
105
+ const diffPathKey = _path.default.resolve(getRootLintPath(), diff.new_path);
104
106
  if (diffPathKey === undefined) {
105
107
  return;
106
108
  }
@@ -18,9 +18,13 @@ function getSummaryOfLint(cliParams) {
18
18
  username,
19
19
  lintEnv
20
20
  } = (0, _cliArgsToObject.cliArgsToObject)(cliParams);
21
+ var $projectName = `${repo}_${branch}_${username}`;
22
+ if (lintEnv === 'pre-commit') {
23
+ $projectName = (0, _startSeverSonarQube.getProjectNameFrmGit)();
24
+ }
21
25
  return {
22
- projectName: lintEnv === 'pre-commit' ? (0, _startSeverSonarQube.getProjectNameFrmGit)() : `${repo}_${branch},${username}`,
23
- reportUrl: `https://serverlinter-np.zohodesk.csez.zohocorpin.com/project/issues?id=${repo}_${branch}_${username}&resolve=false`,
26
+ projectName: $projectName,
27
+ reportUrl: `https://serverlinter-np.zohodesk.csez.zohocorpin.com/project/issues?id=${$projectName}&resolve=false`,
24
28
  jsonReportPath: (0, _eslintLintStage.getReportPath)().toString()
25
29
  };
26
30
  }
@@ -16,7 +16,6 @@ var _cliArgsToObject = require("../utils/cliArgsToObject");
16
16
  var _sonarReportSummary = require("./sonarReportSummary");
17
17
  var _logger = require("../utils/logger");
18
18
  var _rootPath = require("../utils/rootPath");
19
- var _fileUtils = require("../utils/fileUtils");
20
19
  var _popUpCli = require("./popUpCli");
21
20
  // Js script to start sonar Server
22
21
 
@@ -26,7 +25,7 @@ var _popUpCli = require("./popUpCli");
26
25
  */
27
26
 
28
27
  function runSonarAnalysis(cliParams) {
29
- var _getFilePathFrmReport;
28
+ var _filterSpecAndFeature, _filterSpecAndFeature2;
30
29
  const {
31
30
  diffPath,
32
31
  repo,
@@ -46,13 +45,17 @@ function runSonarAnalysis(cliParams) {
46
45
  if (lintEnv === 'pre-commit') {
47
46
  project_name = getProjectNameFrmGit();
48
47
  }
49
- var resultFilesPath = diffPath ? (0, _eslintLintStage.getDiffFiles)(require((0, _eslintLintStage.getDiffJsonPath)(diffPath))).join(',') : [`${_path.default.resolve(process.cwd(), 'uat', 'modules')}`].join(',');
50
- const source_directories = ((_getFilePathFrmReport = getFilePathFrmReport(require((0, _eslintLintStage.getReportPath)()))) === null || _getFilePathFrmReport === void 0 ? void 0 : _getFilePathFrmReport.featureFilesPath) || [' '];
51
- const source_directories_str = lintEnv == 'pre-commit' ? ' ' : source_directories.join(',');
48
+ console.log(filterSpecAndFeatureFiles((0, _eslintLintStage.getDiffFiles)(require((0, _eslintLintStage.getDiffJsonPath)(diffPath)))));
49
+ var resultFilesPath = diffPath ? (_filterSpecAndFeature = filterSpecAndFeatureFiles((0, _eslintLintStage.getDiffFiles)(require((0, _eslintLintStage.getDiffJsonPath)(diffPath))))) === null || _filterSpecAndFeature === void 0 ? void 0 : _filterSpecAndFeature.stepFilesPath.join(',') : [`${_path.default.resolve(process.cwd(), 'uat', 'modules')}`].join(',');
50
+ const source_directories = ((_filterSpecAndFeature2 = filterSpecAndFeatureFiles((0, _eslintLintStage.getDiffFiles)(require((0, _eslintLintStage.getDiffJsonPath)(diffPath))))) === null || _filterSpecAndFeature2 === void 0 ? void 0 : _filterSpecAndFeature2.featureFilesPath) || [' '];
52
51
  if (lintEnv == 'pre-commit') {
53
- resultFilesPath = (0, _eslintLintStage.gitDiffFiles)().join(',');
52
+ resultFilesPath = filterSpecAndFeatureFiles((0, _eslintLintStage.gitDiffFiles)()).stepFilesPath.join(',');
54
53
  }
55
- const command = ['-jar', sonar_scanner_path, `-Dsonar.host.url=${sonarqube_host_url}`, `-Dsonar.projectKey=${project_name}`, `-Dsonar.login=${Dlogin}`, `-Dsonar.password=${Dpassword}`, `-Dsonar.sources=${source_directories_str}`, `-Dsonar.tests=${resultFilesPath}`, '-Dsonar.language=js', `-Dsonar.working.directory=${getSonarArtifactsDir()}`, `-Dsonar.eslint.reportPaths=${(0, _eslintLintStage.getReportPath)()}`, '-Dsonar.javascript.lcov.reportPaths=coverage/lcov-report/lcov.info'];
54
+ if (lintEnv == 'pre-commit') {
55
+ source_directories = filterSpecAndFeatureFiles((0, _eslintLintStage.gitDiffFiles)()).featureFilesPath.join(',');
56
+ }
57
+ const command = ['-jar', sonar_scanner_path, `-Dsonar.host.url=${sonarqube_host_url}`, `-Dsonar.projectKey=${project_name}`, `-Dsonar.login=${Dlogin}`, `-Dsonar.password=${Dpassword}`, `-Dsonar.sources=${source_directories.join(',')}`, `-Dsonar.tests=${resultFilesPath}`, '-Dsonar.language=js', `-Dsonar.working.directory=${getSonarArtifactsDir()}`, `-Dsonar.eslint.reportPaths=${(0, _eslintLintStage.getReportPath)()}`, '-Dsonar.javascript.lcov.reportPaths=coverage/lcov-report/lcov.info'];
58
+ console.log(command);
56
59
  const child_process = (0, _child_process.spawn)('java', command);
57
60
  child_process.stdout.on('data', data => {
58
61
  _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, data);
@@ -79,12 +82,13 @@ function runSonarAnalysis(cliParams) {
79
82
  }
80
83
  });
81
84
  }
82
- function getFilePathFrmReport(resultJson) {
85
+ function filterSpecAndFeatureFiles(resultJson) {
83
86
  return resultJson.reduce((filesPath, fileReport) => {
84
- if (fileReport.filePath.includes('.feature')) {
85
- filesPath.featureFilesPath.push(fileReport.filePath);
87
+ if (fileReport.includes('.feature')) {
88
+ filesPath.featureFilesPath.push(fileReport);
89
+ } else {
90
+ filesPath.stepFilesPath.push(fileReport);
86
91
  }
87
- filesPath.stepFilesPath.push(fileReport.filePath);
88
92
  return filesPath;
89
93
  }, {
90
94
  stepFilesPath: [],
@@ -106,11 +110,11 @@ function getRepoName() {
106
110
  return repoName.pop().split('/').pop().split('.')[0];
107
111
  }
108
112
  function getBranchName() {
109
- const branchName = getSpawnOutput('git', ['branch'])[1]; // to get current branch
113
+ const branchName = getSpawnOutput('git', ['branch'])[0]; // to get current branch
110
114
  if (branchName.startsWith('*')) {
111
115
  return branchName.replace('*', ' ').trim();
112
116
  }
113
- return branchName;
117
+ return branchName.trim();
114
118
  }
115
119
  function getSpawnOutput(command, params = []) {
116
120
  const demon_process = (0, _child_process.spawnSync)(command, params, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.1.8-eslint-23",
3
+ "version": "0.1.8-eslint-25",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {