From 2117a2372e2a0864aa575a1fc61fa59ed264a92e Mon Sep 17 00:00:00 2001 From: ayachensiyuan <67082457+ayachensiyuan@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:55:57 +0800 Subject: [PATCH] test: distinguish describe name & fix quota limited (#10338) * test: distinguish describe name * test: fix quota limited --------- Co-authored-by: v-ivanchen_microsoft --- packages/tests/src/e2e/commonUtils.ts | 30 ++++++++++------ .../ProvisionProactiveMessage.tests.ts | 8 +++++ .../e2e/samples/ProvisionShareNow.tests.ts | 4 ++- .../src/e2e/samples/sampleCaseFactory.ts | 2 +- .../ui-test/remotedebug/remotedebugContext.ts | 35 ++++++++----------- .../sample-localdebug-share-now.test.ts | 1 - ...mple-remotedebug-proactive-message.test.ts | 15 ++++++++ .../sample-remotedebug-share-now.test.ts | 5 +++ 8 files changed, 66 insertions(+), 34 deletions(-) diff --git a/packages/tests/src/e2e/commonUtils.ts b/packages/tests/src/e2e/commonUtils.ts index 14efbdd049..54bc333025 100644 --- a/packages/tests/src/e2e/commonUtils.ts +++ b/packages/tests/src/e2e/commonUtils.ts @@ -156,6 +156,26 @@ export async function setProvisionParameterValue( return fs.writeJSON(parametersFilePath, parameters, { spaces: 4 }); } +export async function setBotSkuNameToB1Bicep( + projectPath: string, + filePath = "" +) { + const azureParametersFilePathSuffix = filePath + ? path.join(filePath) + : path.join("infra", "azure.parameters.json"); + const azureParametersFilePath = path.resolve( + projectPath, + azureParametersFilePathSuffix + ); + const ProvisionParameters = await fs.readJSON(azureParametersFilePath); + ProvisionParameters["parameters"]["provisionParameters"]["value"][ + "botWebAppSKU" + ] = "B1"; + return fs.writeJSON(azureParametersFilePath, ProvisionParameters, { + spaces: 4, + }); +} + export async function setSimpleAuthSkuNameToB1(projectPath: string) { const envFilePath = path.resolve(projectPath, envFilePathSuffix); const context = await fs.readJSON(envFilePath); @@ -201,16 +221,6 @@ export async function setBotSkuNameToB1(projectPath: string) { return fs.writeJSON(envFilePath, context, { spaces: 4 }); } -export async function setBotSkuNameToB1Bicep( - projectPath: string, - envName: string -): Promise { - return setProvisionParameterValue(projectPath, envName, { - key: "webAppSKU", - value: "B1", - }); -} - export async function setSkipAddingSqlUser(projectPath: string) { const envFilePath = path.resolve(projectPath, envFilePathSuffix); const context = await fs.readJSON(envFilePath); diff --git a/packages/tests/src/e2e/samples/ProvisionProactiveMessage.tests.ts b/packages/tests/src/e2e/samples/ProvisionProactiveMessage.tests.ts index 3dd6b7be75..49075a62ba 100644 --- a/packages/tests/src/e2e/samples/ProvisionProactiveMessage.tests.ts +++ b/packages/tests/src/e2e/samples/ProvisionProactiveMessage.tests.ts @@ -8,6 +8,7 @@ import { TemplateProjectFolder } from "../../utils/constants"; import { CaseFactory } from "./sampleCaseFactory"; import { Executor } from "../../utils/executor"; +import { setBotSkuNameToB1Bicep } from "../commonUtils"; class ProactiveMessagingTestCase extends CaseFactory { public override async onCreate( @@ -24,6 +25,13 @@ class ProactiveMessagingTestCase extends CaseFactory { ); } + override async onBeforeProvision(projectPath: string): Promise { + await setBotSkuNameToB1Bicep( + projectPath, + "templates/azure/azure.parameters.dev.json" + ); + } + override async onAfterCreate(projectPath: string): Promise { return Promise.resolve(); } diff --git a/packages/tests/src/e2e/samples/ProvisionShareNow.tests.ts b/packages/tests/src/e2e/samples/ProvisionShareNow.tests.ts index 928dee4f9d..90fbd7e347 100644 --- a/packages/tests/src/e2e/samples/ProvisionShareNow.tests.ts +++ b/packages/tests/src/e2e/samples/ProvisionShareNow.tests.ts @@ -8,11 +8,13 @@ import { TemplateProjectFolder } from "../../utils/constants"; import { CaseFactory } from "./sampleCaseFactory"; import * as path from "path"; -import { editDotEnvFile } from "../commonUtils"; +import { editDotEnvFile, setBotSkuNameToB1Bicep } from "../commonUtils"; import { getUuid } from "../../commonlib/utilities"; class ShareNowTestCase extends CaseFactory { override async onBeforeProvision(projectPath: string): Promise { + // fix quota issue + await setBotSkuNameToB1Bicep(projectPath); const envFilePath = path.resolve(projectPath, "env", ".env.dev.user"); editDotEnvFile(envFilePath, "SQL_USER_NAME", "Abc123321"); editDotEnvFile( diff --git a/packages/tests/src/e2e/samples/sampleCaseFactory.ts b/packages/tests/src/e2e/samples/sampleCaseFactory.ts index c4409c80c7..73106ba6fe 100644 --- a/packages/tests/src/e2e/samples/sampleCaseFactory.ts +++ b/packages/tests/src/e2e/samples/sampleCaseFactory.ts @@ -114,7 +114,7 @@ export abstract class CaseFactory { onBeforeProvision, onCreate, } = this; - describe("Sample Tests", function () { + describe(`Sample Tests: ${sampleName}`, function () { const testFolder = getTestFolder(); const appName = getUniqueAppName(); const projectPath = path.resolve(testFolder, appName); diff --git a/packages/tests/src/ui-test/remotedebug/remotedebugContext.ts b/packages/tests/src/ui-test/remotedebug/remotedebugContext.ts index 3bee85607b..2be6f563e7 100644 --- a/packages/tests/src/ui-test/remotedebug/remotedebugContext.ts +++ b/packages/tests/src/ui-test/remotedebug/remotedebugContext.ts @@ -3,7 +3,6 @@ import * as fs from "fs-extra"; import * as path from "path"; -import * as os from "os"; import { TestContext } from "../testContext"; import { CommandPaletteCommands, @@ -110,14 +109,6 @@ export async function setSimpleAuthSkuNameToB1(projectPath: string) { context[simpleAuthPluginName]["skuName"] = "B1"; return fs.writeJSON(envFilePath, context, { spaces: 4 }); } -export async function setBotSkuNameToB1(projectPath: string) { - const botPluginName = "fx-resource-bot"; - const envFilePathSuffix = path.join(".fx", "env.default.json"); - const envFilePath = path.resolve(projectPath, envFilePathSuffix); - const context = await fs.readJSON(envFilePath); - context[botPluginName]["skuName"] = "B1"; - return fs.writeJSON(envFilePath, context, { spaces: 4 }); -} export async function setSkuNameToB1(projectPath: string) { const parameters = "parameters"; @@ -159,20 +150,22 @@ export async function setSimpleAuthSkuNameToB1Bicep( export async function setBotSkuNameToB1Bicep( projectPath: string, - envName: string + filePath = "" ) { - const ConfigFolderName = "fx"; - const InputConfigsFolderName = "configs"; - const bicepParameterFile = path.join( - `.${ConfigFolderName}`, - InputConfigsFolderName, - `azure.parameters.${envName}.json` + const azureParametersFilePathSuffix = filePath + ? path.join(filePath) + : path.join("infra", "azure.parameters.json"); + const azureParametersFilePath = path.resolve( + projectPath, + azureParametersFilePathSuffix ); - const parametersFilePath = path.resolve(projectPath, bicepParameterFile); - const parameters = await fs.readJSON(parametersFilePath); - parameters["parameters"]["provisionParameters"]["value"]["botWebAppSKU"] = - "B1"; - return fs.writeJSON(parametersFilePath, parameters, { spaces: 4 }); + const ProvisionParameters = await fs.readJSON(azureParametersFilePath); + ProvisionParameters["parameters"]["provisionParameters"]["value"][ + "botWebAppSKU" + ] = "B1"; + return fs.writeJSON(azureParametersFilePath, ProvisionParameters, { + spaces: 4, + }); } export async function inputSqlUserName( diff --git a/packages/tests/src/ui-test/samples/sample-localdebug-share-now.test.ts b/packages/tests/src/ui-test/samples/sample-localdebug-share-now.test.ts index b3344809a6..3cc6967c06 100644 --- a/packages/tests/src/ui-test/samples/sample-localdebug-share-now.test.ts +++ b/packages/tests/src/ui-test/samples/sample-localdebug-share-now.test.ts @@ -11,7 +11,6 @@ import { validateShareNow } from "../../utils/playwrightOperation"; import { CaseFactory } from "./sampleCaseFactory"; import { AzSqlHelper } from "../../utils/azureCliHelper"; import { SampledebugContext } from "./sampledebugContext"; -import * as uuid from "uuid"; import { expect } from "chai"; import * as path from "path"; import { editDotEnvFile } from "../../utils/commonUtils"; diff --git a/packages/tests/src/ui-test/samples/sample-remotedebug-proactive-message.test.ts b/packages/tests/src/ui-test/samples/sample-remotedebug-proactive-message.test.ts index 1b3172d627..9406a43b5d 100644 --- a/packages/tests/src/ui-test/samples/sample-remotedebug-proactive-message.test.ts +++ b/packages/tests/src/ui-test/samples/sample-remotedebug-proactive-message.test.ts @@ -9,11 +9,26 @@ import { Page } from "playwright"; import { TemplateProject } from "../../utils/constants"; import { validateProactiveMessaging } from "../../utils/playwrightOperation"; import { CaseFactory } from "./sampleCaseFactory"; +import { AzSqlHelper } from "../../utils/azureCliHelper"; +import { SampledebugContext } from "./sampledebugContext"; +import { setBotSkuNameToB1Bicep } from "../remotedebug/remotedebugContext"; class ProactiveMessagingTestCase extends CaseFactory { override async onValidate(page: Page): Promise { return await validateProactiveMessaging(page); } + + override async onAfterCreate( + sampledebugContext: SampledebugContext, + env: "local" | "dev", + azSqlHelper?: AzSqlHelper | undefined + ): Promise { + // fix quota issue + await setBotSkuNameToB1Bicep( + sampledebugContext.projectPath, + "templates/azure/azure.parameters.dev.json" + ); + } } new ProactiveMessagingTestCase( diff --git a/packages/tests/src/ui-test/samples/sample-remotedebug-share-now.test.ts b/packages/tests/src/ui-test/samples/sample-remotedebug-share-now.test.ts index f62ea4d0c8..f3faa53bd0 100644 --- a/packages/tests/src/ui-test/samples/sample-remotedebug-share-now.test.ts +++ b/packages/tests/src/ui-test/samples/sample-remotedebug-share-now.test.ts @@ -15,6 +15,7 @@ import * as uuid from "uuid"; import * as fs from "fs"; import * as path from "path"; import { editDotEnvFile } from "../../utils/commonUtils"; +import { setBotSkuNameToB1Bicep } from "../remotedebug/remotedebugContext"; class ShareNowTestCase extends CaseFactory { public sqlUserName: string; @@ -52,7 +53,11 @@ class ShareNowTestCase extends CaseFactory { const password = this.sqlPassword; editDotEnvFile(envFilePath, "SQL_USER_NAME", user); editDotEnvFile(envFilePath, "SQL_PASSWORD", password); + + // fix quota issue + await setBotSkuNameToB1Bicep(sampledebugContext.projectPath); }; + public override onBeforeBrowerStart = async ( sampledebugContext: SampledebugContext ): Promise => {