UNPKG

@sasjs/cli

Version:

Command line interface for SASjs

307 lines (306 loc) 17 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (g && (g = 0, op[0] && (_ = 0)), _) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); var path_1 = __importDefault(require("path")); var node_graphviz_1 = require("node-graphviz"); var test_1 = require("../../../utils/test"); var utils_1 = require("@sasjs/utils"); var generateDot_1 = require("../generateDot"); var utils_2 = require("../../../utils"); var types_1 = require("../../../types"); describe('sasjs doc lineage', function () { var appName = "test-app-doc-".concat((0, utils_1.generateTimestamp)()); var docOutputDefault = path_1.default.join(__dirname, appName, 'sasjsbuild', 'docs'); var defaultTarget; var defaultConfig; beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, test_1.createTestApp)(__dirname, appName)]; case 1: _a.sent(); return [4 /*yield*/, (0, utils_2.findTargetInConfiguration)('viya', types_1.TargetScope.Local)]; case 2: (defaultTarget = (_a.sent()).target); return [4 /*yield*/, (0, utils_2.getLocalConfig)()]; case 3: defaultConfig = _a.sent(); return [2 /*return*/]; } }); }); }); afterEach(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, utils_1.deleteFolder)(docOutputDefault)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); afterAll(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, test_1.removeTestApp)(__dirname, appName)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); it("should generate dot-files", function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, expect((0, generateDot_1.generateDot)(defaultTarget, defaultConfig)).resolves.toEqual({ outDirectory: docOutputDefault })]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.verifyDotFiles)(docOutputDefault)]; case 2: _a.sent(); return [2 /*return*/]; } }); }); }); it("should generate dot-files to ./my-docs-<timestamp>", function () { return __awaiter(void 0, void 0, void 0, function () { var docOutputProvided; return __generator(this, function (_a) { switch (_a.label) { case 0: docOutputProvided = path_1.default.join(__dirname, appName, "my-docs-".concat((0, utils_1.generateTimestamp)())); return [4 /*yield*/, expect((0, generateDot_1.generateDot)(defaultTarget, defaultConfig, docOutputProvided)).resolves.toEqual({ outDirectory: docOutputProvided })]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.verifyDotFiles)(docOutputProvided)]; case 2: _a.sent(); return [2 /*return*/]; } }); }); }); it("should generate dot-files to sasjsconfig.json's outDirectory", function () { return __awaiter(void 0, void 0, void 0, function () { var docOutputProvided, target; return __generator(this, function (_a) { switch (_a.label) { case 0: docOutputProvided = path_1.default.join(__dirname, appName, "xyz-".concat((0, utils_1.generateTimestamp)())); target = new utils_1.Target(__assign(__assign({}, defaultTarget.toJson()), { docConfig: { outDirectory: docOutputProvided } })); return [4 /*yield*/, expect((0, generateDot_1.generateDot)(target, defaultConfig)).resolves.toEqual({ outDirectory: docOutputProvided })]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.verifyDotFiles)(docOutputProvided)]; case 2: _a.sent(); return [2 /*return*/]; } }); }); }); it("should generate dot-files to default location having docConfig.outDirectory is empty", function () { return __awaiter(void 0, void 0, void 0, function () { var target; return __generator(this, function (_a) { switch (_a.label) { case 0: target = new utils_1.Target(__assign(__assign({}, defaultTarget.toJson()), { docConfig: { outDirectory: '' } })); return [4 /*yield*/, expect((0, generateDot_1.generateDot)(target, defaultConfig)).resolves.toEqual({ outDirectory: docOutputDefault })]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.verifyDotFiles)(docOutputDefault)]; case 2: _a.sent(); return [2 /*return*/]; } }); }); }); it("should generate dot-files custom jobs", function () { return __awaiter(void 0, void 0, void 0, function () { var target; return __generator(this, function (_a) { switch (_a.label) { case 0: target = new utils_1.Target(__assign(__assign({}, defaultTarget.toJson()), { jobConfig: { jobFolders: ['../testJobs'] } })); return [4 /*yield*/, expect((0, generateDot_1.generateDot)(target, defaultConfig)).resolves.toEqual({ outDirectory: docOutputDefault })]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.verifyDotFiles)(docOutputDefault)]; case 2: _a.sent(); return [4 /*yield*/, verifyCustomDotFiles(docOutputDefault)]; case 3: _a.sent(); return [2 /*return*/]; } }); }); }); it("should generate dot-files custom jobs having double qoutes", function () { return __awaiter(void 0, void 0, void 0, function () { var target; return __generator(this, function (_a) { switch (_a.label) { case 0: target = new utils_1.Target(__assign(__assign({}, defaultTarget.toJson()), { jobConfig: { jobFolders: ['../testJobHavingDoubleQoutes'] } })); return [4 /*yield*/, expect((0, generateDot_1.generateDot)(target, defaultConfig)).resolves.toEqual({ outDirectory: docOutputDefault })]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.verifyDotFiles)(docOutputDefault)]; case 2: _a.sent(); return [2 /*return*/]; } }); }); }); it("should generate dot-files custom jobs having back slashes", function () { return __awaiter(void 0, void 0, void 0, function () { var target; return __generator(this, function (_a) { switch (_a.label) { case 0: target = new utils_1.Target(__assign(__assign({}, defaultTarget.toJson()), { jobConfig: { jobFolders: ['../testJobHavingBackSlashes'] } })); return [4 /*yield*/, expect((0, generateDot_1.generateDot)(target, defaultConfig)).resolves.toEqual({ outDirectory: docOutputDefault })]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.verifyDotFiles)(docOutputDefault)]; case 2: _a.sent(); return [2 /*return*/]; } }); }); }); }); var verifyCustomDotFiles = function (docsFolder) { return __awaiter(void 0, void 0, void 0, function () { var dotCodeFile, dotFileContent, _a, nodes, edges, _b, _c, file1, file2, input1, input2, input3, input4, input5, output1, output2, output3, output4, param, nodeFileJobInit, nodeFileJobTerm, nodeInput1, nodeInput2, nodeInput3, nodeInput4, nodeInput5, nodeOutput1, nodeOutput2, nodeOutput3, nodeOutput4, nodeParam; return __generator(this, function (_d) { switch (_d.label) { case 0: dotCodeFile = path_1.default.join(docsFolder, 'data_lineage.dot'); return [4 /*yield*/, (0, utils_1.readFile)(dotCodeFile)]; case 1: dotFileContent = _d.sent(); _c = (_b = JSON).parse; return [4 /*yield*/, node_graphviz_1.graphviz.dot(dotFileContent, 'dot_json')]; case 2: _a = _c.apply(_b, [_d.sent()]), nodes = _a.objects, edges = _a.edges; file1 = 'jobinit.sas'.toUpperCase(); file2 = 'jobterm.sas'.toUpperCase(); input1 = 'LIB.test_input_1'.toUpperCase(); input2 = 'LIB.test_input_2'.toUpperCase(); input3 = 'LIBr.test_input_3'.toUpperCase(); input4 = 'LIBf.test_input_4'.toUpperCase(); input5 = 'LIBf.test_input_5'.toUpperCase(); output1 = 'LND.test_output_1'.toUpperCase(); output2 = 'LND.test_output_2'.toUpperCase(); output3 = 'LND.test_output_3'.toUpperCase(); output4 = 'LND.test_output_4'.toUpperCase(); param = 'BOTH.as_input_and_output'.toUpperCase(); nodeFileJobInit = nodes.find(function (node) { var _a; return (_a = node.label) === null || _a === void 0 ? void 0 : _a.includes(file1); }); nodeFileJobTerm = nodes.find(function (node) { var _a; return (_a = node.label) === null || _a === void 0 ? void 0 : _a.includes(file2); }); nodeInput1 = nodes.find(function (node) { return node.label === input1; }); nodeInput2 = nodes.find(function (node) { return node.label === input2; }); nodeInput3 = nodes.find(function (node) { return node.label === input3; }); nodeInput4 = nodes.find(function (node) { return node.label === input4; }); nodeInput5 = nodes.find(function (node) { return node.label === input5; }); nodeOutput1 = nodes.find(function (node) { return node.label === output1; }); nodeOutput2 = nodes.find(function (node) { return node.label === output2; }); nodeOutput3 = nodes.find(function (node) { return node.label === output3; }); nodeOutput4 = nodes.find(function (node) { return node.label === output4; }); nodeParam = nodes.find(function (node) { return node.label === param; }); // checking colors of same libs should be same expect(nodeInput1.color).toEqual(nodeInput2.color); expect(nodeInput4.color).toEqual(nodeInput5.color); expect(nodeInput1.color).not.toEqual(nodeInput4.color); expect(nodeInput1.color).not.toEqual(nodeInput3.color); expect(nodeOutput1.color).toEqual(nodeOutput2.color); expect(nodeOutput1.color).toEqual(nodeOutput3.color); expect(nodeOutput1.color).toEqual(nodeOutput4.color); expect(nodeParam.color).not.toEqual(nodeInput1.color); expect(nodeParam.color).not.toEqual(nodeInput4.color); expect(nodeParam.color).not.toEqual(nodeOutput1.color); // checking edges as per ./testjobs expect(findEdge(edges, nodeInput1, nodeFileJobInit)).toBeTruthy(); expect(findEdge(edges, nodeInput4, nodeFileJobInit)).toBeTruthy(); expect(findEdge(edges, nodeInput5, nodeFileJobInit)).toBeTruthy(); expect(findEdge(edges, nodeFileJobInit, nodeOutput1)).toBeTruthy(); expect(findEdge(edges, nodeInput1, nodeFileJobTerm)).toBeTruthy(); expect(findEdge(edges, nodeInput2, nodeFileJobTerm)).toBeTruthy(); expect(findEdge(edges, nodeInput3, nodeFileJobTerm)).toBeTruthy(); expect(findEdge(edges, nodeInput4, nodeFileJobTerm)).toBeTruthy(); expect(findEdge(edges, nodeFileJobTerm, nodeOutput1)).toBeTruthy(); expect(findEdge(edges, nodeFileJobTerm, nodeOutput2)).toBeTruthy(); expect(findEdge(edges, nodeFileJobTerm, nodeOutput3)).toBeTruthy(); expect(findEdge(edges, nodeFileJobTerm, nodeOutput4)).toBeTruthy(); expect(findEdge(edges, nodeParam, nodeFileJobTerm)).toBeTruthy(); expect(findEdge(edges, nodeFileJobInit, nodeParam)).toBeTruthy(); expect(findEdge(edges, nodeFileJobTerm, nodeParam)).toBeUndefined(); expect(findEdge(edges, nodeParam, nodeFileJobInit)).toBeUndefined(); return [2 /*return*/]; } }); }); }; function findEdge(edges, tail, head) { return edges.find(function (edge) { return edge.tail === tail._gvid && edge.head === head._gvid; }); }