@sasjs/cli 3.6.7 → 3.7.6

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.
@@ -1,2 +1,3 @@
1
1
  import { Target } from '@sasjs/utils';
2
2
  export declare function runTest(target: Target, testRegExps?: string[], outDirectory?: string, flowSourcePath?: string): Promise<undefined>;
3
+ export declare const getTestUrl: (target: Target, jobLocation: string) => string;
@@ -75,7 +75,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
75
75
  return (mod && mod.__esModule) ? mod : { "default": mod };
76
76
  };
77
77
  Object.defineProperty(exports, "__esModule", { value: true });
78
- exports.runTest = void 0;
78
+ exports.getTestUrl = exports.runTest = void 0;
79
79
  var saveOutput_1 = require("./internal/saveOutput");
80
80
  var types_1 = require("../../types");
81
81
  var file_1 = require("../../utils/file");
@@ -90,10 +90,10 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
90
90
  var _a, _b;
91
91
  if (testRegExps === void 0) { testRegExps = []; }
92
92
  return __awaiter(this, void 0, void 0, function () {
93
- var testFlowData, testFlow, flow, sasjs, authConfig, username, password, sas9CredentialsError, result, isCodeExamplePrinted, printCodeExample, jsonPath, xmlPath, _c, csvData, csvPath, coverageReportPath, resultTable, testsCount, passedTestsCount, testsWithResultsCount;
93
+ var testFlowData, testFlow, flow, sasjs, authConfig, username, password, _c, sas9CredentialsError, e_1, result, isCodeExamplePrinted, printCodeExample, jsonPath, xmlPath, _d, csvData, csvPath, coverageReportPath, resultTable, testsCount, passedTestsCount, testsWithResultsCount;
94
94
  var _this = this;
95
- return __generator(this, function (_d) {
96
- switch (_d.label) {
95
+ return __generator(this, function (_e) {
96
+ switch (_e.label) {
97
97
  case 0:
98
98
  if (outDirectory)
99
99
  outDirectory = path_1.default.join(process.currentDir, outDirectory);
@@ -109,7 +109,7 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
109
109
  return Promise.reject("Test flow file was not found at ".concat(flowSourcePath));
110
110
  })];
111
111
  case 1:
112
- testFlowData = _d.sent();
112
+ testFlowData = _e.sent();
113
113
  if (!testFlowData)
114
114
  return [2 /*return*/];
115
115
  testFlow = { tests: [] };
@@ -124,7 +124,7 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
124
124
  flow.push(testFlow.testSetUp);
125
125
  if (testFlow.tests)
126
126
  flow = __spreadArray(__spreadArray([], __read(flow), false), __read(testFlow.tests.filter(function (test) {
127
- var e_1, _a;
127
+ var e_2, _a;
128
128
  if (!testRegExps.length)
129
129
  return true;
130
130
  var match = false;
@@ -135,12 +135,12 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
135
135
  match = true;
136
136
  }
137
137
  }
138
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
138
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
139
139
  finally {
140
140
  try {
141
141
  if (testRegExps_1_1 && !testRegExps_1_1.done && (_a = testRegExps_1.return)) _a.call(testRegExps_1);
142
142
  }
143
- finally { if (e_1) throw e_1.error; }
143
+ finally { if (e_2) throw e_2.error; }
144
144
  }
145
145
  return match;
146
146
  })), false);
@@ -155,27 +155,43 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
155
155
  contextName: target.contextName,
156
156
  useComputeApi: false
157
157
  });
158
- if (!(target.serverType === utils_1.ServerType.SasViya)) return [3 /*break*/, 3];
159
- return [4 /*yield*/, (0, config_1.getAuthConfig)(target)];
160
- case 2:
161
- authConfig = _d.sent();
162
- _d.label = 3;
158
+ _c = target.serverType;
159
+ switch (_c) {
160
+ case utils_1.ServerType.SasViya: return [3 /*break*/, 2];
161
+ case utils_1.ServerType.Sas9: return [3 /*break*/, 4];
162
+ case utils_1.ServerType.Sasjs: return [3 /*break*/, 5];
163
+ }
164
+ return [3 /*break*/, 9];
165
+ case 2: return [4 /*yield*/, (0, config_1.getAuthConfig)(target)];
163
166
  case 3:
164
- if (target.serverType === utils_1.ServerType.Sas9) {
165
- if (target.authConfigSas9) {
166
- username = target.authConfigSas9.userName;
167
- password = target.authConfigSas9.password;
168
- }
169
- else {
170
- username = process.env.SAS_USERNAME;
171
- password = process.env.SAS_PASSWORD;
172
- }
173
- if (!username || !password) {
174
- sas9CredentialsError = process.sasjsConstants.sas9CredentialsError;
175
- throw new Error(sas9CredentialsError);
176
- }
177
- password = (0, utils_1.decodeFromBase64)(password);
167
+ authConfig = _e.sent();
168
+ return [3 /*break*/, 9];
169
+ case 4:
170
+ if (target.authConfigSas9) {
171
+ username = target.authConfigSas9.userName;
172
+ password = target.authConfigSas9.password;
173
+ }
174
+ else {
175
+ username = process.env.SAS_USERNAME;
176
+ password = process.env.SAS_PASSWORD;
177
+ }
178
+ if (!username || !password) {
179
+ sas9CredentialsError = process.sasjsConstants.sas9CredentialsError;
180
+ throw new Error(sas9CredentialsError);
178
181
  }
182
+ password = (0, utils_1.decodeFromBase64)(password);
183
+ return [3 /*break*/, 9];
184
+ case 5:
185
+ _e.trys.push([5, 7, , 8]);
186
+ return [4 /*yield*/, (0, config_1.getAuthConfig)(target)];
187
+ case 6:
188
+ authConfig = _e.sent();
189
+ return [3 /*break*/, 8];
190
+ case 7:
191
+ e_1 = _e.sent();
192
+ return [3 /*break*/, 8];
193
+ case 8: return [3 /*break*/, 9];
194
+ case 9:
179
195
  result = {
180
196
  sasjs_test_meta: []
181
197
  };
@@ -188,7 +204,7 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
188
204
  }
189
205
  };
