UNPKG

sleeveforarm

Version:
172 lines 9.22 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 chai_1 = require("chai"); const fs = require("fs-extra"); const Path = require("path"); const Request = require("request-promise-native"); const CliUtilities = require("../src/cliUtilities"); const CommonUtilities = require("../src/common-utilities"); const Resource = require("../src/resource"); // tslint:disable-next-line:max-line-length const WebappNodeAzureInfrastructure = require("../src/webapp-node-azureinfrastructure"); const TestUtilities = require("./testUtilities"); describe("Web app Node Azure", () => { before(function () { return __awaiter(this, void 0, void 0, function* () { this.timeout(60 * 1000); yield CommonUtilities.exec("npm link", Path.join(__dirname, "..")); }); }); let testingDirFullPath; let sleeveCommandLocation; let resourcesInEnvironment; beforeEach(function () { return __awaiter(this, void 0, void 0, function* () { [testingDirFullPath, sleeveCommandLocation] = yield TestUtilities.setupMochaTestLogging(this); }); }); afterEach(function () { return __awaiter(this, void 0, void 0, function* () { yield TestUtilities.tearDownMochaTestLogging(resourcesInEnvironment, testingDirFullPath, this); }); }); it("should be deployable", function () { return __awaiter(this, void 0, void 0, function* () { const deploymentType = Resource.DeployType.Production; this.timeout(15 * 60 * 1000); const webAppSamplePath = Path.join(testingDirFullPath, TestUtilities.generateRandomTestGroupName()); yield fs.emptyDir(webAppSamplePath); yield CommonUtilities.exec(`${sleeveCommandLocation} init`, webAppSamplePath); // tslint:disable-next-line:max-line-length yield CommonUtilities.exec(`${sleeveCommandLocation} setup -t webapp-node -n foo`, webAppSamplePath); yield CommonUtilities.exec(`${sleeveCommandLocation} \ setup -t mySqlAzure -n mySql`, webAppSamplePath); // Set up our test const fooPath = Path.join(webAppSamplePath, "foo"); yield CommonUtilities.exec("npm install mysql2 --save", fooPath); yield CommonUtilities.exec("npm link sleeveforarm", fooPath); const testAssetsPath = Path.join(__dirname, "..", "testAssets"); for (const fileName of ["index.ts", "deploy.cmd", ".deployment"]) { const fileToCopyPath = Path.join(testAssetsPath, fileName); yield fs.copy(fileToCopyPath, Path.join(fooPath, fileName), { overwrite: true }); } try { yield CommonUtilities.exec("tsc index.ts --target es6 --module commonjs --moduleResolution node > NUL", fooPath); } catch (err) { // TSC will fail because of spurious type failures, we can // ignore. If there is a real problem the next script will // fail. } // await CommonUtilities.exec(`${sleeveCommandLocation} deploy`, // webAppSamplePath); resourcesInEnvironment = yield CliUtilities.deployResources(webAppSamplePath, deploymentType, true); const webApp = resourcesInEnvironment.find((resource) => CommonUtilities.isClass(resource, WebappNodeAzureInfrastructure.WebappNodeAzureInfrastructure)); if (webApp === undefined) { throw new Error("We don't have a webApp in our results!"); } const baseDeployWebApp = yield webApp.getBaseDeployClassInstance(); const deployedURL = yield baseDeployWebApp.getDeployedURL(); yield getTheResult(deployedURL); const manageData = yield CliUtilities.getManageResourceData(webAppSamplePath); chai_1.expect(yield manageData[Resource.DeployType.Production]).to.have .string("https://ms.portal.azure.com/#resource/subscriptions/"); }); }); function waitAndTryAgain(url, httpGetResult, resolve, reject) { return __awaiter(this, void 0, void 0, function* () { setTimeout(function () { return __awaiter(this, void 0, void 0, function* () { try { yield getTheResult(url, httpGetResult); resolve(); } catch (err) { reject(err); } }); }, 5000); }); } function getTheResult(url, httpGetResult = "") { return __awaiter(this, void 0, void 0, function* () { httpGetResult = httpGetResult ? httpGetResult : "A Name"; return new Promise(function (resolve, reject) { return __awaiter(this, void 0, void 0, function* () { try { const getResult = yield Request.get(url); if (getResult === "Not Set!") { waitAndTryAgain(url, httpGetResult, resolve, reject); } else { try { chai_1.expect(getResult).equals(httpGetResult); resolve(); } catch (err) { reject(err); } } } catch (err) { // BUGBUG: Yes we will go into an endless loop if // all we get are ECONNREFUSED errors but eventually // the test itself times out. if (err.error.errno === "ECONNREFUSED") { // We made the request too quickly waitAndTryAgain(url, httpGetResult, resolve, reject); return; } throw err; } }); }); }); } it("should run locally", function () { return __awaiter(this, void 0, void 0, function* () { const deploymentType = Resource.DeployType.LocalDevelopment; this.timeout(10 * 60 * 1000); const webAppSamplePath = Path.join(testingDirFullPath, TestUtilities.generateRandomTestGroupName()); yield fs.emptyDir(webAppSamplePath); yield CommonUtilities.exec(`${sleeveCommandLocation} init`, webAppSamplePath); // await CliUtilities.init(webAppSamplePath); yield CommonUtilities.exec(`${sleeveCommandLocation} setup -t webapp-node -n foo`, webAppSamplePath); yield CommonUtilities.exec(`${sleeveCommandLocation} \ setup -t mySqlAzure -n mySql`, webAppSamplePath); resourcesInEnvironment = yield CliUtilities.deployResources(webAppSamplePath, deploymentType, false); // await CommonUtilities.exec(`${sleeveCommandLocation} deploy`, // webAppSamplePath); const fooPath = Path.join(webAppSamplePath, "foo"); yield CommonUtilities.exec("npm install mysql2 --save", fooPath); yield CommonUtilities.exec("npm link sleeveforarm", fooPath); const fileToCopy = Path.join(__dirname, "..", "testAssets", "index.ts"); yield fs.copy(fileToCopy, Path.join(fooPath, "index.ts"), { overwrite: true }); try { yield CommonUtilities.exec("tsc index.ts --target es6 --module commonjs --moduleResolution node > NUL", fooPath); } catch (err) { // TSC will fail because of spurious type failures, we can // ignore. If there is a real problem the next script will // fail. } CommonUtilities.exec("node index.js", fooPath); yield getTheResult("http://localhost:1337"); const manageData = yield CliUtilities.getManageResourceData(webAppSamplePath); chai_1.expect(manageData[Resource.DeployType.LocalDevelopment]).to.have .string("https://ms.portal.azure.com/#resource/subscriptions/"); }); }); }); //# sourceMappingURL=webapp-node-azureTest.js.map