Skip to content

Commit acccf52

Browse files
authored
Add constants and element helper class in test (#2409)
* Add constants and element helper class in test * Update gulp file
1 parent df11864 commit acccf52

14 files changed

Lines changed: 138 additions & 81 deletions

File tree

.ci/smoke-tests-common-validation.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ steps:
77
Contents: |
88
$(System.DefaultWorkingDirectory)/*.vsix
99
TargetFolder: "$(System.DefaultWorkingDirectory)/test/smoke/resources/extension"
10-
- bash: npm run prepare-smoke-tests
10+
- script: npm run prepare-smoke-tests
1111
displayName: "Prepare smoke tests"
12-
- bash: npm run smoke-tests --verbose
12+
- script: npm run prepare-smoke-tests-project
13+
displayName: "Prepare smoke tests sample project"
14+
- script: npm run smoke-tests --verbose
1315
displayName: "Run smoke tests"
1416
env:
1517
DISPLAY: ":99.0"

.gitignore

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,27 @@ src/**/nodeDebugLocation.json
99
nls.*.json
1010
test/*.xml
1111
test/resources/projects/*
12+
test/**/*.js
13+
!test/**/.eslintrc.js
14+
test/smoke/vscode
15+
test/smoke/resources/sampleReactNativeProject
16+
!test/smoke/resources/sampleReactNativeProject/*.js
17+
!test/resources/sampleReactNativeProject/metro.config.js
18+
!test/resources/newVersionReactNativeProject/*.js
19+
test/smoke/*.xml
20+
test/smoke/screenshots
1221

1322
# Compiled files
1423
src/**/*.js
1524
dist/**
1625
!src/extension/appcenter/lib/**/*.js
17-
test/**/*.js
18-
!test/resources/sampleReactNativeProject/metro.config.js
19-
!test/resources/newVersionReactNativeProject/*.js
20-
!test/**/.eslintrc.js
21-
test/smoke/vscode
2226
!gulpfile.js
2327
SmokeTestLogs
2428
VSCodeUserData
2529
**/*.js.map
2630
vscode-react-native-*.vsix
2731
vscode-react-native-*.vsix.zip
2832
*-report
29-
!test/smoke/resources/sampleReactNativeProject/*.js
30-
test/smoke/*.xml
31-
test/smoke/screenshots
3233

3334
# Sample Application auto-generated files
3435
SampleApplication/.vscode/.react/debuggerWorker.js
@@ -43,4 +44,4 @@ SampleApplication/.watchmanconfig
4344
SampleApplication/.vscode/launchReactNative.js
4445
SampleApplication/.vscode/settings.json
4546
SampleApplication/tsconfig.json
46-
SampleApplication/.vscode/typings/
47+
SampleApplication/.vscode/typings/

gulp_scripts/formatter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const runPrettier = async fix => {
1515
"!test/smoke/.vscode-test/**",
1616
"!src/**/*.d.ts",
1717
"!SECURITY.md",
18+
"!test/smoke/resources/sampleReactNativeProject/**"
1819
],
1920
{
2021
stdio: "inherit",

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,6 +1418,7 @@
14181418
"test-localization": "node ./test/localization/runTest.js",
14191419
"prepare": "husky install",
14201420
"prepare-smoke-tests": "cd test/smoke && npm ci",
1421+
"prepare-smoke-tests-project": "cd test/smoke/resources/sampleReactNativeProject && npm install",
14211422
"smoke-tests": "cd test/smoke && tsc && node ./node_modules/mocha/bin/_mocha --config ./.mocharc.js --reporter mocha-multi-reporters"
14221423
},
14231424
"prettier": {

test/smoke/resources/sampleReactNativeProject/.gitignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/smoke/resources/sampleReactNativeProject/.vscode/emptyTelemetrySettings.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/smoke/resources/sampleReactNativeProject/.vscode/settings.json

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,34 @@
11
{
2-
"name": "sampleReactNativeProject",
2+
"name": "rn_0_81_0",
33
"version": "0.0.1",
44
"private": true,
5-
"scripts": {
6-
"start": "node node_modules/react-native/local-cli/cli.js start"
7-
},
85
"dependencies": {
9-
"react": "17.0.2",
10-
"react-native": "0.65.0",
11-
"react-native-windows": "0.65.9"
6+
"react": "19.1.0",
7+
"react-native": "0.81.0",
8+
"@react-native/new-app-screen": "0.81.0",
9+
"react-native-safe-area-context": "^5.5.2"
10+
},
11+
"devDependencies": {
12+
"@babel/core": "^7.25.2",
13+
"@babel/preset-env": "^7.25.3",
14+
"@babel/runtime": "^7.25.0",
15+
"@react-native-community/cli": "20.0.0",
16+
"@react-native-community/cli-platform-android": "20.0.0",
17+
"@react-native-community/cli-platform-ios": "20.0.0",
18+
"@react-native/babel-preset": "0.81.0",
19+
"@react-native/eslint-config": "0.81.0",
20+
"@react-native/metro-config": "0.81.0",
21+
"@react-native/typescript-config": "0.81.0",
22+
"@types/jest": "^29.5.13",
23+
"@types/react": "^19.1.0",
24+
"@types/react-test-renderer": "^19.1.0",
25+
"eslint": "^8.19.0",
26+
"jest": "^29.6.3",
27+
"prettier": "2.8.8",
28+
"react-test-renderer": "19.1.0",
29+
"typescript": "^5.8.3"
30+
},
31+
"engines": {
32+
"node": ">=18"
1233
}
13-
}
34+
}

