UNPKG

@sasjs/cli

Version:

Command line interface for SASjs

956 lines (955 loc) 48.5 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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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 utils_1 = require("@sasjs/utils"); var config_1 = require("../../../utils/config"); var test_1 = require("../../../utils/test"); var compileModule = __importStar(require("../compile")); var compileSingleFile_1 = require("../compileSingleFile"); var compileFile = __importStar(require("../internal/compileFile")); var utils_2 = require("../../../utils"); var compileCommand_1 = require("../compileCommand"); var error_1 = require("@sasjs/utils/error"); var compileTestFileModule = __importStar(require("../internal/compileTestFile")); describe('sasjs compile', function () { var sharedAppName; var appName; var target; var homedir = require('os').homedir(); beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: sharedAppName = "cli-tests-compile-".concat((0, utils_1.generateTimestamp)()); return [4 /*yield*/, (0, test_1.createTestApp)(homedir, sharedAppName)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: appName = "cli-tests-compile-".concat((0, utils_1.generateTimestamp)()); return [4 /*yield*/, (0, test_1.createTestApp)(__dirname, appName)]; case 1: _a.sent(); return [4 /*yield*/, (0, config_1.findTargetInConfiguration)('viya')]; case 2: target = (_a.sent()).target; jest.spyOn(compileModule, 'copyFilesToBuildFolder'); jest.spyOn(compileModule, 'compileJobsServicesTests'); 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, test_1.removeTestApp)(__dirname, appName)]; 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)(homedir, sharedAppName)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); it('it should compile project from sub folder', function () { return __awaiter(void 0, void 0, void 0, function () { var serviceFolder, testFile, wrongSasjsBuildFolder, correctSasjsBuildFolder, correctBuildFile; return __generator(this, function (_a) { switch (_a.label) { case 0: serviceFolder = path_1.default.join(process.projectDir, 'sasjs', 'services', 'admin'); testFile = 'dostuff.test.sas'; wrongSasjsBuildFolder = path_1.default.join(serviceFolder, 'sasjsbuild'); correctSasjsBuildFolder = path_1.default.join(process.currentDir, 'sasjsbuild'); correctBuildFile = path_1.default.join(correctSasjsBuildFolder, 'tests', 'services', 'admin', testFile); return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(serviceFolder, testFile), '')]; case 1: _a.sent(); process.currentDir = serviceFolder; return [4 /*yield*/, expect(compileModule.compile(target)).toResolve()]; case 2: _a.sent(); return [4 /*yield*/, expect((0, utils_1.folderExists)(wrongSasjsBuildFolder)).resolves.toEqual(false)]; case 3: _a.sent(); return [4 /*yield*/, expect((0, utils_1.folderExists)(correctSasjsBuildFolder)).resolves.toEqual(true)]; case 4: _a.sent(); return [4 /*yield*/, expect((0, utils_1.fileExists)(correctBuildFile)).resolves.toEqual(true)]; case 5: _a.sent(); return [2 /*return*/]; } }); }); }); it('should compile an uncompiled project', function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, expect(compileModule.compile(target)).toResolve()]; case 1: _a.sent(); expect(compileModule.copyFilesToBuildFolder).toHaveBeenCalled(); expect(compileModule.compileJobsServicesTests).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should compile an uncompiled project with absolute macroPaths', function () { return __awaiter(void 0, void 0, void 0, function () { var absolutePathToSharedApp; return __generator(this, function (_a) { switch (_a.label) { case 0: absolutePathToSharedApp = path_1.default.join(homedir, sharedAppName); return [4 /*yield*/, (0, test_1.updateConfig)({ macroFolders: ["".concat(absolutePathToSharedApp, "/sasjs/macros")] }, true)]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.updateTarget)({ macroFolders: ["".concat(absolutePathToSharedApp, "/sasjs/targets/viya/macros")] }, 'viya', true)]; case 2: _a.sent(); return [4 /*yield*/, expect(compileModule.compile(target)).toResolve()]; case 3: _a.sent(); expect(compileModule.copyFilesToBuildFolder).toHaveBeenCalled(); expect(compileModule.compileJobsServicesTests).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should compile project with having tilde in paths', function () { return __awaiter(void 0, void 0, void 0, function () { var tildePathToApp; return __generator(this, function (_a) { switch (_a.label) { case 0: tildePathToApp = path_1.default.join(__dirname, appName).replace(homedir, '~'); return [4 /*yield*/, (0, test_1.updateConfig)(prefixConfigWithPath(tildePathToApp), true)]; case 1: _a.sent(); return [4 /*yield*/, (0, test_1.updateTarget)(prefixTargetConfigWithPath(tildePathToApp), 'viya', true)]; case 2: _a.sent(); return [4 /*yield*/, expect(compileModule.compile(target)).toResolve()]; case 3: _a.sent(); expect(compileModule.copyFilesToBuildFolder).toHaveBeenCalled(); expect(compileModule.compileJobsServicesTests).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should compile an uncompiled project having no target', 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.removeAllTargetsFromConfigs)()]; case 1: _a.sent(); return [4 /*yield*/, expect(compileModule.compile({})).toResolve()]; case 2: _a.sent(); expect(compileModule.copyFilesToBuildFolder).toHaveBeenCalled(); expect(compileModule.compileJobsServicesTests).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should fail to compile for missing program file', function () { return __awaiter(void 0, void 0, void 0, function () { var newTarget, errorMessage; return __generator(this, function (_a) { switch (_a.label) { case 0: newTarget = new utils_1.Target(__assign(__assign({}, target.toJson()), { serviceConfig: { serviceFolders: ['../services'] } })); errorMessage = "Unable to load dependencies for: ".concat(path_1.default.join(__dirname, 'services/example.sas'), "\n") + 'The following files were listed under SAS Includes but could not be found:\n' + "1. 'doesnotexist.sas' with fileRef 'SOMEREF'\n" + 'Please check that they exist in the folder(s) listed in the `programFolders` array in your sasjsconfig.json file.\n' + 'Program Folders:\n' + "- ".concat(path_1.default.join(__dirname, appName, 'sasjs/programs')); return [4 /*yield*/, expect(compileModule.compile(newTarget)).rejects.toThrow(errorMessage)]; case 1: _a.sent(); expect(compileModule.copyFilesToBuildFolder).toHaveBeenCalled(); expect(compileModule.compileJobsServicesTests).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should skip compilation if a project is already compiled', function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, expect(compileModule.compile(target)).toResolve()]; case 1: _a.sent(); expect(compileModule.copyFilesToBuildFolder).toHaveBeenCalled(); expect(compileModule.compileJobsServicesTests).toHaveBeenCalled(); jest.resetAllMocks(); return [4 /*yield*/, compileModule.compile(target)]; case 2: _a.sent(); expect(compileModule.copyFilesToBuildFolder).not.toHaveBeenCalled(); expect(compileModule.compileJobsServicesTests).not.toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should fail to compile if testSetUp is present and test file compilation failed', function () { return __awaiter(void 0, void 0, void 0, function () { var testSetUpFile, compileTestFileError, testTarget, expectedError; return __generator(this, function (_a) { switch (_a.label) { case 0: testSetUpFile = 'WRONG.sas'; compileTestFileError = "ENOENT: no such file or directory, open '".concat(testSetUpFile, "'"); testTarget = __assign({}, target); testTarget.testConfig = { testSetUp: testSetUpFile }; jest .spyOn(compileTestFileModule, 'compileTestFile') .mockImplementation(function () { return Promise.reject(compileTestFileError); }); expectedError = (0, error_1.prefixMessage)(compileTestFileError, 'Test set up compilation has failed. '); return [4 /*yield*/, expect(compileModule.compile(testTarget)).rejects.toEqual(expectedError)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); it('should fail to compile if testTearDown is present and test file compilation failed', function () { return __awaiter(void 0, void 0, void 0, function () { var testTearDownFile, compileTestFileError, testTarget, expectedError; return __generator(this, function (_a) { switch (_a.label) { case 0: testTearDownFile = 'WRONG.sas'; compileTestFileError = "ENOENT: no such file or directory, open '".concat(testTearDownFile, "'"); testTarget = __assign({}, target); testTarget.testConfig = { testTearDown: testTearDownFile }; jest .spyOn(compileTestFileModule, 'compileTestFile') .mockImplementation(function () { return Promise.reject(compileTestFileError); }); expectedError = (0, error_1.prefixMessage)(compileTestFileError, 'Test tear down compilation has failed. '); return [4 /*yield*/, expect(compileModule.compile(testTarget)).rejects.toEqual(expectedError)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); }); describe('sasjs compile single file', function () { var appName; var target; 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, test_1.removeTestApp)(__dirname, appName)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); describe('job', function () { beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: appName = "cli-tests-compile-".concat((0, utils_1.generateTimestamp)()); return [4 /*yield*/, (0, test_1.createTestJobsApp)(__dirname, appName)]; case 1: _a.sent(); return [4 /*yield*/, (0, config_1.findTargetInConfiguration)('viya')]; case 2: target = (_a.sent()).target; jest.spyOn(compileFile, 'compileFile'); return [2 /*return*/]; } }); }); }); it('should compile single file', function () { return __awaiter(void 0, void 0, void 0, function () { var command, output; return __generator(this, function (_a) { switch (_a.label) { case 0: command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'job', '-s', './jobs/extract/makedata1.sas' ]); return [4 /*yield*/, command.output]; case 1: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(target, 'job', command.source, output)).toResolve()]; case 2: _a.sent(); expect(compileFile.compileFile).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should compile single file with absolute path', function () { return __awaiter(void 0, void 0, void 0, function () { var command, output; return __generator(this, function (_a) { switch (_a.label) { case 0: command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'job', '-s', './jobs/extract/makedata1.sas' ]); return [4 /*yield*/, command.output]; case 1: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(target, 'job', command.source, output)).toResolve()]; case 2: _a.sent(); expect(compileFile.compileFile).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); }); describe('service', function () { beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: appName = "cli-tests-compile-".concat((0, utils_1.generateTimestamp)()); return [4 /*yield*/, (0, test_1.createTestApp)(__dirname, appName)]; case 1: _a.sent(); return [4 /*yield*/, (0, config_1.findTargetInConfiguration)('viya')]; case 2: target = (_a.sent()).target; jest.spyOn(compileFile, 'compileFile'); return [2 /*return*/]; } }); }); }); it('should compile single file', function () { return __awaiter(void 0, void 0, void 0, function () { var command, output; return __generator(this, function (_a) { switch (_a.label) { case 0: command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'service', '-s', 'sasjs/services/common/example.sas' ]); return [4 /*yield*/, command.output]; case 1: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(target, 'service', command.source, output)).toResolve()]; case 2: _a.sent(); expect(compileFile.compileFile).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should compile single file with absolute path', function () { return __awaiter(void 0, void 0, void 0, function () { var command, output; return __generator(this, function (_a) { switch (_a.label) { case 0: command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'service', '-s', "".concat(process.projectDir, "/sasjs/services/common/example.sas") ]); return [4 /*yield*/, command.output]; case 1: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(target, 'service', command.source, output)).toResolve()]; case 2: _a.sent(); expect(compileFile.compileFile).toHaveBeenCalled(); return [2 /*return*/]; } }); }); }); it('should compile service without duplicates', function () { return __awaiter(void 0, void 0, void 0, function () { var compiledPath, compiledService; return __generator(this, function (_a) { switch (_a.label) { case 0: compiledPath = path_1.default.join(process.projectDir, 'sasjsbuild', 'services', 'admin', 'dostuff.sas'); return [4 /*yield*/, compileModule.compile(target)]; case 1: _a.sent(); return [4 /*yield*/, (0, utils_1.readFile)(compiledPath)]; case 2: compiledService = _a.sent(); expect(compiledService.match(/%macro mv_webout/g).length).toEqual(1); return [2 /*return*/]; } }); }); }); }); }); var defaultBuildConfig = { buildOutputFileName: 'test.sas', initProgram: '', termProgram: '', macroVars: {} }; describe('sasjs compile outside project', function () { var sharedAppName; var appName; var parentOutputFolder; var homedir = require('os').homedir(); describe('with global config', function () { beforeAll(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: sharedAppName = "cli-tests-compile-".concat((0, utils_1.generateTimestamp)()); return [4 /*yield*/, (0, test_1.createTestApp)(homedir, sharedAppName)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () { var configuration; return __generator(this, function (_a) { switch (_a.label) { case 0: appName = "cli-tests-compile-".concat((0, utils_1.generateTimestamp)()); return [4 /*yield*/, (0, test_1.updateConfig)({ macroFolders: [ "./".concat(sharedAppName, "/sasjs/macros"), "./".concat(sharedAppName, "/sasjs/targets/viya/macros") ] }, false)]; case 1: _a.sent(); process.projectDir = ''; return [4 /*yield*/, (0, config_1.getGlobalRcFile)()]; case 2: configuration = _a.sent(); return [4 /*yield*/, (0, utils_2.setConstants)(false, undefined, configuration)]; case 3: _a.sent(); process.sasjsConfig = configuration; process.currentDir = path_1.default.join(__dirname, appName); return [4 /*yield*/, (0, utils_1.createFolder)(process.currentDir)]; case 4: _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, test_1.updateConfig)({ macroFolders: [], buildConfig: defaultBuildConfig }, false)]; case 1: _a.sent(); return [4 /*yield*/, (0, utils_1.deleteFolder)(parentOutputFolder)]; case 2: _a.sent(); return [4 /*yield*/, (0, utils_1.deleteFolder)(process.currentDir)]; case 3: _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)(homedir, sharedAppName)]; case 1: _a.sent(); return [4 /*yield*/, (0, utils_1.deleteFolder)(path_1.default.join(homedir, '.sasjs'))]; case 2: _a.sent(); return [2 /*return*/]; } }); }); }); it('should compile single file', function () { return __awaiter(void 0, void 0, void 0, function () { var buildOutputFolder, destinationPath, command, output, compiledContent, macrosToTest; return __generator(this, function (_a) { switch (_a.label) { case 0: buildOutputFolder = path_1.default.join(homedir, '.sasjs', 'sasjsbuild'); destinationPath = path_1.default.join(buildOutputFolder, 'services', 'services', 'example1.sas'); parentOutputFolder = buildOutputFolder; command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'service', '-s', '../services/example1.sas' ]); output = command.output; return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(undefined, 'service', command.source, output)).resolves.toEqual({ destinationPath: destinationPath })]; case 1: _a.sent(); return [4 /*yield*/, expect((0, utils_1.fileExists)(destinationPath)).resolves.toEqual(true)]; case 2: _a.sent(); return [4 /*yield*/, (0, utils_1.readFile)(destinationPath)]; case 3: compiledContent = _a.sent(); macrosToTest = [ 'mf_nobs', 'examplemacro', 'yetanothermacro' ]; return [4 /*yield*/, (0, test_1.verifyCompiledService)(compiledContent, macrosToTest, false, false)]; case 4: _a.sent(); return [2 /*return*/]; } }); }); }); it('should compile single file with absolute macroFolder paths', function () { return __awaiter(void 0, void 0, void 0, function () { var buildOutputFolder, destinationPath, absolutePathToSharedApp, command, output, compiledContent, macrosToTest; return __generator(this, function (_a) { switch (_a.label) { case 0: buildOutputFolder = path_1.default.join(homedir, '.sasjs', 'sasjsbuild'); destinationPath = path_1.default.join(buildOutputFolder, 'services', 'services', 'example1.sas'); absolutePathToSharedApp = path_1.default.join(homedir, sharedAppName); parentOutputFolder = buildOutputFolder; return [4 /*yield*/, (0, test_1.updateConfig)({ macroFolders: [ "".concat(absolutePathToSharedApp, "/sasjs/macros"), "".concat(absolutePathToSharedApp, "/sasjs/targets/viya/macros") ] }, false)]; case 1: _a.sent(); command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'service', '-s', '../services/example1.sas' ]); return [4 /*yield*/, command.output]; case 2: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(undefined, 'service', command.source, output)).resolves.toEqual({ destinationPath: destinationPath })]; case 3: _a.sent(); return [4 /*yield*/, expect((0, utils_1.fileExists)(destinationPath)).resolves.toEqual(true)]; case 4: _a.sent(); return [4 /*yield*/, (0, utils_1.readFile)(destinationPath)]; case 5: compiledContent = _a.sent(); macrosToTest = [ 'mf_nobs', 'examplemacro', 'yetanothermacro' ]; return [4 /*yield*/, (0, test_1.verifyCompiledService)(compiledContent, macrosToTest, false, false)]; case 6: _a.sent(); return [2 /*return*/]; } }); }); }); it('should fail to compile single file', function () { return __awaiter(void 0, void 0, void 0, function () { var buildOutputFolder, dependencies, configuration, command, output; return __generator(this, function (_a) { switch (_a.label) { case 0: buildOutputFolder = path_1.default.join(homedir, '.sasjs', 'sasjsbuild'); parentOutputFolder = buildOutputFolder; dependencies = ['examplemacro.sas', 'yetanothermacro.sas']; return [4 /*yield*/, (0, test_1.updateConfig)({ macroFolders: [] }, false)]; case 1: _a.sent(); return [4 /*yield*/, (0, config_1.getGlobalRcFile)()]; case 2: configuration = _a.sent(); process.sasjsConfig = configuration; command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'service', '-s', '../services/example1.sas' ]); return [4 /*yield*/, command.output]; case 3: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(undefined, 'service', command.source, output)).rejects.toEqual("Unable to locate dependencies: ".concat(dependencies.join(', ')))]; case 4: _a.sent(); return [2 /*return*/]; } }); }); }); it('should compile single file at absolute path in global config.sasjsBuildFolder', function () { return __awaiter(void 0, void 0, void 0, function () { var buildOutputFolder, destinationPath, configuration, command, output, compiledContent, macrosToTest; return __generator(this, function (_a) { switch (_a.label) { case 0: buildOutputFolder = path_1.default.join(__dirname, 'random-folder', appName); destinationPath = path_1.default.join(buildOutputFolder, 'services', 'services', 'example1.sas'); parentOutputFolder = path_1.default.join(__dirname, 'random-folder'); return [4 /*yield*/, (0, test_1.updateConfig)({ sasjsBuildFolder: buildOutputFolder, buildConfig: defaultBuildConfig }, false)]; case 1: _a.sent(); return [4 /*yield*/, (0, config_1.getGlobalRcFile)()]; case 2: configuration = _a.sent(); return [4 /*yield*/, (0, utils_2.setConstants)(false, undefined, configuration)]; case 3: _a.sent(); command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'service', '-s', '../services/example1.sas' ]); return [4 /*yield*/, command.output]; case 4: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(undefined, 'service', command.source, output)).resolves.toEqual({ destinationPath: destinationPath })]; case 5: _a.sent(); return [4 /*yield*/, expect((0, utils_1.fileExists)(destinationPath)).resolves.toEqual(true)]; case 6: _a.sent(); return [4 /*yield*/, (0, utils_1.readFile)(destinationPath)]; case 7: compiledContent = _a.sent(); macrosToTest = [ 'mf_nobs', 'examplemacro', 'yetanothermacro' ]; return [4 /*yield*/, (0, test_1.verifyCompiledService)(compiledContent, macrosToTest, false, false)]; case 8: _a.sent(); return [2 /*return*/]; } }); }); }); it('should compile single file at relative path in global config.sasjsBuildFolder', function () { return __awaiter(void 0, void 0, void 0, function () { var buildOutputFolder, destinationPath, configuration, command, output, compiledContent, macrosToTest; return __generator(this, function (_a) { switch (_a.label) { case 0: buildOutputFolder = path_1.default.join(homedir, appName, 'random-folder'); destinationPath = path_1.default.join(buildOutputFolder, 'services', 'services', 'example1.sas'); parentOutputFolder = path_1.default.join(homedir, appName); return [4 /*yield*/, (0, test_1.updateConfig)({ sasjsBuildFolder: appName + '/random-folder', buildConfig: defaultBuildConfig }, false)]; case 1: _a.sent(); return [4 /*yield*/, (0, config_1.getGlobalRcFile)()]; case 2: configuration = _a.sent(); return [4 /*yield*/, (0, utils_2.setConstants)(false, undefined, configuration)]; case 3: _a.sent(); command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'service', '-s', '../services/example1.sas' ]); return [4 /*yield*/, command.output]; case 4: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(undefined, 'service', command.source, output)).resolves.toEqual({ destinationPath: destinationPath })]; case 5: _a.sent(); return [4 /*yield*/, expect((0, utils_1.fileExists)(destinationPath)).resolves.toEqual(true)]; case 6: _a.sent(); return [4 /*yield*/, (0, utils_1.readFile)(destinationPath)]; case 7: compiledContent = _a.sent(); macrosToTest = [ 'mf_nobs', 'examplemacro', 'yetanothermacro' ]; return [4 /*yield*/, (0, test_1.verifyCompiledService)(compiledContent, macrosToTest, false, false)]; case 8: _a.sent(); return [2 /*return*/]; } }); }); }); }); describe('without global config', function () { beforeEach(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { case 0: appName = "cli-tests-compile-".concat((0, utils_1.generateTimestamp)()); return [4 /*yield*/, (0, config_1.saveGlobalRcFile)('')]; case 1: _a.sent(); return [4 /*yield*/, (0, utils_2.setConstants)(false)]; case 2: _a.sent(); process.sasjsConfig = {}; process.projectDir = ''; process.currentDir = path_1.default.join(__dirname, appName); return [4 /*yield*/, (0, utils_1.createFolder)(process.currentDir)]; case 3: _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)(process.currentDir)]; case 1: _a.sent(); return [2 /*return*/]; } }); }); }); it('should fail to compile single file', function () { return __awaiter(void 0, void 0, void 0, function () { var dependencies, command, output; return __generator(this, function (_a) { switch (_a.label) { case 0: dependencies = ['examplemacro.sas', 'yetanothermacro.sas']; command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', 'service', '-s', '../services/example1.sas' ]); return [4 /*yield*/, command.output]; case 1: output = _a.sent(); return [4 /*yield*/, expect((0, compileSingleFile_1.compileSingleFile)(undefined, 'service', command.source, output)).rejects.toEqual("Unable to locate dependencies: ".concat(dependencies.join(', ')))]; case 2: _a.sent(); return [2 /*return*/]; } }); }); }); it('should compile without duplicates', function () { return __awaiter(void 0, void 0, void 0, function () { var testServicePath, appPath, command, compiledTestService; var _a; return __generator(this, function (_b) { switch (_b.label) { case 0: testServicePath = path_1.default.join('services', 'admin', 'test.sas'); appPath = path_1.default.join(__dirname, appName); return [4 /*yield*/, (0, test_1.createTestApp)(__dirname, appName)]; case 1: _b.sent(); return [4 /*yield*/, (0, utils_1.createFile)(path_1.default.join(appPath, 'sasjs', 'targets', 'viya', testServicePath), '')]; case 2: _b.sent(); command = new compileCommand_1.CompileCommand([ 'node', 'sasjs', 'compile', '-t', 'viya' ]); return [4 /*yield*/, command.executeCompile()]; case 3: _b.sent(); return [4 /*yield*/, (0, utils_1.readFile)(path_1.default.join(appPath, 'sasjsbuild', testServicePath))]; case 4: compiledTestService = _b.sent(); expect((_a = compiledTestService.match(/^\*\sService start;$/gm)) === null || _a === void 0 ? void 0 : _a.length).toEqual(1); return [2 /*return*/]; } }); }); }); }); }); var prefixConfigWithPath = function (prefixPath) { return ({ buildConfig: { initProgram: "".concat(prefixPath, "/sasjs/build/buildinit.sas"), termProgram: "".concat(prefixPath, "/sasjs/build/buildterm.sas"), buildOutputFolder: "".concat(prefixPath, "/sasjsbuild"), buildResultsFolder: "".concat(prefixPath, "/sasjsresults"), macroVars: { name: 'value', numvar: '42' }, buildOutputFileName: 'undefined' }, deployConfig: { deployServicePack: false, deployScripts: ["".concat(prefixPath, "/sasjs/build/deployscript.sh")] }, serviceConfig: { serviceFolders: [ "".concat(prefixPath, "/sasjs/services/common"), "".concat(prefixPath, "/sasjs/services/admin") ], initProgram: "".concat(prefixPath, "/sasjs/build/serviceinit.sas"), termProgram: "".concat(prefixPath, "/sasjs/build/serviceterm.sas"), macroVars: { name: 'value', numvar: '42' } }, macroFolders: ["".concat(prefixPath, "/sasjs/macros")], programFolders: ["".concat(prefixPath, "/sasjs/programs")] }); }; var prefixTargetConfigWithPath = function (prefixPath) { return ({ buildConfig: { buildOutputFileName: 'myviyadeploy.sas', initProgram: "".concat(prefixPath, "/sasjs/build/buildinitviya.sas"), termProgram: "".concat(prefixPath, "/sasjs/targets/viya/viyabuildterm.sas"), macroVars: { name: 'viyavalue', extravar: 'this too' } }, deployConfig: { deployServicePack: true, deployScripts: ["".concat(prefixPath, "/sasjsbuild/myviyadeploy.sas")] }, serviceConfig: { serviceFolders: ["".concat(prefixPath, "/sasjs/targets/viya/services/admin")], initProgram: "".concat(prefixPath, "/sasjs/build/serviceinit.sas"), termProgram: "".concat(prefixPath, "/sasjs/build/serviceinit.sas"), macroVars: { name: 'viyavalue', extravar: 'this too' } }, macroFolders: ["".concat(prefixPath, "/sasjs/targets/viya/macros")] }); };