Skip to content

Commit 2247d50

Browse files
authored
chore(web-components): Use Playwright fixture for tests (#33023)
1 parent 479f2f3 commit 2247d50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+4266
-5340
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "Allow field states to be set regardless of connection status",
4+
"packageName": "@fluentui/web-components",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"@nx/plugin": "19.8.4",
8585
"@nx/workspace": "19.8.4",
8686
"@octokit/rest": "18.12.0",
87+
"@oddbird/css-anchor-positioning": "0.4.0",
8788
"@phenomnomnominal/tsquery": "6.1.3",
8889
"@playwright/test": "1.49.1",
8990
"@react-native/babel-preset": "0.73.21",
@@ -224,7 +225,7 @@
224225
"enquirer": "2.3.6",
225226
"enzyme": "3.10.0",
226227
"enzyme-to-json": "3.6.2",
227-
"esbuild": "0.20.1",
228+
"esbuild": "0.24.2",
228229
"esbuild-loader": "4.1.0",
229230
"eslint": "8.57.0",
230231
"eslint-config-airbnb": "18.2.1",
@@ -342,6 +343,7 @@
342343
"tslib": "2.6.3",
343344
"typescript": "5.3.3",
344345
"vinyl": "2.2.0",
346+
"vite": "6.0.7",
345347
"webpack": "5.94.0",
346348
"webpack-bundle-analyzer": "4.10.1",
347349
"webpack-cli": "5.1.4",
@@ -374,7 +376,7 @@
374376
},
375377
"resolutions": {
376378
"@types/jest-axe/axe-core": "4.7.2",
377-
"esbuild": "0.20.1",
379+
"esbuild": "0.24.2",
378380
"eslint": "8.57.0",
379381
"swc-loader": "^0.2.6",
380382
"prettier": "2.8.8",

packages/web-components/.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
}
3636
],
3737
"comma-dangle": "off",
38+
"prefer-const": ["error", { "destructuring": "all" }],
3839
"@typescript-eslint/no-non-null-assertion": "off",
3940
"@typescript-eslint/no-use-before-define": "off",
4041
"@typescript-eslint/no-empty-interface": "error",

packages/web-components/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,6 @@ This is a known issue and will indicate that you need to refresh the page. We're
8989

9090
## Testing
9191

92-
When testing locally, start the dev server and in a separate terminal window, run `yarn test:dev` within the web-components folder.
92+
On CI, a static test harness build is first generated by running Vite in build mode. The Playwright tests are then run against the generated harness. To run Playwright tests in this mode, use the command `yarn nx run web-components:e2e`.
93+
94+
To run Playwright tests locally in [UI mode](https://playwright.dev/docs/test-ui-mode), use the command `yarn nx run web-components:e2e:local`. This will start a local development server with Vite and open the Playwright test runner UI.

packages/web-components/docs/api-report.md

+2
Original file line numberDiff line numberDiff line change
@@ -4060,6 +4060,8 @@ export class Tooltip extends FASTElement {
40604060
mouseleaveAnchorHandler: () => void;
40614061
positioning?: TooltipPositioningOption;
40624062
// @internal
4063+
positioningChanged(): void;
4064+
// @internal
40634065
showTooltip(delay?: number): void;
40644066
}
40654067

packages/web-components/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
"./package.json": "./package.json"
6666
},
6767
"sideEffects": [
68+
"define.*",
69+
"index-rollup.*",
6870
"./dist/esm/**/define.js",
6971
"./dist/web-components.js",
7072
"./dist/web-components.min.js"
@@ -86,8 +88,8 @@
8688
"start": "yarn start-storybook -p 6006 --docs",
8789
"start-storybook": "storybook dev",
8890
"build-storybook": "storybook build -o ./dist/storybook --docs",
89-
"e2e": "playwright test",
90-
"test:dev": "playwright test"
91+
"e2e": "node ./scripts/e2e.js",
92+
"e2e:local": "node ./scripts/e2e.js --ui"
9193
},
9294
"devDependencies": {
9395
"@microsoft/fast-element": "2.0.0",

packages/web-components/playwright.config.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,26 @@ const config: PlaywrightTestConfig = {
77
fullyParallel: process.env.CI ? false : true,
88
timeout: process.env.CI ? 10000 : 30000,
99
use: {
10-
baseURL: 'http://localhost:6006/iframe.html',
11-
viewport: {
12-
height: 720,
13-
width: 1280,
14-
},
10+
baseURL: 'http://localhost:5173',
1511
},
1612
projects: [
1713
{
1814
name: 'chromium',
1915
use: { ...devices['Desktop Chrome'] },
20-
testMatch: /.*\.spec\.ts$/,
2116
},
2217
{
2318
name: 'firefox',
2419
use: { ...devices['Desktop Firefox'] },
25-
testMatch: [/set-theme\.spec\.ts$/],
2620
},
2721
{
2822
name: 'webkit',
2923
use: { ...devices['Desktop Safari'] },
30-
testMatch: [/set-theme\.spec\.ts$/],
3124
},
3225
],
3326
webServer: {
34-
// double-quotes are required for Windows
35-
command: `node -e "import('express').then(({ default: e }) => e().use(e.static('./dist/storybook')).listen(6006))"`,
36-
port: 6006,
37-
reuseExistingServer: process.env.CI ? false : true,
27+
command: 'yarn vite preview test/harness',
28+
port: 5173,
29+
reuseExistingServer: true,
3830
},
3931
};
4032

packages/web-components/project.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"projectType": "library",
55
"implicitDependencies": [],
6-
"tags": ["platform:web", "web-components"],
7-
"targets": {
8-
"e2e": { "dependsOn": ["build-storybook"] }
9-
}
6+
"tags": ["platform:web", "web-components"]
107
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* eslint-env node */
2+
import { execSync, spawn } from 'node:child_process';
3+
4+
const uiMode = process.argv.includes('--ui');
5+
6+
try {
7+
// UI Mode runs Vite in development mode and Playwright in UI mode, in parallel
8+
if (uiMode) {
9+
const vite = spawn('vite', ['serve', 'test/harness'], { stdio: 'inherit' });
10+
const playwright = spawn('playwright', ['test', '--ui'], { stdio: 'inherit' });
11+
12+
// Forward the exit codes if the child processes exit
13+
vite.on('exit', code => process.exit(code));
14+
playwright.on('exit', code => process.exit(code));
15+
16+
// Close the processes when the parent process exits
17+
process.on('exit', () => {
18+
vite.kill();
19+
playwright.kill();
20+
process.exit(0);
21+
});
22+
23+
// Run both processes in parallel
24+
Promise.all([vite, playwright]);
25+
}
26+
27+
// E2E Mode first builds the test harness with Vite and then runs the tests with Playwright
28+
if (!uiMode) {
29+
// Build the test harness
30+
execSync(`vite build test/harness`, { stdio: 'inherit' });
31+
32+
// Run the tests
33+
execSync(`playwright test`, { stdio: 'inherit' });
34+
}
35+
} catch (err) {
36+
console.error(err);
37+
process.exit(1);
38+
}

0 commit comments

Comments
 (0)