test/smoke/suites/activation.test.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { Page } from "playwright";
55
import { SmokeTestLogger } from "./helper/smokeTestLogger";
66
import { app, screenshots } from "./main";
77
import assert = require("assert");
8+
import { ElementHelper } from "./helper/elementHelper";
9+
import { Constant } from "./helper/constants";
810

911
export function startExtensionActivationTests(): void {
1012
describe("ExtensionActivationTest", () => {
@@ -40,8 +42,28 @@ export function startExtensionActivationTests(): void {
4042
afterEach(dispose);
4143

4244
it("Verify extension is activated", async () => {
43-
const page = await initApp();
44-
const isActivited = await app.getExtension().checkExtensionActivated(page);
45+
let isActivited = false;
46+
await initApp();
47+
48+
try {
49+
await ElementHelper.WaitElementSelectorVisible(
50+
`[id="${Constant.previewExtensionId}"]`,
51+
2000,
52+
);
53+
SmokeTestLogger.info("React-native-preview extension is activated");
54+
isActivited = true;
55+
} catch {
56+
try {
57+
await ElementHelper.WaitElementSelectorVisible(
58+
`[id="${Constant.prodExtensionId}"]`,
59+
2000,
60+
);
61+
SmokeTestLogger.info("React-native-prod extension is activated");
62+
isActivited = true;
63+
} catch {
64+
isActivited = false;
65+
}
66+
}
4567
assert.ok(isActivited, "Extension is not activated. Skip other test cases...");
4668
});
4769
});

test/smoke/suites/commands.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { Page } from "playwright";
55
import { SmokeTestLogger } from "./helper/smokeTestLogger";
66
import { app, screenshots } from "./main";
77
import * as assert from "assert";
8+
import { ElementHelper } from "./helper/elementHelper";
9+
import { Element } from "./helper/constants";
810

911
export function startCommandPaletteTests(): void {
1012
describe("CommandPaletteTest", () => {
@@ -40,19 +42,20 @@ export function startCommandPaletteTests(): void {
4042
afterEach(dispose);
4143

4244
it("Verify react native command is visible in command palette", async () => {
43-
const page = await initApp();
45+
const text = "React Native: Start Packager";
46+
await initApp();
4447

45-
const cmdKey = process.platform === "darwin" ? "Meta" : "Control";
46-
await page.keyboard.press(`${cmdKey}+Shift+P`);
47-
await page.waitForSelector(".quick-input-widget", { timeout: 10000 });
48+
await ElementHelper.openCommandPalette();
49+
await ElementHelper.WaitElementClassNameVisible(Element.commandPaletteClassName, 5000);
4850

49-
await page.keyboard.type("React Native: Start Packager");
50-
const option = await page.waitForSelector("#quickInput_list .monaco-list-row.focused", {
51-
timeout: 30000,
52-
});
51+
await ElementHelper.inputText(text);
52+
const option = await ElementHelper.WaitElementSelectorVisible(
53+
Element.commandPaletteFocusedItemSelector,
54+
5000,
55+
);
5356

5457
const value = await option.getAttribute("aria-label");
55-
assert.ok(value?.includes("React Native: Start Packager"));
58+
assert.ok(value?.includes(text));
5659
});
5760
});
5861
}

0 commit comments

Comments
 (0)