From fb8871cfbfdc50f493685e7e7a17a00ce210b2d1 Mon Sep 17 00:00:00 2001 From: Armando Trejo Oliver Date: Thu, 6 Apr 2023 10:13:05 -0700 Subject: [PATCH] Load Legacy Mongo Shell V2 by default (#1424) - Load Legacy Mongo Shell V2 by default - Add/Keep feature flags to load from portal BE and V1 - Skip code coverage if skipCodeCoverage environment variable is set to "true" --- jest.config.js | 3 +- .../MongoShellTab/getMongoShellOrigin.test.ts | 33 +++-- .../Tabs/MongoShellTab/getMongoShellOrigin.ts | 11 +- .../MongoShellTab/getMongoShellUrl.test.ts | 127 +++++++++++------- .../Tabs/MongoShellTab/getMongoShellUrl.ts | 19 +-- src/Platform/Hosted/extractFeatures.ts | 10 +- 6 files changed, 122 insertions(+), 81 deletions(-) diff --git a/jest.config.js b/jest.config.js index abce87358..6f1e875e0 100644 --- a/jest.config.js +++ b/jest.config.js @@ -18,7 +18,8 @@ module.exports = { // clearMocks: false, // Indicates whether the coverage information should be collected while executing the test - collectCoverage: true, + + collectCoverage: process.env.skipCodeCoverage === "true" ? false : true, // An array of glob patterns indicating a set of files for which coverage information should be collected collectCoverageFrom: ["src/**/*.{js,jsx,ts,tsx}"], diff --git a/src/Explorer/Tabs/MongoShellTab/getMongoShellOrigin.test.ts b/src/Explorer/Tabs/MongoShellTab/getMongoShellOrigin.test.ts index 4d3c5b668..7d3aa54de 100644 --- a/src/Explorer/Tabs/MongoShellTab/getMongoShellOrigin.test.ts +++ b/src/Explorer/Tabs/MongoShellTab/getMongoShellOrigin.test.ts @@ -12,18 +12,19 @@ describe("getMongoShellOrigin", () => { new URLSearchParams({ "feature.enableLegacyMongoShellV1": "false", "feature.enableLegacyMongoShellV2": "false", - "feature.enableLegacyMongoShellV1Dist": "false", - "feature.enableLegacyMongoShellV2Dist": "false", + "feature.enableLegacyMongoShellV1Debug": "false", + "feature.enableLegacyMongoShellV2Debug": "false", + "feature.loadLegacyMongoShellFromBE": "false", }) ), }); }); - it("should return BACKEND_ENDPOINT by default", () => { - expect(getMongoShellOrigin()).toBe(configContext.BACKEND_ENDPOINT); + it("should return by default", () => { + expect(getMongoShellOrigin()).toBe(window.origin); }); - it("should return /mongoshell/index.html when enableLegacyMongoShellV1", () => { + it("should return window.origin when enableLegacyMongoShellV1", () => { updateUserContext({ features: extractFeatures( new URLSearchParams({ @@ -35,7 +36,7 @@ describe("getMongoShellOrigin", () => { expect(getMongoShellOrigin()).toBe(window.origin); }); - it("should return /mongoshell/index.html when enableLegacyMongoShellV2===true", () => { + it("should return window.origin when enableLegacyMongoShellV2===true", () => { updateUserContext({ features: extractFeatures( new URLSearchParams({ @@ -47,11 +48,11 @@ describe("getMongoShellOrigin", () => { expect(getMongoShellOrigin()).toBe(window.origin); }); - it("should return /mongoshell/index.html when enableLegacyMongoShellV1Dist===true", () => { + it("should return window.origin when enableLegacyMongoShellV1Debug===true", () => { updateUserContext({ features: extractFeatures( new URLSearchParams({ - "feature.enableLegacyMongoShellV1Dist": "true", + "feature.enableLegacyMongoShellV1Debug": "true", }) ), }); @@ -59,15 +60,27 @@ describe("getMongoShellOrigin", () => { expect(getMongoShellOrigin()).toBe(window.origin); }); - it("should return /mongoshell/index.html when enableLegacyMongoShellV2Dist===true", () => { + it("should return window.origin when enableLegacyMongoShellV2Debug===true", () => { updateUserContext({ features: extractFeatures( new URLSearchParams({ - "feature.enableLegacyMongoShellV2Dist": "true", + "feature.enableLegacyMongoShellV2Debug": "true", }) ), }); expect(getMongoShellOrigin()).toBe(window.origin); }); + + it("should return BACKEND_ENDPOINT when loadLegacyMongoShellFromBE===true", () => { + updateUserContext({ + features: extractFeatures( + new URLSearchParams({ + "feature.loadLegacyMongoShellFromBE": "true", + }) + ), + }); + + expect(getMongoShellOrigin()).toBe(configContext.BACKEND_ENDPOINT); + }); }); diff --git a/src/Explorer/Tabs/MongoShellTab/getMongoShellOrigin.ts b/src/Explorer/Tabs/MongoShellTab/getMongoShellOrigin.ts index 3f8a81c71..774a4443c 100644 --- a/src/Explorer/Tabs/MongoShellTab/getMongoShellOrigin.ts +++ b/src/Explorer/Tabs/MongoShellTab/getMongoShellOrigin.ts @@ -2,14 +2,9 @@ import { configContext } from "../../../ConfigContext"; import { userContext } from "../../../UserContext"; export function getMongoShellOrigin(): string { - if ( - userContext.features.enableLegacyMongoShellV1 === true || - userContext.features.enableLegacyMongoShellV2 === true || - userContext.features.enableLegacyMongoShellV1Dist === true || - userContext.features.enableLegacyMongoShellV2Dist === true - ) { - return window.origin; + if (userContext.features.loadLegacyMongoShellFromBE === true) { + return configContext.BACKEND_ENDPOINT; } - return configContext.BACKEND_ENDPOINT; + return window.origin; } diff --git a/src/Explorer/Tabs/MongoShellTab/getMongoShellUrl.test.ts b/src/Explorer/Tabs/MongoShellTab/getMongoShellUrl.test.ts index 58749aa7a..65d4548be 100644 --- a/src/Explorer/Tabs/MongoShellTab/getMongoShellUrl.test.ts +++ b/src/Explorer/Tabs/MongoShellTab/getMongoShellUrl.test.ts @@ -1,5 +1,5 @@ import { extractFeatures } from "Platform/Hosted/extractFeatures"; -import { Platform, resetConfigContext, updateConfigContext } from "../../../ConfigContext"; +import { Platform, configContext, resetConfigContext, updateConfigContext } from "../../../ConfigContext"; import { updateUserContext, userContext } from "../../../UserContext"; import { getExtensionEndpoint, getMongoShellUrl } from "./getMongoShellUrl"; @@ -36,8 +36,9 @@ describe("getMongoShellUrl", () => { new URLSearchParams({ "feature.enableLegacyMongoShellV1": "false", "feature.enableLegacyMongoShellV2": "false", - "feature.enableLegacyMongoShellV1Dist": "false", - "feature.enableLegacyMongoShellV2Dist": "false", + "feature.enableLegacyMongoShellV1Debug": "false", + "feature.enableLegacyMongoShellV2Debug": "false", + "feature.loadLegacyMongoShellFromBE": "false", }) ), portalEnv: "prod", @@ -46,53 +47,16 @@ describe("getMongoShellUrl", () => { queryString = `resourceId=${userContext.databaseAccount.id}&accountName=${userContext.databaseAccount.name}&mongoEndpoint=${userContext.databaseAccount.properties.documentEndpoint}`; }); - it("should return {mongoBackendEndpoint}/content/mongoshell/dist/index.html by default ", () => { - expect(getMongoShellUrl()).toBe(`${mongoBackendEndpoint}/content/mongoshell/dist/index.html?${queryString}`); + it("should return /mongoshell/indexv2.html by default ", () => { + expect(getMongoShellUrl()).toBe(`/mongoshell/indexv2.html?${queryString}`); }); - it("should return {mongoBackendEndpoint}/content/mongoshell/index.html when portalEnv==localhost ", () => { + it("should return /mongoshell/indexv2.html when portalEnv==localhost ", () => { updateUserContext({ portalEnv: "localhost", }); - expect(getMongoShellUrl()).toBe(`${mongoBackendEndpoint}/content/mongoshell/index.html?${queryString}`); - }); - - it("should return {mongoBackendEndpoint}/content/mongoshell/dist/index.html when configContext.platform !== Platform.Hosted", () => { - updateConfigContext({ - platform: Platform.Portal, - }); - - expect(getMongoShellUrl()).toBe(`${mongoBackendEndpoint}/content/mongoshell/dist/index.html?${queryString}`); - }); - - it("should return /content/mongoshell/index.html when configContext.BACKEND_ENDPOINT === '' and configContext.platform === Platform.Hosted", () => { - resetConfigContext(); - updateConfigContext({ - platform: Platform.Hosted, - }); - - expect(getMongoShellUrl()).toBe(`/content/mongoshell/dist/index.html?${queryString}`); - }); - - it("should return /content/mongoshell/index.html when configContext.BACKEND_ENDPOINT === '' and configContext.platform !== Platform.Hosted", () => { - resetConfigContext(); - - updateConfigContext({ - platform: Platform.Portal, - }); - - expect(getMongoShellUrl()).toBe(`/content/mongoshell/dist/index.html?${queryString}`); - }); - - it("should return /content/mongoshell/index.html when configContext.BACKEND_ENDPOINT !== '' and configContext.platform !== Platform.Hosted", () => { - resetConfigContext(); - updateConfigContext({ - platform: Platform.Portal, - BACKEND_ENDPOINT: mongoBackendEndpoint, - }); - - expect(getMongoShellUrl()).toBe(`${mongoBackendEndpoint}/content/mongoshell/dist/index.html?${queryString}`); + expect(getMongoShellUrl()).toBe(`/mongoshell/indexv2.html?${queryString}`); }); it("should return /mongoshell/index.html when enableLegacyMongoShellV1===true", () => { @@ -119,28 +83,91 @@ describe("getMongoShellUrl", () => { expect(getMongoShellUrl()).toBe(`/mongoshell/indexv2.html?${queryString}`); }); - it("should return /mongoshell/index.html when enableLegacyMongoShellV1Dist===true", () => { + it("should return /mongoshell/index.html when enableLegacyMongoShellV1Debug===true", () => { updateUserContext({ features: extractFeatures( new URLSearchParams({ - "feature.enableLegacyMongoShellV1Dist": "true", + "feature.enableLegacyMongoShellV1Debug": "true", }) ), }); - expect(getMongoShellUrl()).toBe(`/mongoshell/dist/index.html?${queryString}`); + expect(getMongoShellUrl()).toBe(`/mongoshell/debug/index.html?${queryString}`); }); - it("should return /mongoshell/index.html when enableLegacyMongoShellV2Dist===true", () => { + it("should return /mongoshell/index.html when enableLegacyMongoShellV2Debug===true", () => { updateUserContext({ features: extractFeatures( new URLSearchParams({ - "feature.enableLegacyMongoShellV2Dist": "true", + "feature.enableLegacyMongoShellV2Debug": "true", }) ), }); - expect(getMongoShellUrl()).toBe(`/mongoshell/dist/indexv2.html?${queryString}`); + expect(getMongoShellUrl()).toBe(`/mongoshell/debug/indexv2.html?${queryString}`); + }); + + describe("loadLegacyMongoShellFromBE===true", () => { + beforeEach(() => { + resetConfigContext(); + updateConfigContext({ + BACKEND_ENDPOINT: mongoBackendEndpoint, + platform: Platform.Hosted, + }); + + updateUserContext({ + features: extractFeatures( + new URLSearchParams({ + "feature.loadLegacyMongoShellFromBE": "true", + }) + ), + }); + }); + + it("should return /mongoshell/index.html", () => { + const endpoint = getExtensionEndpoint(configContext.platform, configContext.BACKEND_ENDPOINT); + expect(getMongoShellUrl()).toBe(`${endpoint}/content/mongoshell/debug/index.html?${queryString}`); + }); + + it("configContext.platform !== Platform.Hosted, should return /mongoshell/indexv2.html", () => { + updateConfigContext({ + platform: Platform.Portal, + }); + + const endpoint = getExtensionEndpoint(configContext.platform, configContext.BACKEND_ENDPOINT); + expect(getMongoShellUrl()).toBe(`${endpoint}/content/mongoshell/debug/index.html?${queryString}`); + }); + + it("configContext.BACKEND_ENDPOINT !== '' and configContext.platform !== Platform.Hosted, should return /mongoshell/indexv2.html", () => { + resetConfigContext(); + updateConfigContext({ + platform: Platform.Portal, + BACKEND_ENDPOINT: mongoBackendEndpoint, + }); + + const endpoint = getExtensionEndpoint(configContext.platform, configContext.BACKEND_ENDPOINT); + expect(getMongoShellUrl()).toBe(`${endpoint}/content/mongoshell/debug/index.html?${queryString}`); + }); + + it("configContext.BACKEND_ENDPOINT === '' and configContext.platform === Platform.Hosted, should return /mongoshell/indexv2.html ", () => { + resetConfigContext(); + updateConfigContext({ + platform: Platform.Hosted, + }); + + const endpoint = getExtensionEndpoint(configContext.platform, configContext.BACKEND_ENDPOINT); + expect(getMongoShellUrl()).toBe(`${endpoint}/content/mongoshell/debug/index.html?${queryString}`); + }); + + it("configContext.BACKEND_ENDPOINT === '' and configContext.platform !== Platform.Hosted, should return /mongoshell/indexv2.html", () => { + resetConfigContext(); + updateConfigContext({ + platform: Platform.Portal, + }); + + const endpoint = getExtensionEndpoint(configContext.platform, configContext.BACKEND_ENDPOINT); + expect(getMongoShellUrl()).toBe(`${endpoint}/content/mongoshell/debug/index.html?${queryString}`); + }); }); }); diff --git a/src/Explorer/Tabs/MongoShellTab/getMongoShellUrl.ts b/src/Explorer/Tabs/MongoShellTab/getMongoShellUrl.ts index 81a63a022..a029fe440 100644 --- a/src/Explorer/Tabs/MongoShellTab/getMongoShellUrl.ts +++ b/src/Explorer/Tabs/MongoShellTab/getMongoShellUrl.ts @@ -12,25 +12,28 @@ export function getMongoShellUrl(): string { return `/mongoshell/index.html?${queryString}`; } - if (userContext.features.enableLegacyMongoShellV1Dist === true) { - return `/mongoshell/dist/index.html?${queryString}`; + if (userContext.features.enableLegacyMongoShellV1Debug === true) { + return `/mongoshell/debug/index.html?${queryString}`; } if (userContext.features.enableLegacyMongoShellV2 === true) { return `/mongoshell/indexv2.html?${queryString}`; } - if (userContext.features.enableLegacyMongoShellV2Dist === true) { - return `/mongoshell/dist/indexv2.html?${queryString}`; + if (userContext.features.enableLegacyMongoShellV2Debug === true) { + return `/mongoshell/debug/indexv2.html?${queryString}`; } - const extensionEndpoint: string = getExtensionEndpoint(configContext.platform, configContext.BACKEND_ENDPOINT); - if (userContext.portalEnv === "localhost") { - return `${extensionEndpoint}/content/mongoshell/index.html?${queryString}`; + return `/mongoshell/indexv2.html?${queryString}`; } - return `${extensionEndpoint}/content/mongoshell/dist/index.html?${queryString}`; + if (userContext.features.loadLegacyMongoShellFromBE === true) { + const extensionEndpoint: string = getExtensionEndpoint(configContext.platform, configContext.BACKEND_ENDPOINT); + return `${extensionEndpoint}/content/mongoshell/debug/index.html?${queryString}`; + } + + return `/mongoshell/indexv2.html?${queryString}`; } export function getExtensionEndpoint(platform: string, backendEndpoint: string): string { diff --git a/src/Platform/Hosted/extractFeatures.ts b/src/Platform/Hosted/extractFeatures.ts index 60d4bfa42..9b39ac757 100644 --- a/src/Platform/Hosted/extractFeatures.ts +++ b/src/Platform/Hosted/extractFeatures.ts @@ -31,9 +31,10 @@ export type Features = { readonly enableThroughputCap: boolean; readonly enableHierarchicalKeys: boolean; readonly enableLegacyMongoShellV1: boolean; - readonly enableLegacyMongoShellV1Dist: boolean; + readonly enableLegacyMongoShellV1Debug: boolean; readonly enableLegacyMongoShellV2: boolean; - readonly enableLegacyMongoShellV2Dist: boolean; + readonly enableLegacyMongoShellV2Debug: boolean; + readonly loadLegacyMongoShellFromBE: boolean; // can be set via both flight and feature flag autoscaleDefault: boolean; @@ -97,9 +98,10 @@ export function extractFeatures(given = new URLSearchParams(window.location.sear enableThroughputCap: "true" === get("enablethroughputcap"), enableHierarchicalKeys: "true" === get("enablehierarchicalkeys"), enableLegacyMongoShellV1: "true" === get("enablelegacymongoshellv1"), - enableLegacyMongoShellV1Dist: "true" === get("enablelegacymongoshellv1dist"), + enableLegacyMongoShellV1Debug: "true" === get("enablelegacymongoshellv1debug"), enableLegacyMongoShellV2: "true" === get("enablelegacymongoshellv2"), - enableLegacyMongoShellV2Dist: "true" === get("enablelegacymongoshellv2dist"), + enableLegacyMongoShellV2Debug: "true" === get("enablelegacymongoshellv2debug"), + loadLegacyMongoShellFromBE: "true" === get("loadlegacymongoshellfrombe"), }; }