UNPKG

teamsfx-extension

Version:

Create, debug, and deploy Teams apps with Teams Toolkit

296 lines 16.9 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const chai = require("chai"); const path = require("path"); const fs = require("fs-extra"); const os = require("os"); const dotnetUtils = require("../utils/dotnet"); const common_1 = require("../../../../src/debug/depsChecker/common"); const checker_1 = require("../../../../src/debug/depsChecker/checker"); const dotnetChecker_1 = require("../../../../src/debug/depsChecker/dotnetChecker"); const testAdapter_1 = require("../adapters/testAdapter"); const testLogger_1 = require("../adapters/testLogger"); const testTelemetry_1 = require("../adapters/testTelemetry"); const common_2 = require("../utils/common"); function createTestChecker(hasTeamsfxBackend, clickCancel = false, dotnetCheckerEnabled = true, funcToolCheckerEnabled = true, nodeCheckerEnabled = true, customDotnetInstallScript = new testAdapter_1.CustomDotnetInstallScript()) { const testAdapter = new testAdapter_1.TestAdapter(hasTeamsfxBackend, clickCancel, dotnetCheckerEnabled, funcToolCheckerEnabled, nodeCheckerEnabled, customDotnetInstallScript); const dotnetChecker = new dotnetChecker_1.DotnetChecker(testAdapter, testLogger_1.logger, new testTelemetry_1.TestTelemetry()); const depsChecker = new checker_1.DepsChecker(testLogger_1.logger, testAdapter, [dotnetChecker]); return [depsChecker, dotnetChecker]; } suite("DotnetChecker E2E Test - first run", () => __awaiter(void 0, void 0, void 0, function* () { setup(function () { return __awaiter(this, void 0, void 0, function* () { yield dotnetUtils.cleanup(); // cleanup to make sure the environment is clean before test }); }); test(".NET SDK is not installed, whether globally or in home dir", function () { return __awaiter(this, void 0, void 0, function* () { if (yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand)) { this.skip(); } const [checker, _] = createTestChecker(true); const shouldContinue = yield checker.resolve(); const dotnetExecPath = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); // should continue because this is the case where the user clicks continue chai.assert.isTrue(shouldContinue); if (common_1.isLinux()) { chai.assert.isNull(dotnetExecPath); } else { chai.assert.isNotNull(dotnetExecPath); chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(dotnetExecPath, dotnetUtils.dotnetInstallVersion)); } }); }); test(".NET SDK is not installed and the user clicks cancel on Linux", function () { return __awaiter(this, void 0, void 0, function* () { if (!(common_1.isLinux() && !(yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand)))) { this.skip(); } const [checker, dotnetChecker] = createTestChecker(true, true); const shouldContinue = yield checker.resolve(); const dotnetExecPathFromConfig = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); const dotnetExecPath = yield dotnetChecker.getDotnetExecPath(); chai.assert.isFalse(shouldContinue); chai.assert.isNull(dotnetExecPathFromConfig); chai.assert.equal(dotnetExecPath, dotnetUtils.dotnetCommand); }); }); test(".NET SDK supported version is installed globally", function () { return __awaiter(this, void 0, void 0, function* () { if (!(yield dotnetUtils.hasAnyDotnetVersions(dotnetUtils.dotnetCommand, dotnetUtils.dotnetSupportedVersions))) { this.skip(); } const dotnetFullPath = yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand); chai.assert.isNotNull(dotnetFullPath); const [checker, dotnetChecker] = createTestChecker(true); const shouldContinue = yield checker.resolve(); chai.assert.isTrue(shouldContinue); const dotnetExecPathFromConfig = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); chai.assert.isNotNull(dotnetExecPathFromConfig); chai.assert.isTrue(yield dotnetUtils.hasAnyDotnetVersions(dotnetExecPathFromConfig, dotnetUtils.dotnetSupportedVersions)); // test dotnet executable is from config file. const dotnetExecPath = yield dotnetChecker.getDotnetExecPath(); common_2.assertPathEqual(dotnetExecPathFromConfig, dotnetExecPath); }); }); test(".NET SDK is too old", function () { return __awaiter(this, void 0, void 0, function* () { const has21 = yield dotnetUtils.hasDotnetVersion(dotnetUtils.dotnetCommand, dotnetUtils.dotnetOldVersion); const hasSupported = yield dotnetUtils.hasAnyDotnetVersions(dotnetUtils.dotnetCommand, dotnetUtils.dotnetSupportedVersions); if (!(has21 && !hasSupported)) { this.skip(); } chai.assert.isTrue(yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand)); const [checker, _] = createTestChecker(true); const shouldContinue = yield checker.resolve(); const dotnetExecPath = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); if (common_1.isLinux()) { chai.assert.isTrue(shouldContinue); chai.assert.isNull(dotnetExecPath); } else { chai.assert.isTrue(shouldContinue); chai.assert.isNotNull(dotnetExecPath); chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(dotnetExecPath, dotnetUtils.dotnetInstallVersion)); } }); }); test(".NET SDK not installed, for frontend-only projects", function () { return __awaiter(this, void 0, void 0, function* () { if (yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand)) { this.skip(); } const [checker, _] = createTestChecker(false); const shouldContinue = yield checker.resolve(); const dotnetExecPath = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); chai.assert.isTrue(shouldContinue); if (common_1.isLinux()) { chai.assert.isNull(dotnetExecPath); } else { chai.assert.isNotNull(dotnetExecPath); chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(dotnetExecPath, dotnetUtils.dotnetInstallVersion)); } }); }); test("DotnetChecker feature flag", function () { return __awaiter(this, void 0, void 0, function* () { const [checker, dotnetChecker] = createTestChecker(true, false, false); const shouldContinue = yield checker.resolve(); chai.assert.isTrue(shouldContinue); const dotnetExecPathFromConfig = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); chai.assert.isNull(dotnetExecPathFromConfig); const dotnetExecPath = yield dotnetChecker.getDotnetExecPath(); chai.assert.equal(dotnetExecPath, dotnetUtils.dotnetCommand); }); }); test(".NET SDK installation failure and manually install", function () { return __awaiter(this, void 0, void 0, function* () { if (common_1.isLinux() || (yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand))) { this.skip(); } // DotnetChecker with mock dotnet-install script const [mockChecker, mockDotnetChecker] = createTestChecker(true, false, true, true, true, new testAdapter_1.CustomDotnetInstallScript(true, 1, "mock dotnet installing", "mock dotnet install failure")); const shouldContinue = yield mockChecker.resolve(); const dotnetExecPathFromConfig = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); const dotnetExecPath = yield mockDotnetChecker.getDotnetExecPath(); chai.assert.isFalse(shouldContinue); chai.assert.isNull(dotnetExecPathFromConfig); chai.assert.equal(dotnetExecPath, dotnetUtils.dotnetCommand); // DotnetChecker with correct dotnet-install script const [checker, dotnetChecker] = createTestChecker(true); // user manually install yield dotnetUtils.withDotnet(dotnetChecker, dotnetChecker_1.DotnetVersion.v31, true, (installedDotnetExecPath) => __awaiter(this, void 0, void 0, function* () { // pre-check installed dotnet works chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(installedDotnetExecPath, dotnetUtils.dotnetInstallVersion)); const shouldContinue = yield checker.resolve(); const dotnetExecPath = yield dotnetChecker.getDotnetExecPath(); chai.assert.isTrue(shouldContinue); common_2.assertPathEqual(dotnetExecPath, installedDotnetExecPath); chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(dotnetExecPath, dotnetUtils.dotnetInstallVersion)); })); }); }); suite("PowerShell ExecutionPolicy is default on Windows", () => __awaiter(void 0, void 0, void 0, function* () { if (!common_1.isWindows()) { return; } let originalExecutionPolicy = "Unrestricted"; setup(function () { return __awaiter(this, void 0, void 0, function* () { originalExecutionPolicy = yield common_2.getExecutionPolicyForCurrentUser(); yield common_2.setExecutionPolicyForCurrentUser("Restricted"); }); }); test(".NET SDK not installed and PowerShell ExecutionPolicy is default (Restricted) on Windows", function () { return __awaiter(this, void 0, void 0, function* () { if (yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand)) { this.skip(); } const [checker, _] = createTestChecker(false); const shouldContinue = yield checker.resolve(); const dotnetExecPath = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); chai.assert.isTrue(shouldContinue); chai.assert.isNotNull(dotnetExecPath); chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(dotnetExecPath, dotnetUtils.dotnetInstallVersion)); }); }); teardown(function () { return __awaiter(this, void 0, void 0, function* () { yield common_2.setExecutionPolicyForCurrentUser(originalExecutionPolicy); }); }); })); teardown(function () { return __awaiter(this, void 0, void 0, function* () { // cleanup to make sure the environment is clean yield dotnetUtils.cleanup(); }); }); })); suite("DotnetChecker E2E Test - second run", () => { setup(function () { return __awaiter(this, void 0, void 0, function* () { yield dotnetUtils.cleanup(); // cleanup to make sure the environment is clean before test }); }); test("Valid dotnet.json file", function () { return __awaiter(this, void 0, void 0, function* () { if (yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand)) { this.skip(); } const [checker, dotnetChecker] = createTestChecker(true); yield dotnetUtils.withDotnet(dotnetChecker, dotnetChecker_1.DotnetVersion.v31, false, (installedDotnetExecPath) => __awaiter(this, void 0, void 0, function* () { // pre-check installed dotnet works chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(installedDotnetExecPath, dotnetUtils.dotnetInstallVersion)); // setup config file yield fs.mkdirp(path.resolve(dotnetUtils.dotnetConfigPath, "..")); yield fs.writeJson(dotnetUtils.dotnetConfigPath, { dotnetExecutablePath: installedDotnetExecPath }, { encoding: "utf-8", spaces: 4, EOL: os.EOL, }); const shouldContinue = yield checker.resolve(); const dotnetExecPath = yield dotnetChecker.getDotnetExecPath(); chai.assert.isTrue(shouldContinue); common_2.assertPathEqual(dotnetExecPath, installedDotnetExecPath); chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(dotnetExecPath, dotnetUtils.dotnetInstallVersion)); })); }); }); test("Invalid dotnet.json file and .NET SDK not installed", function () { return __awaiter(this, void 0, void 0, function* () { if (yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand)) { this.skip(); } const invalidPath = "/this/path/does/not/exist"; // setup config file yield fs.mkdirp(path.resolve(dotnetUtils.dotnetConfigPath, "..")); yield fs.writeJson(dotnetUtils.dotnetConfigPath, { dotnetExecutablePath: invalidPath }, { encoding: "utf-8", spaces: 4, EOL: os.EOL, }); const [checker, dotnetChecker] = createTestChecker(true); const shouldContinue = yield checker.resolve(); const dotnetExecPath = yield dotnetChecker.getDotnetExecPath(); chai.assert.isTrue(shouldContinue); if (common_1.isLinux()) { // Don't use assertPathEqual because this path does not exist chai.assert.equal(dotnetExecPath, invalidPath); } else { chai.assert.isNotNull(dotnetExecPath); chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(dotnetExecPath, dotnetUtils.dotnetInstallVersion)); } }); }); test("Invalid dotnet.json file and .NET SDK installed", function () { return __awaiter(this, void 0, void 0, function* () { if (yield common_2.commandExistsInPath(dotnetUtils.dotnetCommand)) { this.skip(); } const [checker, dotnetChecker] = createTestChecker(true); yield dotnetUtils.withDotnet(dotnetChecker, dotnetChecker_1.DotnetVersion.v31, true, (installedDotnetExecPath) => __awaiter(this, void 0, void 0, function* () { const invalidPath = "/this/path/does/not/exist"; // setup config file yield fs.mkdirp(path.resolve(dotnetUtils.dotnetConfigPath, "..")); yield fs.writeJson(dotnetUtils.dotnetConfigPath, { dotnetExecutablePath: invalidPath }, { encoding: "utf-8", spaces: 4, EOL: os.EOL, }); const shouldContinue = yield checker.resolve(); const dotnetExecPath = yield dotnetChecker.getDotnetExecPath(); const dotnetExecPathFromConfig = yield dotnetUtils.getDotnetExecPathFromConfig(dotnetUtils.dotnetConfigPath); chai.assert.isTrue(shouldContinue); common_2.assertPathEqual(dotnetExecPath, installedDotnetExecPath); chai.assert.isNotNull(dotnetExecPathFromConfig); common_2.assertPathEqual(dotnetExecPath, dotnetExecPathFromConfig); chai.assert.isTrue(yield dotnetUtils.hasDotnetVersion(dotnetExecPath, dotnetUtils.dotnetInstallVersion)); })); }); }); teardown(function () { return __awaiter(this, void 0, void 0, function* () { // cleanup to make sure the environment is clean yield dotnetUtils.cleanup(); }); }); }); //# sourceMappingURL=dotnet.js.map