190
206
  return [4 /*yield*/, (0, utils_1.asyncForEach)(flow, function (test) { return __awaiter(_this, void 0, void 0, function () {
191
- var sasJobLocation, testTarget, testId, testUrl, printTestUrl;
207
+ var sasJobLocation, testTarget, testId, testUrl, printTestUrl, handleRes;
192
208
  var _this = this;
193
209
  return __generator(this, function (_a) {
194
210
  switch (_a.label) {
@@ -202,101 +218,102 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
202
218
  .pop()
203
219
  .replace(/(.test)?(.\d+)?(.sas)?$/i, '');
204
220
  testId = (0, utils_1.uuidv4)();
205
- testUrl = "".concat(target.serverUrl, "/").concat(target.serverType === utils_1.ServerType.SasViya
206
- ? 'SASJobExecution'
207
- : 'SASStoredProcess', "/?_program=").concat(sasJobLocation, "&_debug=2477");
221
+ testUrl = (0, exports.getTestUrl)(target, sasJobLocation);
208
222
  if (target.contextName) {
209
223
  testUrl = "".concat(testUrl, "&_contextName=").concat(encodeURIComponent(target.contextName));
210
224
  }
211
225
  printTestUrl = function () { return process.logger.info("Test URL: ".concat(testUrl)); };
212
226
  printTestUrl();
213
- return [4 /*yield*/, sasjs
214
- .request(sasJobLocation, {}, { username: username, password: password }, function () {
215
- (0, displayResult_1.displayError)(null, 'Login callback called. Request failed.');
216
- }, authConfig, ['log'])
217
- .then(function (res) { return __awaiter(_this, void 0, void 0, function () {
218
- var lineBreak, existingTestTarget, existingTestTarget;
219
- var _a, _b;
220
- return __generator(this, function (_c) {
221
- switch (_c.label) {
222
- case 0:
223
- lineBreak = true;
224
- if (!res.result) {
225
- (0, displayResult_1.displayError)({}, "Job did not return a response, to debug click ".concat(testUrl));
226
- printCodeExample();
227
- lineBreak = false;
228
- existingTestTarget = result.sasjs_test_meta.find(function (testResult) {
229
- return testResult.test_target === testTarget;
227
+ handleRes = function (res) { return __awaiter(_this, void 0, void 0, function () {
228
+ var lineBreak, existingTestTarget, existingTestTarget;
229
+ var _a, _b;
230
+ return __generator(this, function (_c) {
231
+ switch (_c.label) {
232
+ case 0:
233
+ lineBreak = true;
234
+ if (!res.result) {
235
+ (0, displayResult_1.displayError)({}, "Job did not return a response, to debug click ".concat(testUrl));
236
+ printCodeExample();
237
+ lineBreak = false;
238
+ existingTestTarget = result.sasjs_test_meta.find(function (testResult) { return testResult.test_target === testTarget; });
239
+ if (existingTestTarget) {
240
+ existingTestTarget.results.push({
241
+ test_loc: test,
242
+ sasjs_test_id: testId,
243
+ result: types_1.TestResultStatus.notProvided,
244
+ test_url: testUrl
230
245
  });
231
- if (existingTestTarget) {
232
- existingTestTarget.results.push({
233
- test_loc: test,
234
- sasjs_test_id: testId,
235
- result: types_1.TestResultStatus.notProvided,
236
- test_url: testUrl
237
- });
238
- }
239
- else {
240
- result.sasjs_test_meta.push({
241
- test_target: testTarget,
242
- results: [
243
- {
244
- test_loc: test,
245
- sasjs_test_id: testId,
246
- result: types_1.TestResultStatus.notProvided,
247
- test_url: testUrl
248
- }
249
- ]
250
- });
251
- }
252
246
  }
253
- if (!((_a = res.result) === null || _a === void 0 ? void 0 : _a.test_results))
254
- lineBreak = false;
255
- if (!res.log) return [3 /*break*/, 2];
256
- return [4 /*yield*/, (0, saveOutput_1.saveLog)(outDirectory, test, res.log, lineBreak)];
257
- case 1:
258
- _c.sent();
259
- _c.label = 2;
260
- case 2:
261
- if ((_b = res.result) === null || _b === void 0 ? void 0 : _b.test_results) {
262
- existingTestTarget = result.sasjs_test_meta.find(function (testResult) {
263
- return testResult.test_target === testTarget;
247
+ else {
248
+ result.sasjs_test_meta.push({
249
+ test_target: testTarget,
250
+ results: [
251
+ {
252
+ test_loc: test,
253
+ sasjs_test_id: testId,
254
+ result: types_1.TestResultStatus.notProvided,
255
+ test_url: testUrl
256
+ }
257
+ ]
258
+ });
259
+ }
260
+ }
261
+ if (!((_a = res.result) === null || _a === void 0 ? void 0 : _a.test_results))
262
+ lineBreak = false;
263
+ if (!res.log) return [3 /*break*/, 2];
264
+ return [4 /*yield*/, (0, saveOutput_1.saveLog)(outDirectory, test, res.log, lineBreak)];
265
+ case 1:
266
+ _c.sent();
267
+ _c.label = 2;
268
+ case 2:
269
+ if ((_b = res.result) === null || _b === void 0 ? void 0 : _b.test_results) {
270
+ existingTestTarget = result.sasjs_test_meta.find(function (testResult) { return testResult.test_target === testTarget; });
271
+ if (existingTestTarget) {
272
+ existingTestTarget.results.push({
273
+ test_loc: test,
274
+ sasjs_test_id: testId,
275
+ result: res.result.test_results,
276
+ test_url: testUrl
264
277
  });
265
- if (existingTestTarget) {
266
- existingTestTarget.results.push({
267
- test_loc: test,
268
- sasjs_test_id: testId,
269
- result: res.result.test_results,
270
- test_url: testUrl
271
- });
272
- }
273
- else {
274
- result.sasjs_test_meta.push({
275
- test_target: testTarget,
276
- results: [
277
- {
278
- test_loc: test,
279
- sasjs_test_id: testId,
280
- result: res.result.test_results,
281
- test_url: testUrl
282
- }
283
- ]
284
- });
285
- }
286
278
  }
287
279
  else {
288
- (0, displayResult_1.displayError)({}, "'test_results' not found in server response, to debug click ".concat(testUrl));
289
- printCodeExample();
280
+ result.sasjs_test_meta.push({
281
+ test_target: testTarget,
282
+ results: [
283
+ {
284
+ test_loc: test,
285
+ sasjs_test_id: testId,
286
+ result: res.result.test_results,
287
+ test_url: testUrl
288
+ }
289
+ ]
290
+ });
290
291
  }
291
- return [2 /*return*/];
292
- }
293
- });
294
- }); })
292
+ }
293
+ else if (target.serverType !== utils_1.ServerType.Sasjs) {
294
+ (0, displayResult_1.displayError)({}, "'test_results' not found in server response, to debug click ".concat(testUrl));
295
+ printCodeExample();
296
+ }
297
+ return [2 /*return*/];
298
+ }
299
+ });
300
+ }); };
301
+ return [4 /*yield*/, sasjs
302
+ .request(sasJobLocation, {}, { username: username, password: password }, function () {
303
+ (0, displayResult_1.displayError)(null, 'Login callback called. Request failed.');
304
+ }, authConfig, ['log'])
305
+ .then(handleRes)
295
306
  .catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
296
- var _a, _b;
297
- return __generator(this, function (_c) {
298
- switch (_c.label) {
307
+ var _a, _b, _c;
308
+ return __generator(this, function (_d) {
309
+ switch (_d.label) {
299
310
  case 0:
311
+ if (!(((_a = err.error) === null || _a === void 0 ? void 0 : _a.message) === 'Error: invalid Json string')) return [3 /*break*/, 2];
312
+ return [4 /*yield*/, handleRes({})];
313
+ case 1:
314
+ _d.sent();
315
+ return [2 /*return*/];
316
+ case 2:
300
317
  printTestUrl();
301
318
  if (err && err.errorCode === 404) {
302
319
  (0, utils_2.displaySasjsRunnerError)(username);
@@ -304,12 +321,12 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
304
321
  else {
305
322
  (0, displayResult_1.displayError)({}, "An error occurred while executing the request. Job location: ".concat(sasJobLocation));
306
323
  }
307
- if (!((_b = (_a = err === null || err === void 0 ? void 0 : err.error) === null || _a === void 0 ? void 0 : _a.details) === null || _b === void 0 ? void 0 : _b.result)) return [3 /*break*/, 2];
324
+ if (!((_c = (_b = err === null || err === void 0 ? void 0 : err.error) === null || _b === void 0 ? void 0 : _b.details) === null || _c === void 0 ? void 0 : _c.result)) return [3 /*break*/, 4];
308
325
  return [4 /*yield*/, (0, saveOutput_1.saveLog)(outDirectory, test, err.error.details.result)];
309
- case 1:
310
- _c.sent();
311
- _c.label = 2;
312
- case 2: return [2 /*return*/];
326
+ case 3:
327
+ _d.sent();
328
+ _d.label = 4;
329
+ case 4: return [2 /*return*/];
313
330
  }
314
331
  });
315
332
  }); })];
@@ -319,22 +336,22 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
319
336
  }
320
337
  });
321
338
  }); })];
322
- case 4:
323
- _d.sent();
339
+ case 10:
340
+ _e.sent();
324
341
  return [4 /*yield*/, (0, saveOutput_1.saveResultJson)(outDirectory, result)];
325
- case 5:
326
- jsonPath = _d.sent();
342
+ case 11:
343
+ jsonPath = _e.sent();
327
344
  if (!jsonPath)
328
345
  return [2 /*return*/];
329
346
  return [4 /*yield*/, (0, saveOutput_1.saveResultXml)(outDirectory, result)];
330
- case 6:
331
- xmlPath = _d.sent();
347
+ case 12:
348
+ xmlPath = _e.sent();
332
349
  return [4 /*yield*/, (0, saveOutput_1.saveResultCsv)(outDirectory, result)];
333
- case 7:
334
- _c = _d.sent(), csvData = _c.csvData, csvPath = _c.csvPath;
350
+ case 13:
351
+ _d = _e.sent(), csvData = _d.csvData, csvPath = _d.csvPath;
335
352
  return [4 /*yield*/, (0, saveOutput_1.saveCoverageLcov)(outDirectory, flow)];
336
- case 8:
337
- coverageReportPath = _d.sent();
353
+ case 14:
354
+ coverageReportPath = _e.sent();
338
355
  resultTable = {};
339
356
  if (Array.isArray(csvData)) {
340
357
  csvData.forEach(function (item) {
@@ -367,3 +384,11 @@ function runTest(target, testRegExps, outDirectory, flowSourcePath) {
367
384
  });
368
385
  }
369
386
  exports.runTest = runTest;
387
+ var getTestUrl = function (target, jobLocation) {
388
+ return "".concat(target.serverUrl, "/").concat(target.serverType === utils_1.ServerType.SasViya
389
+ ? 'SASJobExecution'
390
+ : target.serverType === utils_1.ServerType.Sas9
391
+ ? 'SASStoredProcess'
392
+ : 'SASjsApi/stp/execute', "/?_program=").concat(jobLocation, "&_debug=2477");
393
+ };
394
+ exports.getTestUrl = getTestUrl;
package/package.json CHANGED
@@ -7,8 +7,6 @@
7
7
  ],
8
8
  "scripts": {
9
9
  "checkNodeVersion": "node -e \"console.log('\u001b[36m', 'Checking your Node.js version...'); if (!process.versions || !process.versions.node) { console.log('\u001b[31m', 'Error determining Node.js version. Exiting...') } if (parseInt(process.versions.node) < 14) { console.log('\u001b[31m', '❌ You must be running at least Node.js 14 to install SASjs CLI.\\nYour current version is ' + process.versions.node + '.\\nPlease install a more recent version and try again.'); process.exit(1); } else { console.log('\u001b[32m', '✅ Node.js version check passed. Continuing...'); } console.log('\u001b[0m', '');\"",
10
- "preinstall": "npm run checkNodeVersion -s",
11
- "prebuild": "npm run checkNodeVersion -s",
12
10
  "start": "nodemon --watch \"src/**/*\" --exec \"npm run build && npm run set:permissions\"",
13
11
  "set:permissions": "node -e \"require('fs').chmodSync('build/index.js', '755')\"",
14
12
  "build": "rimraf build && tsc -p . && npm run copy:files",
@@ -17,9 +15,9 @@
17
15
  "test": "npm run test:mocked && npm run test:server",
18
16
  "test:server": "jest --silent --runInBand --config=jest.server.config.js",
19
17
  "test:mocked": "jest --silent --runInBand --config=jest.config.js --coverage",
20
- "semantic-release": "semantic-release -d",
21
18
  "lint:fix": "npx prettier --write \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
22
19
  "lint": "npx prettier --check \"{src,test}/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
20
+ "preinstall": "npm run checkNodeVersion -s",
23
21
  "prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
24
22
  },
25
23
  "release": {
@@ -49,8 +47,8 @@
49
47
  "access": "public"
50
48
  },
51
49
  "dependencies": {
52
- "@sasjs/adapter": "3.4.2",
53
- "@sasjs/core": "3.10.0",
50
+ "@sasjs/adapter": "^3.7.3",
51
+ "@sasjs/core": "4.9.0",
54
52
  "@sasjs/lint": "1.11.2",
55
53
  "@sasjs/utils": "2.36.0",
56
54
  "chalk": "4.1.2",
@@ -90,12 +88,11 @@
90
88
  "jest-cli": "27.4.7",
91
89
  "jest-extended": "1.1.0",
92
90
  "nodemon": "2.0.15",
93
- "semantic-release": "17.4.7",
94
91
  "ts-jest": "27.1.2",
95
92
  "ts-node": "10.4.0",
96
93
  "tslib": "2.3.1",
97
94
  "typescript": "4.5.4",
98
95
  "util": "0.12.4"
99
96
  },
100
- "version": "3.6.7"
97
+ "version": "3.7.6"
101
98
  }