Skip to content

Commit b5ed37b

Browse files
authored
Set up Playwright for fast-element testing (#7239)
## 📖 Description Currently the tests in fast-element use Karma, Chai, and Mocha, this infrastructure is a bit outdated and doesn’t align with the tech stack used in fast-html and other projects we work on. It also makes it difficult to test in non-Chromium environments. This PR is intended to add a basic set up for using Playwright for all testing. Not all tests have been converted to use Playwright, and some aspects are still not working yet (e.g. when it involves decorator). But it’s a good starting point and we can incrementally migrate the rest of tests onto Playwright appoach. ### 🎫 Issues #7253
1 parent b245834 commit b5ed37b

22 files changed

+1072
-701
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "introduce playwright for testing",
4+
"packageName": "@microsoft/fast-element",
5+
"email": "machi@microsoft.com",
6+
"dependentChangeType": "none"
7+
}

packages/fast-element/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@
117117
"prettier:diff": "prettier --config ../../.prettierrc \"**/*.ts\" --list-different",
118118
"eslint": "eslint . --ext .ts",
119119
"eslint:fix": "eslint . --ext .ts --fix",
120-
"test": "npm run eslint && npm run test-chrome:verbose && npm run doc:ci && npm run doc:exports:ci",
120+
"test:playwright": "playwright test",
121+
"test-server": "npx vite test/ --clearScreen false",
122+
"test": "npm run eslint && npm run test-chrome:verbose && npm run doc:ci && npm run doc:exports:ci && npm run test:playwright",
121123
"test-node": "nyc --reporter=lcov --reporter=text-summary --report-dir=coverage/node --temp-dir=coverage/.nyc_output mocha --reporter min --exit dist/esm/__test__/setup-node.js './dist/esm/**/*.spec.js'",
122124
"test-node:verbose": "nyc --reporter=lcov --reporter=text-summary --report-dir=coverage/node --temp-dir=coverage/.nyc_output mocha --reporter spec --exit dist/esm/__test__/setup-node.js './dist/esm/**/*.spec.js'",
123125
"test-chrome": "karma start karma.conf.cjs --browsers=ChromeHeadlessOpt --single-run --coverage",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
export default defineConfig({
4+
testDir: ".",
5+
testMatch: "**/*.pw.spec.ts",
6+
retries: 3,
7+
projects: [
8+
{
9+
name: "chromium",
10+
use: { ...devices["Desktop Chrome"] },
11+
},
12+
],
13+
webServer: {
14+
command: "npm run test-server",
15+
port: 5173,
16+
reuseExistingServer: true,
17+
},
18+
});

packages/fast-element/src/components/fast-definitions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Constructable, isString, KernelServiceId } from "../interfaces.js";
22
import { Observable } from "../observation/observable.js";
3-
import { createTypeRegistry, FAST, TypeRegistry } from "../platform.js";
3+
import { createTypeRegistry, FAST, type TypeRegistry } from "../platform.js";
44
import { ComposableStyles, ElementStyles } from "../styles/element-styles.js";
55
import type { ElementViewTemplate } from "../templating/template.js";
66
import { AttributeConfiguration, AttributeDefinition } from "./attributes.js";

packages/fast-element/src/components/hydration.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import chai, { expect } from "chai";
2+
import "../debug.js";
23
import { css, HostBehavior, Updates } from "../index.js";
34
import { html } from "../templating/template.js";
45
import { uniqueElementName } from "../testing/exports.js";

0 commit comments

Comments
 (0)