Skip to content

Commit 2296464

Browse files
committed
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
1 parent e53f37f commit 2296464

6 files changed

Lines changed: 58 additions & 114 deletions

File tree

test/smoke/suites/commands.test.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,19 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for details.
33

4-
import { Page } from "playwright";
5-
import { SmokeTestLogger } from "./helper/smokeTestLogger";
6-
import { app, screenshots } from "./main";
74
import assert = require("assert");
85
import { ElementHelper } from "./helper/elementHelper";
96
import { Element } from "./helper/constants";
107
import { ComponentHelper } from "./helper/componentHelper";
118
import { TimeoutConstants } from "./helper/timeoutConstants";
9+
import { BaseSmokeTest } from "./helper/baseSmokeTest";
1210
export function startCommandPaletteTests(): void {
1311
describe("CommandPaletteTest", () => {
14-
async function initApp(): Promise<Page> {
15-
await app.launch();
16-
return app.getMainPage();
17-
}
18-
19-
async function dispose() {
20-
if (this.currentTest?.state === "failed") {
21-
SmokeTestLogger.info("Test failed, taking screenshot ...");
22-
await screenshots.takeScreenshots(
23-
this.currentTest.parent?.title || "Others",
24-
this.currentTest.title.replace(/\s+/g, "_"),
25-
);
26-
}
27-
try {
28-
SmokeTestLogger.info(`Dispose test: "${this.currentTest.title}" ...`);
29-
if (app) {
30-
await app.close();
31-
}
32-
} catch (error) {
33-
SmokeTestLogger.error(`Error while dispose: ${error}`);
34-
}
35-
}
36-
37-
afterEach(dispose);
12+
afterEach(BaseSmokeTest.dispose);
3813

3914
it("Verify react native command is visible in command palette", async () => {
4015
const text = "React Native: Start Packager";
41-
await initApp();
16+
await BaseSmokeTest.initApp();
4217

4318
await ComponentHelper.openCommandPalette();
4419
await ElementHelper.WaitElementClassNameVisible(

test/smoke/suites/debugConfiguration.test.ts

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,22 @@
33

44
import * as fs from "fs";
55
import * as path from "path";
6-
import { Page } from "playwright";
7-
import { SmokeTestLogger } from "./helper/smokeTestLogger";
8-
import { app, screenshots } from "./main";
96
import assert = require("assert");
107
import { ElementHelper } from "./helper/elementHelper";
118
import { Element } from "./helper/constants";
129
import { ComponentHelper } from "./helper/componentHelper";
1310
import { TimeoutConstants } from "./helper/timeoutConstants";
11+
import { BaseSmokeTest } from "./helper/baseSmokeTest";
1412

1513
export function startDebugConfigurationTests(): void {
1614
describe("DebugConfigurationTest", () => {
17-
async function initApp(): Promise<Page> {
18-
await app.launch();
19-
return app.getMainPage();
20-
}
21-
22-
async function dispose() {
23-
if (this.currentTest?.state === "failed") {
24-
SmokeTestLogger.info("Test failed, taking screenshot ...");
25-
await screenshots.takeScreenshots(
26-
this.currentTest.parent?.title || "Others",
27-
this.currentTest.title.replace(/\s+/g, "_"),
28-
);
29-
}
30-
try {
31-
SmokeTestLogger.info(`Dispose test: "${this.currentTest.title}" ...`);
32-
if (app) {
33-
await app.close();
34-
}
35-
} catch (error) {
36-
SmokeTestLogger.error(`Error while dispose: ${error}`);
37-
}
38-
}
39-
40-
afterEach(dispose);
15+
afterEach(BaseSmokeTest.dispose);
4116

4217
it("Verify extension debugger is visible in select debugger list", async () => {
4318
const createLaunchFile = "create a launch.json file";
4419
const rnOptionText = "More React Native options...";
4520

46-
await initApp();
21+
await BaseSmokeTest.initApp();
4722

4823
await ComponentHelper.openRunAndDebugTab();
4924
await ElementHelper.WaitElementClassNameVisible(Element.welcomeViewClassName);
@@ -70,7 +45,7 @@ export function startDebugConfigurationTests(): void {
7045

7146
fs.writeFileSync(path.join(vscodeFolderPath, "launch.json"), JSON.stringify({}));
7247

73-
await initApp();
48+
await BaseSmokeTest.initApp();
7449

7550
await ComponentHelper.openFileExplorer();
7651
const vscodeFolder = await ComponentHelper.WaitFileVisibleInFileExplorer(".vscode");

test/smoke/suites/fileExplorer.test.ts

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,21 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for details.
33

4-
import { Page } from "playwright";
5-
import { SmokeTestLogger } from "./helper/smokeTestLogger";
6-
import { app, screenshots } from "./main";
74
import { CommonHelper } from "./helper/commonHelper";
85
import { ComponentHelper } from "./helper/componentHelper";
96
import assert = require("assert");
7+
import { BaseSmokeTest } from "./helper/baseSmokeTest";
108

119
export function startFileExplorerTests(): void {
1210
describe("FileExplorerTest", () => {
13-
async function initApp(): Promise<Page> {
14-
await app.launch();
15-
return app.getMainPage();
16-
}
17-
18-
async function dispose() {
19-
if (this.currentTest?.state === "failed") {
20-
SmokeTestLogger.info("Test failed, taking screenshot ...");
21-
await screenshots.takeScreenshots(
22-
this.currentTest.parent?.title || "Others",
23-
this.currentTest.title.replace(/\s+/g, "_"),
24-
);
25-
}
26-
try {
27-
SmokeTestLogger.info(`Dispose test: "${this.currentTest.title}" ...`);
28-
if (app) {
29-
await app.close();
30-
}
31-
} catch (error) {
32-
SmokeTestLogger.error(`Error while dispose: ${error}`);
33-
}
34-
}
35-
36-
afterEach(dispose);
11+
afterEach(BaseSmokeTest.dispose);
3712

3813
it("Verify .vscode folder will be created when extension is activated", async () => {
3914
const projectName = "sampleReactNativeProject";
4015
const folderName = ".vscode";
4116
await CommonHelper.findAndDeleteVSCodeSettingsDirectory(projectName);
4217

43-
await initApp();
18+
await BaseSmokeTest.initApp();
4419

4520
await ComponentHelper.openFileExplorer();
4621
const folder = await ComponentHelper.WaitFileVisibleInFileExplorer(folderName);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for details.
3+
4+
import assert = require("assert");
5+
import { BaseSmokeTest } from "./helper/baseSmokeTest";
6+
import { ComponentHelper } from "./helper/componentHelper";
7+
import { Element } from "./helper/constants";
8+
import { ElementHelper } from "./helper/elementHelper";
9+
import { TimeoutConstants } from "./helper/timeoutConstants";
10+
11+
export function startNetworkInspectorTests(): void {
12+
describe("NetworkInspectorTest", () => {
13+
afterEach(BaseSmokeTest.dispose);
14+
15+
it("Verify network inspector commands are visible in command palette", async () => {
16+
await BaseSmokeTest.initApp();
17+
18+
const expectedCommands = [
19+
"React Native: Run Network Inspector",
20+
"React Native: Stop Network Inspector",
21+
];
22+
23+
for (const command of expectedCommands) {
24+
await ComponentHelper.openCommandPalette();
25+
await ElementHelper.WaitElementClassNameVisible(
26+
Element.commandPaletteClassName,
27+
TimeoutConstants.COMMAND_PALETTE_TIMEOUT,
28+
);
29+
30+
await ElementHelper.inputText(command);
31+
const option = await ElementHelper.WaitElementSelectorVisible(
32+
Element.commandPaletteFocusedItemSelector,
33+
TimeoutConstants.COMMAND_PALETTE_TIMEOUT,
34+
);
35+
36+
const value = await option.getAttribute("aria-label");
37+
assert.ok(value?.includes(command), `Command '${command}' is not visible`);
38+
}
39+
});
40+
});
41+
}

test/smoke/suites/packager.test.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,18 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for details.
33

4-
import { Page } from "playwright";
5-
import { SmokeTestLogger } from "./helper/smokeTestLogger";
6-
import { app, screenshots } from "./main";
74
import assert = require("assert");
85
import { ComponentHelper } from "./helper/componentHelper";
96
import { TimeoutConstants } from "./helper/timeoutConstants";
7+
import { BaseSmokeTest } from "./helper/baseSmokeTest";
8+
import { SmokeTestLogger } from "./helper/smokeTestLogger";
109

1110
export function startPackagerTests(): void {
1211
describe("PackagerTest", () => {
13-
async function initApp(): Promise<Page> {
14-
await app.launch();
15-
return app.getMainPage();
16-
}
17-
18-
async function dispose() {
19-
if (this.currentTest?.state === "failed") {
20-
SmokeTestLogger.info("Test failed, taking screenshot ...");
21-
await screenshots.takeScreenshots(
22-
this.currentTest.parent?.title || "Others",
23-
this.currentTest.title.replace(/\s+/g, "_"),
24-
);
25-
}
26-
try {
27-
SmokeTestLogger.info(`Dispose test: "${this.currentTest.title}" ...`);
28-
if (app) {
29-
await app.close();
30-
}
31-
} catch (error) {
32-
SmokeTestLogger.error(`Error while dispose: ${error}`);
33-
}
34-
}
35-
36-
afterEach(dispose);
12+
afterEach(BaseSmokeTest.dispose);
3713

3814
it("Verify react-native packager state is changed correctly when start and stop metro", async () => {
39-
await initApp();
15+
await BaseSmokeTest.initApp();
4016

4117
let packager = await ComponentHelper.getReactNativePackager();
4218
let currentState = await packager.getAttribute("aria-label");
@@ -65,7 +41,7 @@ export function startPackagerTests(): void {
6541

6642
it("Verify Clean & Restart Packager command works correctly", async function () {
6743
this.timeout(TimeoutConstants.PACKAGER_CLEAN_RESTART_TIMEOUT); // 5 minutes timeout for clean restart
68-
await initApp();
44+
await BaseSmokeTest.initApp();
6945

7046
// Execute Clean & Restart Packager command
7147
// The command should handle starting the packager if it's not already running

test/smoke/suites/smoke.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { smokeTestFail } from "./helper/utilities";
1212
import { startPackagerTests } from "./packager.test";
1313
import { startVsixExistenceTest } from "./vsixbuild.test";
1414
import { startLogGrammarTests } from "./logGrammar.test";
15+
import { startNetworkInspectorTests } from "./networkInspector.test";
1516

1617
export function startSmokeTests(setup: () => Promise<void>, cleanUp: () => Promise<void>): void {
1718
// Guard: if mocha BDD hooks are absent, do not attempt to register tests
@@ -42,6 +43,7 @@ export function startSmokeTests(setup: () => Promise<void>, cleanUp: () => Promi
4243
startCommandPaletteTests();
4344
startFileExplorerTests();
4445
startPackagerTests();
46+
startNetworkInspectorTests();
4547
startActionBarTests();
4648
startDebugConfigurationTests();
4749
startCDPNodeVersionCompatibilityTests();

0 commit comments

Comments
 (0)