@zohodesk/testinglibrary 0.1.8-eslint-19 → 0.1.8-eslint-21

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/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':
@@ -16,7 +16,7 @@ var _path = _interopRequireDefault(require("path"));
16
16
  var _logger = require("../utils/logger");
17
17
  var _cliArgsToObject = require("../utils/cliArgsToObject");
18
18
  var _fileUtils = require("../utils/fileUtils");
19
- var _requestJarAPI = require("./requestJarAPI");
19
+ // import { requestJAR } from './requestJarAPI';
20
20
  async function runEslintForDiff(cliParams, options = {}) {
21
21
  // $(git diff --name-only HEAD HEAD~1 | grep -E '\.(js|jsx)$' | xargs)
22
22
  // await requestJAR(cliParams);
@@ -45,9 +45,13 @@ async function runEslintForDiff(cliParams, options = {}) {
45
45
  lint_process.stderr.on('error', err => {
46
46
  _logger.Logger.log(_logger.Logger.FAILURE_TYPE, err);
47
47
  });
48
- lint_process.on('close', onclose => {
48
+ lint_process.on('error', errors => {
49
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, errors);
50
+ });
51
+ lint_process.on('close', async onclose => {
49
52
  if (diffPath && !(filteredDiffFiles.length === 0)) {
50
- (0, _fileUtils.writeFileContents)(reportPath, filterReport_JSON(require(reportPath), diffJSON));
53
+ const filteredJson = await filterReport_JSON(require(reportPath), diffJSON);
54
+ (0, _fileUtils.writeFileContents)(reportPath, JSON.stringify(filteredJson));
51
55
  }
52
56
  resolve({
53
57
  status: 'success'
@@ -60,25 +64,31 @@ async function runEslintForDiff(cliParams, options = {}) {
60
64
  });
61
65
  }
62
66
  function filterReport_JSON(resultJson, diffJson) {
63
- const impactLineArray = filterDiffJson(diffJson);
64
- resultJson = resultJson.filter(result => {
65
- var _impactLineArray$get;
66
- const isImpactFile = getPathFromTestDir(result.filePath);
67
- if (!isImpactFile) {
68
- return false;
67
+ return new Promise(resolve => {
68
+ if (!diffJson) {
69
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'git diff json is not given ...');
70
+ resolve(false);
69
71
  }
70
- if (((_impactLineArray$get = impactLineArray.get(isImpactFile)) === null || _impactLineArray$get === void 0 ? void 0 : _impactLineArray$get.length) !== 0) {
71
- result.messages = result.messages.filter(errorMsg => {
72
- if (impactLineArray.get(isImpactFile).includes(errorMsg.line)) {
73
- return true;
74
- }
72
+ const impactLineArray = filterDiffJson(diffJson);
73
+ resultJson = resultJson.filter(result => {
74
+ var _impactLineArray$get;
75
+ const isImpactFile = getPathFromTestDir(result.filePath);
76
+ if (!isImpactFile) {
75
77
  return false;
76
- });
77
- return true;
78
- }
79
- return false;
78
+ }
79
+ if (((_impactLineArray$get = impactLineArray.get(isImpactFile)) === null || _impactLineArray$get === void 0 ? void 0 : _impactLineArray$get.length) !== 0) {
80
+ result.messages = result.messages.filter(errorMsg => {
81
+ if (impactLineArray.get(isImpactFile).includes(errorMsg.line)) {
82
+ return true;
83
+ }
84
+ return false;
85
+ });
86
+ return true;
87
+ }
88
+ return false;
89
+ });
90
+ resolve(resultJson);
80
91
  });
81
- return JSON.stringify(resultJson);
82
92
  }
83
93
  function filterDiffJson(diffJson) {
84
94
  var _diffJson$diffs;
@@ -131,13 +141,14 @@ function getDiffFiles(diffJson) {
131
141
  if (!diffJson) {
132
142
  return null;
133
143
  }
144
+ const rootPath = getRootLintPath();
134
145
  return diffJson === null || diffJson === void 0 ? void 0 : diffJson.diffs.map(diff => {
135
- return diff === null || diff === void 0 ? void 0 : diff.new_path;
146
+ return _path.default.resolve(rootPath, diff === null || diff === void 0 ? void 0 : diff.new_path);
136
147
  });
137
148
  }
138
149
  function getReportPath(reportPath = null, reportOptions = {}) {
139
150
  let jsonReportPath = reportPath || _path.default.resolve(process.cwd(), 'uat', 'lint-report', 'lintReport.json');
140
- return reportPath ? reportPath : jsonReportPath;
151
+ return jsonReportPath;
141
152
  }
142
153
  function getDiffJsonPath(diffJsonPath) {
143
154
  return _path.default.resolve(diffJsonPath);
@@ -1,5 +1,30 @@
1
1
  "use strict";
2
2
 
3
- const {
4
- spawn
5
- } = require('child_process');
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.showMsgPopUp = showMsgPopUp;
8
+ var _startSeverSonarQube = require("./startSever-sonarQube");
9
+ var _path = _interopRequireDefault(require("path"));
10
+ function showMsgPopUp(condition) {
11
+ // java -jar ./IDEMessagePluginRecent.jar project_name "BothStagedAndUnstaged" server_url java_version_output
12
+ const command = 'java';
13
+ const params = ['-jar', `${getPopupJarPath()}`, (0, _startSeverSonarQube.getProjectNameFrmGit)(), condition, 'java version 11'];
14
+ switch (condition) {
15
+ case 'NoIssueFound':
16
+ (0, _startSeverSonarQube.getSpawnOutput)(command, params);
17
+ break;
18
+ case 'IssueFound':
19
+ (0, _startSeverSonarQube.getSpawnOutput)(command, params);
20
+ break;
21
+ case 'BothStagedAndUnstaged':
22
+ (0, _startSeverSonarQube.getSpawnOutput)(command, params);
23
+ break;
24
+ default:
25
+ break;
26
+ }
27
+ }
28
+ function getPopupJarPath() {
29
+ return _path.default.resolve('node_modules', '@zohodesk', 'testinglibrary', 'build', 'lint-ci', 'java-jar', 'IDEMessagePluginRecent.jar');
30
+ }
@@ -4,6 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.getSummaryOfLint = getSummaryOfLint;
7
8
  exports.writeSummaryOfLint = writeSummaryOfLint;
8
9
  var _path = _interopRequireDefault(require("path"));
9
10
  var _fileUtils = require("../utils/fileUtils");
@@ -24,5 +25,8 @@ function getSummaryOfLint(cliParams) {
24
25
  };
25
26
  }
26
27
  function writeSummaryOfLint(cliParams) {
27
- (0, _fileUtils.writeFileContents)(_path.default.resolve(process.cwd(), 'uat', 'lint-report', 'lint-summary.json'), JSON.stringify(getSummaryOfLint(cliParams)));
28
+ (0, _fileUtils.writeFileContents)(_path.default.resolve(process.cwd(), 'uat', 'lint-report', 'lint-summary.json'), JSON.stringify({
29
+ ...getSummaryOfLint(cliParams),
30
+ ...(0, _startSeverSonarQube.getLintStatus)()
31
+ }));
28
32
  }
@@ -4,7 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
+ exports.getLintStatus = getLintStatus;
7
8
  exports.getProjectNameFrmGit = getProjectNameFrmGit;
9
+ exports.getSpawnOutput = getSpawnOutput;
8
10
  exports.runSonarAnalysis = runSonarAnalysis;
9
11
  var _path = _interopRequireDefault(require("path"));
10
12
  var _fs = _interopRequireDefault(require("fs"));
@@ -14,6 +16,8 @@ var _cliArgsToObject = require("../utils/cliArgsToObject");
14
16
  var _sonarReportSummary = require("./sonarReportSummary");
15
17
  var _logger = require("../utils/logger");
16
18
  var _rootPath = require("../utils/rootPath");
19
+ var _fileUtils = require("../utils/fileUtils");
20
+ var _popUpCli = require("./popUpCli");
17
21
  // Js script to start sonar Server
18
22
 
19
23
  /**
@@ -22,7 +26,7 @@ var _rootPath = require("../utils/rootPath");
22
26
  */
23
27
 
24
28
  function runSonarAnalysis(cliParams) {
25
- var _getFilePathFrmReport, _getFilePathFrmReport2;
29
+ var _getFilePathFrmReport;
26
30
  const {
27
31
  diffPath,
28
32
  repo,
@@ -42,8 +46,8 @@ function runSonarAnalysis(cliParams) {
42
46
  if (lintEnv === 'pre-commit') {
43
47
  project_name = getProjectNameFrmGit();
44
48
  }
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) || [' '];
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) || [' '];
47
51
  const source_directories_str = lintEnv == 'pre-commit' ? ' ' : source_directories.join(',');
48
52
  if (lintEnv == 'pre-commit') {
49
53
  resultFilesPath = (0, _eslintLintStage.gitDiffFiles)().join(',');
@@ -62,6 +66,22 @@ function runSonarAnalysis(cliParams) {
62
66
  child_process.on('close', code => {
63
67
  _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, `Lint Stage Executed & Status - ${code === 0 ? 'Success' : 'Failure'}`);
64
68
  (0, _sonarReportSummary.writeSummaryOfLint)(cliParams);
69
+ _logger.Logger.log(_logger.Logger.INFO_TYPE, `report url - ${(0, _sonarReportSummary.getSummaryOfLint)(cliParams).reportUrl}`);
70
+ if (lintEnv == 'pre-commit') {
71
+ _logger.Logger.log(_logger.Logger.SUCCESS_TYPE, 'lint triggered from pre-commit ...');
72
+ if (!getLintStatus().status && getLintStatus().message == 'failed') {
73
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'rules violated .. ');
74
+ (0, _popUpCli.showMsgPopUp)('IssueFound');
75
+ process.exit(0);
76
+ } else {
77
+ (0, _popUpCli.showMsgPopUp)('NoIssueFound');
78
+ }
79
+ if (!getLintStatus().status && getLintStatus().message == 'failed') {
80
+ _logger.Logger.log(_logger.Logger.FAILURE_TYPE, 'rules violated .. ');
81
+ (0, _popUpCli.showMsgPopUp)('IssueFound');
82
+ process.exit(0);
83
+ }
84
+ }
65
85
  });
66
86
  }
67
87
  function getFilePathFrmReport(resultJson) {
@@ -80,21 +100,21 @@ function getProjectNameFrmGit() {
80
100
  return `${getRepoName()}_${getBranchName()}_${getGitUsername()}`;
81
101
  }
82
102
  function getGitUsername() {
83
- const userName = getSpwanOutput('git', ['config', 'user.email']);
103
+ const userName = getSpawnOutput('git', ['config', 'user.email']);
84
104
  return userName.pop().split('@')[0];
85
105
  }
86
106
  function getRepoName() {
87
- const repoName = getSpwanOutput('git', ['remote', 'get-url', 'origin']);
107
+ const repoName = getSpawnOutput('git', ['remote', 'get-url', 'origin']);
88
108
  return repoName.pop().split('/').pop().split('.')[0];
89
109
  }
90
110
  function getBranchName() {
91
- const branchName = getSpwanOutput('git', ['branch'])[1];
111
+ const branchName = getSpawnOutput('git', ['branch']).shift();
92
112
  if (branchName.startsWith('*')) {
93
113
  return branchName.replace('*', ' ').trim();
94
114
  }
95
115
  return branchName;
96
116
  }
97
- function getSpwanOutput(command, params = []) {
117
+ function getSpawnOutput(command, params = []) {
98
118
  const demon_process = (0, _child_process.spawnSync)(command, params, {
99
119
  shell: true
100
120
  });
@@ -112,6 +132,39 @@ function getCredentials(login, password) {
112
132
  Dpassword: 'developer'
113
133
  };
114
134
  }
135
+ function getLintStatus() {
136
+ var reportStatus = true;
137
+ const report = require((0, _eslintLintStage.getReportPath)());
138
+ if (report.length == 0) {
139
+ reportStatus = true;
140
+ return {
141
+ status: true,
142
+ message: 'passed'
143
+ };
144
+ }
145
+ if (report.length != 0) {
146
+ for (i = 0; i < report.length; i++) {
147
+ if (fileReport.messages != 0 && fileReport.errorCount != 0) {
148
+ reportStatus = false;
149
+ break;
150
+ }
151
+ }
152
+ if (reportStatus) {
153
+ return {
154
+ status: reportStatus,
155
+ message: 'passed'
156
+ };
157
+ }
158
+ return {
159
+ status: reportStatus,
160
+ message: 'failed'
161
+ };
162
+ }
163
+ return {
164
+ status: reportStatus,
165
+ message: 'passed'
166
+ };
167
+ }
115
168
  function getSonarArtifactsDir() {
116
169
  return _path.default.resolve(process.cwd(), 'uat', 'lint-report', '.scannerwork');
117
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/testinglibrary",
3
- "version": "0.1.8-eslint-19",
3
+ "version": "0.1.8-eslint-21",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {