UNPKG

sleeveforarm

Version:
83 lines 3.83 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { 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) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs-extra"); const generatePassword = require("generate-password"); const Path = require("path"); const Winston = require("winston"); const CommonUtilities = require("../src/common-utilities"); const Data = require("../src/data"); // tslint:disable-next-line:max-line-length const ResourceGroupInfrastructure = require("../src/resourceGroupInfrastructure"); exports.testingDirParentPath = Path.join(__dirname, "..", "disposableTestFiles"); function generateLogPath(mochaThis) { return Path.join(exports.testingDirParentPath, mochaThis.currentTest.parent.title, mochaThis.currentTest.title); } function setupMochaTestLogging(mochaThis, emptyDir = true) { return __awaiter(this, void 0, void 0, function* () { const testingDirFullPath = generateLogPath(mochaThis); if (emptyDir) { yield fs.emptyDir(testingDirFullPath); } const logFilePath = Path.join(testingDirFullPath, "output.log"); Winston.add(Winston.transports.File, { filename: logFilePath, level: "silly" }); Winston.remove(Winston.transports.Console); Winston.add(Winston.transports.Console, { level: "silly", stderrLevels: [] }); const sleeveCommandLocation = Path.join(testingDirFullPath, "..", "..", "..", "src", "sleeveforarm.cmd"); return [testingDirFullPath, sleeveCommandLocation]; }); } exports.setupMochaTestLogging = setupMochaTestLogging; function tearDownMochaTestLogging(resourcesInEnvironment, testingDirFullPath, mochaState) { return __awaiter(this, void 0, void 0, function* () { Winston.remove(Winston.transports.File); for (const resource of resourcesInEnvironment) { if (CommonUtilities.isClass(resource, ResourceGroupInfrastructure.ResourceGroupInfrastructure)) { yield resource .deleteResource(); } } // If the test failed we want to keep the files and resources around // so we can investigate if (mochaState.currentTest.state !== "failed") { try { fs.removeSync(testingDirFullPath); } catch (err) { if (err.code !== "ENOTEMPTY" && err.code !== "EBUSY") { // The log file is still trying to write which // screws up the delete but it's o.k., all the // files are gone throw err; } } } }); } exports.tearDownMochaTestLogging = tearDownMochaTestLogging; function generateRandomTestGroupName() { return generatePassword.generate({ length: Data.data.ResourceGroupLength - Data.data.DataCenterAcronymLength - Data.data.DeploymentTypeIdLength, numbers: false, // so I just ban them completely. symbols: false, uppercase: false }); } exports.generateRandomTestGroupName = generateRandomTestGroupName; //# sourceMappingURL=testUtilities.js.map