@sasjs/cli 3.1.0 → 3.4.1

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.
@@ -101,8 +101,8 @@ function getPreCodeForServicePack(serverType) {
101
101
  '/* so we provide instead as __program */\n' +
102
102
  '%global __program _program;\n' +
103
103
  '%let _program=%sysfunc(coalescec(&__program,&_program));\n' +
104
- '%macro webout(action,ds,dslabel=,fmt=);\n' +
105
- '%mv_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt)\n' +
104
+ '%macro webout(action,ds,dslabel=,fmt=,missing=NULL);\n' +
105
+ '%mv_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing)\n' +
106
106
  '%mend;\n';
107
107
  return [3 /*break*/, 14];
108
108
  case 5:
@@ -119,8 +119,8 @@ function getPreCodeForServicePack(serverType) {
119
119
  case 8:
120
120
  content = _g + _l.sent();
121
121
  content +=
122
- ' %macro webout(action,ds,dslabel=,fmt=);\n' +
123
- ' %mm_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt)\n' +
122
+ ' %macro webout(action,ds,dslabel=,fmt=,missing=NULL);\n' +
123
+ ' %mm_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing)\n' +
124
124
  ' %mend;\n';
125
125
  return [3 /*break*/, 14];
126
126
  case 9:
@@ -137,8 +137,8 @@ function getPreCodeForServicePack(serverType) {
137
137
  case 12:
138
138
  content = _k + _l.sent();
139
139
  content +=
140
- ' %macro webout(action,ds,dslabel=,fmt=);\n' +
141
- ' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt)\n' +
140
+ ' %macro webout(action,ds,dslabel=,fmt=,missing=NULL);\n' +
141
+ ' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing)\n' +
142
142
  ' %mend;\n';
143
143
  return [3 /*break*/, 14];
144
144
  case 13: throw new error_1.ServerTypeError();
@@ -119,8 +119,8 @@ describe('sasjs cbd with server type SASJS', function () {
119
119
  return [4 /*yield*/, utils_1.readFile(macroCorePath + "/server/ms_webout.sas")];
120
120
  case 7:
121
121
  ms_webout = _a.sent();
122
- webout = ' %macro webout(action,ds,dslabel=,fmt=);\n' +
123
- ' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt)\n' +
122
+ webout = ' %macro webout(action,ds,dslabel=,fmt=,missing=NULL);\n' +
123
+ ' %ms_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing)\n' +
124
124
  ' %mend;\n';
125
125
  expect(sasjs.deployToSASjs).toHaveBeenCalledWith({
126
126
  members: [
@@ -3,6 +3,7 @@ import { AuthConfig, Target } from '@sasjs/utils';
3
3
  import { ReturnCode } from '../../types/command';
4
4
  import { TargetCommand } from '../../types/command/targetCommand';
5
5
  export declare class JobCommand extends TargetCommand {
6
+ private jobSubCommands;
6
7
  constructor(args: string[]);
7
8
  execute(): Promise<ReturnCode>;
8
9
  executeJobSasjs(sasjs: SASjs, target: Target): Promise<ReturnCode>;
@@ -66,6 +66,7 @@ var execute_1 = require("./internal/execute");
66
66
  var JobSubCommand;
67
67
  (function (JobSubCommand) {
68
68
  JobSubCommand["Execute"] = "execute";
69
+ JobSubCommand["Exec"] = "exec";
69
70
  })(JobSubCommand || (JobSubCommand = {}));
70
71
  var syntax = 'job <subCommand> <jobPath> [options]';
71
72
  var usage = 'sasjs job <execute> <jobPath> [options]';
@@ -123,8 +124,11 @@ var JobCommand = /** @class */ (function (_super) {
123
124
  __extends(JobCommand, _super);
124
125
  function JobCommand(args) {
125
126
  var _this = this;
127
+ var jobSubCommands = Object.values(JobSubCommand);
126
128
  var subCommand = args[3];
127
- var parseOptions = subCommand === JobSubCommand.Execute ? executeParseOptions : {};
129
+ var parseOptions = jobSubCommands.includes(subCommand)
130
+ ? executeParseOptions
131
+ : {};
128
132
  _this = _super.call(this, args, {
129
133
  parseOptions: parseOptions,
130
134
  usage: usage,
@@ -132,6 +136,7 @@ var JobCommand = /** @class */ (function (_super) {
132
136
  examples: examples,
133
137
  syntax: syntax
134
138
  }) || this;
139
+ _this.jobSubCommands = jobSubCommands;
135
140
  return _this;
136
141
  }
137
142
  JobCommand.prototype.execute = function () {
@@ -166,7 +171,7 @@ var JobCommand = /** @class */ (function (_super) {
166
171
  authConfig = _e.sent();
167
172
  if (!authConfig)
168
173
  return [2 /*return*/, command_1.ReturnCode.InternalError];
169
- if (!(this.parsed.subCommand === JobSubCommand.Execute)) return [3 /*break*/, 5];
174
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 5];
170
175
  return [4 /*yield*/, this.executeJobViya(target, sasjs, authConfig)];
171
176
  case 4:
172
177
  _c = _e.sent();
@@ -182,7 +187,7 @@ var JobCommand = /** @class */ (function (_super) {
182
187
  });
183
188
  if (typeof this.parsed.jobPath !== 'string')
184
189
  return [2 /*return*/, command_1.ReturnCode.InvalidCommand];
185
- if (!(this.parsed.subCommand === JobSubCommand.Execute)) return [3 /*break*/, 9];
190
+ if (!this.jobSubCommands.includes(this.parsed.subCommand)) return [3 /*break*/, 9];
186
191
  return [4 /*yield*/, this.executeJobSasjs(sasjs, target)];
187
192
  case 8:
188
193
  _d = _e.sent();
@@ -362,17 +362,24 @@ var executeCalledWith = function (_a) {
362
362
  var executeCommandWrapper = function (additionalParams, checkTarget) {
363
363
  if (checkTarget === void 0) { checkTarget = true; }
364
364
  return __awaiter(void 0, void 0, void 0, function () {
365
- var args, command, returnCode, targetInfo;
365
+ var subCommand, args, command, returnCode, targetInfo;
366
366
  return __generator(this, function (_a) {
367
367
  switch (_a.label) {
368
368
  case 0:
369
- args = __spreadArray(__spreadArray([], __read(defaultArgs)), __read(additionalParams));
369
+ subCommand = 'execute';
370
+ args = __spreadArray(__spreadArray([], __read(defaultArgs)), __read(additionalParams)).map(function (arg) {
371
+ if (arg === 'execute') {
372
+ arg = Math.random() > 0.5 ? 'exec' : arg;
373
+ subCommand = arg;
374
+ }
375
+ return arg;
376
+ });
370
377
  command = new jobCommand_1.JobCommand(args);
371
378
  return [4 /*yield*/, command.execute()];
372
379
  case 1:
373
380
  returnCode = _a.sent();
374
381
  expect(command.name).toEqual('job');
375
- expect(command.subCommand).toEqual('execute');
382
+ expect(command.subCommand).toEqual(subCommand);
376
383
  if (!checkTarget) return [3 /*break*/, 3];
377
384
  return [4 /*yield*/, command.getTargetInfo()];
378
385
  case 2:
@@ -6,3 +6,4 @@ export declare const saveResultCsv: (outDirectory: string, result: TestResults,
6
6
  csvPath: string;
7
7
  }>;
8
8
  export declare const saveResultXml: (outDirectory: string, result: TestResults) => Promise<string>;
9
+ export declare const saveCoverageLcov: (outDirectory: string, tests: string[]) => Promise<string>;
@@ -60,7 +60,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
60
60
  return (mod && mod.__esModule) ? mod : { "default": mod };
61
61
  };
62
62
  Object.defineProperty(exports, "__esModule", { value: true });
63
- exports.saveResultXml = exports.saveResultCsv = exports.saveResultJson = exports.saveLog = void 0;
63
+ exports.saveCoverageLcov = exports.saveResultXml = exports.saveResultCsv = exports.saveResultJson = exports.saveLog = void 0;
64
64
  var path_1 = __importDefault(require("path"));
65
65
  var utils_1 = require("@sasjs/utils");
66
66
  var file_1 = require("../../../utils/file");
@@ -262,3 +262,43 @@ var saveResultXml = function (outDirectory, result) { return __awaiter(void 0, v
262
262
  });
263
263
  }); };
264
264
  exports.saveResultXml = saveResultXml;
265
+ var saveCoverageLcov = function (outDirectory, tests) { return __awaiter(void 0, void 0, void 0, function () {
266
+ var testsPrefixRegExp, coverageReport, coveringFile, filePath;
267
+ return __generator(this, function (_a) {
268
+ switch (_a.label) {
269
+ case 0:
270
+ testsPrefixRegExp = new RegExp("^tests/");
271
+ coverageReport = [];
272
+ coveringFile = function (filePath) { return __awaiter(void 0, void 0, void 0, function () {
273
+ return __generator(this, function (_a) {
274
+ switch (_a.label) {
275
+ case 0: return [4 /*yield*/, utils_1.fileExists(path_1.default.join(process.sasjsConstants.buildDestinationFolder, filePath))];
276
+ case 1: return [2 /*return*/, (_a.sent())
277
+ ? filePath
278
+ : 'standalone'];
279
+ }
280
+ });
281
+ }); };
282
+ return [4 /*yield*/, utils_1.asyncForEach(tests, function (test) { return __awaiter(void 0, void 0, void 0, function () {
283
+ var _a, _b, _c;
284
+ return __generator(this, function (_d) {
285
+ switch (_d.label) {
286
+ case 0:
287
+ _b = (_a = coverageReport).push;
288
+ _c = "TN:" + test.split('/').pop() + "\nSF:";
289
+ return [4 /*yield*/, coveringFile(test.replace(testsPrefixRegExp, '').replace(utils_1.testFileRegExp, '.sas'))];
290
+ case 1: return [2 /*return*/, _b.apply(_a, [_c + (_d.sent()) + "\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record"])];
291
+ }
292
+ });
293
+ }); })];
294
+ case 1:
295
+ _a.sent();
296
+ filePath = path_1.default.join(outDirectory, 'coverage.lcov');
297
+ return [4 /*yield*/, utils_1.createFile(filePath, coverageReport.join('\n'))];
298
+ case 2:
299
+ _a.sent();
300
+ return [2 /*return*/, filePath];
301
+ }
302
+ });
303
+ }); };
304
+ exports.saveCoverageLcov = saveCoverageLcov;
@@ -99,7 +99,7 @@ describe('sasjs test', function () {
99
99
  });
100
100
  }); });
101
101
  it('should execute tests and create result CSV, XML and JSON files using default source and output locations', function () { return __awaiter(void 0, void 0, void 0, function () {
102
- var expectedResultsJson, expectedResultsCsv, resultsFolderPath, resultsJsonPath, resultsJson, resultsCsvPath, parsedResults, resultsCsv, resultsXmlPath, resultsXml, expectedResultsXml;
102
+ var expectedResultsJson, expectedResultsCsv, resultsFolderPath, resultsJsonPath, resultsJson, resultsCsvPath, parsedResults, resultsCsv, resultsXmlPath, resultsXml, expectedResultsXml, coverageLcovPath, expectedCoverageLcov, coverageLcov;
103
103
  return __generator(this, function (_a) {
104
104
  switch (_a.label) {
105
105
  case 0:
@@ -232,6 +232,15 @@ describe('sasjs test', function () {
232
232
  resultsXml = resultsXml.replace(/testsuites id="[^ ]*"/gm, "testsuites id=\"\"");
233
233
  resultsXml = resultsXml.replace(/testcase id="[^ ]*"/gm, "testcase id=\"\"");
234
234
  expect(resultsXml).toEqual(expectedResultsXml);
235
+ coverageLcovPath = path_1.default.join(resultsFolderPath, 'coverage.lcov');
236
+ return [4 /*yield*/, expect(utils_1.fileExists(coverageLcovPath)).resolves.toEqual(true)];
237
+ case 9:
238
+ _a.sent();
239
+ expectedCoverageLcov = "TN:testsetup.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:exampleprogram.test.sas\nSF:jobs/jobs/exampleprogram.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:standalone.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:examplemacro.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:shouldFail.test.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:dostuff.test.0.sas\nSF:services/admin/dostuff.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:dostuff.test.1.sas\nSF:services/admin/dostuff.sas\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record\nTN:testteardown.sas\nSF:standalone\nFNF:1\nFNH:1\nLF:1\nLH:1\nBRF:1\nBRH:1\nend_of_record";
240
+ return [4 /*yield*/, utils_1.readFile(coverageLcovPath)];
241
+ case 10:
242
+ coverageLcov = _a.sent();
243
+ expect(coverageLcov).toEqual(expectedCoverageLcov);
235
244
  return [2 /*return*/];
236
245
  }
237
246
  });
@@ -86,7 +86,7 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
86
86
  var _a, _b;
87
87
  if (testRegExps === void 0) { testRegExps = []; }
88
88
  return __awaiter(this, void 0, void 0, function () {
89
- var testFlowData, testFlow, flow, sasjs, authConfig, username, password, sas9CredentialsError, result, isCodeExamplePrinted, printCodeExample, jsonPath, xmlPath, _c, csvData, csvPath, resultTable, testsCount, passedTestsCount, testsWithResultsCount;
89
+ var testFlowData, testFlow, flow, sasjs, authConfig, username, password, sas9CredentialsError, result, isCodeExamplePrinted, printCodeExample, jsonPath, xmlPath, _c, csvData, csvPath, coverageReportPath, resultTable, testsCount, passedTestsCount, testsWithResultsCount;
90
90
  var _this = this;
91
91
  return __generator(this, function (_d) {
92
92
  switch (_d.label) {
@@ -328,6 +328,9 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
328
328
  return [4 /*yield*/, saveOutput_1.saveResultCsv(outDirectory, result)];
329
329
  case 7:
330
330
  _c = _d.sent(), csvData = _c.csvData, csvPath = _c.csvPath;
331
+ return [4 /*yield*/, saveOutput_1.saveCoverageLcov(outDirectory, flow)];
332
+ case 8:
333
+ coverageReportPath = _d.sent();
331
334
  resultTable = {};
332
335
  if (Array.isArray(csvData)) {
333
336
  csvData.forEach(function (item) {
@@ -353,6 +356,7 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
353
356
  testsWithResultsCount = Object.values(resultTable).filter(function (res) { return res.test_suite_result !== types_1.TestResultStatus.notProvided; }).length;
354
357
  (_b = process.logger) === null || _b === void 0 ? void 0 : _b.info("Tests provided results: " + (testsWithResultsCount + '/' + testsCount) + " (" + chalk_1.default.greenBright(Math.round((testsWithResultsCount / testsCount) * 100 || 0) + '%') + ")\n Tests that pass: " + (passedTestsCount + '/' + testsWithResultsCount) + " (" + chalk_1.default.greenBright(Math.round((passedTestsCount / testsWithResultsCount) * 100 || 0) + '%') + ")\n ");
355
358
  displayResult_1.displaySuccess("Tests execution finished. The results are stored at:\n " + jsonPath + "\n " + csvPath + "\n " + xmlPath);
359
+ displayResult_1.displaySuccess("Tests coverage report:\n " + coverageReportPath);
356
360
  return [2 /*return*/];
357
361
  }
358
362
  });
package/package.json CHANGED
@@ -49,8 +49,8 @@
49
49
  "access": "public"
50
50
  },
51
51
  "dependencies": {
52
- "@sasjs/adapter": "3.3.0",
53
- "@sasjs/core": "2.54.1",
52
+ "@sasjs/adapter": "3.3.1",
53
+ "@sasjs/core": "^3.8.0",
54
54
  "@sasjs/lint": "1.11.2",
55
55
  "@sasjs/utils": "2.34.1",
56
56
  "chalk": "4.1.2",
@@ -97,5 +97,5 @@
97
97
  "typescript": "4.3.5",
98
98
  "util": "0.12.4"
99
99
  },
100
- "version": "3.1.0"
100
+ "version": "3.4.1"
101
101
  }