From 2296464f7bc7c22ea600e8742c7d7247767b4690 Mon Sep 17 00:00:00 2001 From: EmmaYuan1015 Date: Mon, 11 May 2026 10:07:22 +0800 Subject: [PATCH] Add Network Inspector smoke suite and refactor dispose logic - Add new NetworkInspectorTest smoke suite to verify Run/Stop Network Inspector commands are visible in the command palette - Register NetworkInspectorTest in the main smoke entry point - Refactor CommandPaletteTest, FileExplorerTest, DebugConfigurationTest, and PackagerTest to reuse BaseSmokeTest.initApp/dispose instead of duplicating the app lifecycle boilerplate --- test/smoke/suites/commands.test.ts | 31 ++------------- test/smoke/suites/debugConfiguration.test.ts | 33 ++-------------- test/smoke/suites/fileExplorer.test.ts | 31 ++------------- test/smoke/suites/networkInspector.test.ts | 41 ++++++++++++++++++++ test/smoke/suites/packager.test.ts | 34 +++------------- test/smoke/suites/smoke.test.ts | 2 + 6 files changed, 58 insertions(+), 114 deletions(-) create mode 100644 test/smoke/suites/networkInspector.test.ts diff --git a/test/smoke/suites/commands.test.ts b/test/smoke/suites/commands.test.ts index 25a8c293e..05f19f2c7 100644 --- a/test/smoke/suites/commands.test.ts +++ b/test/smoke/suites/commands.test.ts @@ -1,44 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for details. -import { Page } from "playwright"; -import { SmokeTestLogger } from "./helper/smokeTestLogger"; -import { app, screenshots } from "./main"; import assert = require("assert"); import { ElementHelper } from "./helper/elementHelper"; import { Element } from "./helper/constants"; import { ComponentHelper } from "./helper/componentHelper"; import { TimeoutConstants } from "./helper/timeoutConstants"; +import { BaseSmokeTest } from "./helper/baseSmokeTest"; export function startCommandPaletteTests(): void { describe("CommandPaletteTest", () => { - async function initApp(): Promise { - await app.launch(); - return app.getMainPage(); - } - - async function dispose() { - if (this.currentTest?.state === "failed") { - SmokeTestLogger.info("Test failed, taking screenshot ..."); - await screenshots.takeScreenshots( - this.currentTest.parent?.title || "Others", - this.currentTest.title.replace(/\s+/g, "_"), - ); - } - try { - SmokeTestLogger.info(`Dispose test: "${this.currentTest.title}" ...`); - if (app) { - await app.close(); - } - } catch (error) { - SmokeTestLogger.error(`Error while dispose: ${error}`); - } - } - - afterEach(dispose); + afterEach(BaseSmokeTest.dispose); it("Verify react native command is visible in command palette", async () => { const text = "React Native: Start Packager"; - await initApp(); + await BaseSmokeTest.initApp(); await ComponentHelper.openCommandPalette(); await ElementHelper.WaitElementClassNameVisible( diff --git a/test/smoke/suites/debugConfiguration.test.ts b/test/smoke/suites/debugConfiguration.test.ts index 52998362e..9aa879f40 100644 --- a/test/smoke/suites/debugConfiguration.test.ts +++ b/test/smoke/suites/debugConfiguration.test.ts @@ -3,47 +3,22 @@ import * as fs from "fs"; import * as path from "path"; -import { Page } from "playwright"; -import { SmokeTestLogger } from "./helper/smokeTestLogger"; -import { app, screenshots } from "./main"; import assert = require("assert"); import { ElementHelper } from "./helper/elementHelper"; import { Element } from "./helper/constants"; import { ComponentHelper } from "./helper/componentHelper"; import { TimeoutConstants } from "./helper/timeoutConstants"; +import { BaseSmokeTest } from "./helper/baseSmokeTest"; export function startDebugConfigurationTests(): void { describe("DebugConfigurationTest", () => { - async function initApp(): Promise { - await app.launch(); - return app.getMainPage(); - } - - async function dispose() { - if (this.currentTest?.state === "failed") { - SmokeTestLogger.info("Test failed, taking screenshot ..."); - await screenshots.takeScreenshots( - this.currentTest.parent?.title || "Others", - this.currentTest.title.replace(/\s+/g, "_"), - ); - } - try { - SmokeTestLogger.info(`Dispose test: "${this.currentTest.title}" ...`); - if (app) { - await app.close(); - } - } catch (error) { - SmokeTestLogger.error(`Error while dispose: ${error}`); - } - } - - afterEach(dispose); + afterEach(BaseSmokeTest.dispose); it("Verify extension debugger is visible in select debugger list", async () => { const createLaunchFile = "create a launch.json file"; const rnOptionText = "More React Native options..."; - await initApp(); + await BaseSmokeTest.initApp(); await ComponentHelper.openRunAndDebugTab(); await ElementHelper.WaitElementClassNameVisible(Element.welcomeViewClassName); @@ -70,7 +45,7 @@ export function startDebugConfigurationTests(): void { fs.writeFileSync(path.join(vscodeFolderPath, "launch.json"), JSON.stringify({})); - await initApp(); + await BaseSmokeTest.initApp(); await ComponentHelper.openFileExplorer(); const vscodeFolder = await ComponentHelper.WaitFileVisibleInFileExplorer(".vscode"); diff --git a/test/smoke/suites/fileExplorer.test.ts b/test/smoke/suites/fileExplorer.test.ts index d6eb3bc0f..ab502549b 100644 --- a/test/smoke/suites/fileExplorer.test.ts +++ b/test/smoke/suites/fileExplorer.test.ts @@ -1,46 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for details. -import { Page } from "playwright"; -import { SmokeTestLogger } from "./helper/smokeTestLogger"; -import { app, screenshots } from "./main"; import { CommonHelper } from "./helper/commonHelper"; import { ComponentHelper } from "./helper/componentHelper"; import assert = require("assert"); +import { BaseSmokeTest } from "./helper/baseSmokeTest"; export function startFileExplorerTests(): void { describe("FileExplorerTest", () => { - async function initApp(): Promise { - await app.launch(); - return app.getMainPage(); - } - - async function dispose() { - if (this.currentTest?.state === "failed") { - SmokeTestLogger.info("Test failed, taking screenshot ..."); - await screenshots.takeScreenshots( - this.currentTest.parent?.title || "Others", - this.currentTest.title.replace(/\s+/g, "_"), - ); - } - try { - SmokeTestLogger.info(`Dispose test: "${this.currentTest.title}" ...`); - if (app) { - await app.close(); - } - } catch (error) { - SmokeTestLogger.error(`Error while dispose: ${error}`); - } - } - - afterEach(dispose); + afterEach(BaseSmokeTest.dispose); it("Verify .vscode folder will be created when extension is activated", async () => { const projectName = "sampleReactNativeProject"; const folderName = ".vscode"; await CommonHelper.findAndDeleteVSCodeSettingsDirectory(projectName); - await initApp(); + await BaseSmokeTest.initApp(); await ComponentHelper.openFileExplorer(); const folder = await ComponentHelper.WaitFileVisibleInFileExplorer(folderName); diff --git a/test/smoke/suites/networkInspector.test.ts b/test/smoke/suites/networkInspector.test.ts new file mode 100644 index 000000000..acf36ac62 --- /dev/null +++ b/test/smoke/suites/networkInspector.test.ts @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for details. + +import assert = require("assert"); +import { BaseSmokeTest } from "./helper/baseSmokeTest"; +import { ComponentHelper } from "./helper/componentHelper"; +import { Element } from "./helper/constants"; +import { ElementHelper } from "./helper/elementHelper"; +import { TimeoutConstants } from "./helper/timeoutConstants"; + +export function startNetworkInspectorTests(): void { + describe("NetworkInspectorTest", () => { + afterEach(BaseSmokeTest.dispose); + + it("Verify network inspector commands are visible in command palette", async () => { + await BaseSmokeTest.initApp(); + + const expectedCommands = [ + "React Native: Run Network Inspector", + "React Native: Stop Network Inspector", + ]; + + for (const command of expectedCommands) { + await ComponentHelper.openCommandPalette(); + await ElementHelper.WaitElementClassNameVisible( + Element.commandPaletteClassName, + TimeoutConstants.COMMAND_PALETTE_TIMEOUT, + ); + + await ElementHelper.inputText(command); + const option = await ElementHelper.WaitElementSelectorVisible( + Element.commandPaletteFocusedItemSelector, + TimeoutConstants.COMMAND_PALETTE_TIMEOUT, + ); + + const value = await option.getAttribute("aria-label"); + assert.ok(value?.includes(command), `Command '${command}' is not visible`); + } + }); + }); +} diff --git a/test/smoke/suites/packager.test.ts b/test/smoke/suites/packager.test.ts index e542b63ea..584f4bbb5 100644 --- a/test/smoke/suites/packager.test.ts +++ b/test/smoke/suites/packager.test.ts @@ -1,42 +1,18 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for details. -import { Page } from "playwright"; -import { SmokeTestLogger } from "./helper/smokeTestLogger"; -import { app, screenshots } from "./main"; import assert = require("assert"); import { ComponentHelper } from "./helper/componentHelper"; import { TimeoutConstants } from "./helper/timeoutConstants"; +import { BaseSmokeTest } from "./helper/baseSmokeTest"; +import { SmokeTestLogger } from "./helper/smokeTestLogger"; export function startPackagerTests(): void { describe("PackagerTest", () => { - async function initApp(): Promise { - await app.launch(); - return app.getMainPage(); - } - - async function dispose() { - if (this.currentTest?.state === "failed") { - SmokeTestLogger.info("Test failed, taking screenshot ..."); - await screenshots.takeScreenshots( - this.currentTest.parent?.title || "Others", - this.currentTest.title.replace(/\s+/g, "_"), - ); - } - try { - SmokeTestLogger.info(`Dispose test: "${this.currentTest.title}" ...`); - if (app) { - await app.close(); - } - } catch (error) { - SmokeTestLogger.error(`Error while dispose: ${error}`); - } - } - - afterEach(dispose); + afterEach(BaseSmokeTest.dispose); it("Verify react-native packager state is changed correctly when start and stop metro", async () => { - await initApp(); + await BaseSmokeTest.initApp(); let packager = await ComponentHelper.getReactNativePackager(); let currentState = await packager.getAttribute("aria-label"); @@ -65,7 +41,7 @@ export function startPackagerTests(): void { it("Verify Clean & Restart Packager command works correctly", async function () { this.timeout(TimeoutConstants.PACKAGER_CLEAN_RESTART_TIMEOUT); // 5 minutes timeout for clean restart - await initApp(); + await BaseSmokeTest.initApp(); // Execute Clean & Restart Packager command // The command should handle starting the packager if it's not already running diff --git a/test/smoke/suites/smoke.test.ts b/test/smoke/suites/smoke.test.ts index ea48094df..184ec36f8 100644 --- a/test/smoke/suites/smoke.test.ts +++ b/test/smoke/suites/smoke.test.ts @@ -12,6 +12,7 @@ import { smokeTestFail } from "./helper/utilities"; import { startPackagerTests } from "./packager.test"; import { startVsixExistenceTest } from "./vsixbuild.test"; import { startLogGrammarTests } from "./logGrammar.test"; +import { startNetworkInspectorTests } from "./networkInspector.test"; export function startSmokeTests(setup: () => Promise, cleanUp: () => Promise): void { // Guard: if mocha BDD hooks are absent, do not attempt to register tests @@ -42,6 +43,7 @@ export function startSmokeTests(setup: () => Promise, cleanUp: () => Promi startCommandPaletteTests(); startFileExplorerTests(); startPackagerTests(); + startNetworkInspectorTests(); startActionBarTests(); startDebugConfigurationTests(); startCDPNodeVersionCompatibilityTests();