Skip to content

Commit 3f8d75b

Browse files
authored
chore: add playwright system test (#64)
1 parent d570cf6 commit 3f8d75b

File tree

10 files changed

+179
-7
lines changed

10 files changed

+179
-7
lines changed

.github/workflows/verify-page.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Verifies gh-page is up and running
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- playwright-base
8+
workflow_dispatch:
9+
10+
jobs:
11+
verify-gh-page:
12+
runs-on: ubuntu-latest
13+
steps:
14+
# - name: Delay start
15+
# run: sleep 30s
16+
# shell: bash
17+
18+
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Setup node
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: 18
26+
27+
- name: Install dependencies
28+
run: |
29+
corepack enable
30+
corepack prepare --activate
31+
pnpm install --frozen-lockfile
32+
33+
- name: Run Playwright tests
34+
run: pnpm stest
35+
working-directory: ./examples
36+
37+
- uses: actions/upload-artifact@v3
38+
if: always()
39+
with:
40+
name: playwright-report
41+
path: examples/test-results/*
42+
retention-days: 5

examples/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ node_modules
33
dist
44
dist-ssr
55
*.local
6+
/test-results/
7+
/playwright-report/
8+
/playwright/.cache/

examples/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
"check:unused-deps": "depcheck . --config=depcheck.yml",
1818
"dev": "vite",
1919
"lint": "tsc --noEmit && eslint . --cache",
20-
"serve": "vite preview"
20+
"serve": "vite preview",
21+
"stest": "pnpm playwright test",
22+
"stest:ui": "pnpm playwright test --ui"
2123
},
2224
"dependencies": {
2325
"@axiscommunications/fluent-hooks": "workspace:*",
@@ -41,6 +43,8 @@
4143
"vite": "^3.0.9"
4244
},
4345
"devDependencies": {
46+
"@types/node": "^20.8.4",
47+
"@playwright/test": "1.38.1",
4448
"@types/react": "^17.0.67",
4549
"@types/react-dom": "^17.0.21",
4650
"eslint": "^8.52.0",

examples/playwright.confg.base.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { Config, PlaywrightTestConfig } from "@playwright/test";
2+
3+
type UseConfig = Config["use"];
4+
type Projects = Config["projects"];
5+
6+
export const chromium = ({ flags }: { flags?: string[] } = {}): UseConfig => ({
7+
browserName: "chromium",
8+
channel: process.env.BROWSER ?? "chrome",
9+
viewport: { width: 1280, height: 720 },
10+
permissions: ["clipboard-write", "clipboard-read"],
11+
launchOptions: {
12+
args: [
13+
"--ignore-certificate-errors",
14+
"--use-fake-ui-for-media-stream",
15+
"--use-fake-device-for-media-stream",
16+
...(flags ?? []),
17+
],
18+
},
19+
});
20+
21+
export function createConfig(
22+
projects: Projects,
23+
addUseOptions: Partial<PlaywrightTestConfig["use"]> = {}
24+
): PlaywrightTestConfig {
25+
return {
26+
forbidOnly: !!process.env.CI,
27+
projects: projects,
28+
use: {
29+
// Context options
30+
ignoreHTTPSErrors: true,
31+
contextOptions: {
32+
locale: "en_GB",
33+
},
34+
// Artifacts
35+
screenshot: "only-on-failure",
36+
trace: "on-first-retry",
37+
...addUseOptions,
38+
},
39+
retries: process.env.CI ? 1 : 0,
40+
reporter: process.env.CI ? [["github"], ["list"]] : [["list"]],
41+
};
42+
}

examples/playwright.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { PlaywrightTestConfig } from "@playwright/test";
2+
import { chromium, createConfig } from "./playwright.confg.base";
3+
4+
const config: PlaywrightTestConfig = {
5+
...createConfig([
6+
{
7+
name: "fluent-components:stest:chromium",
8+
use: chromium(),
9+
testMatch: ["system-test/**.stest.ts"],
10+
},
11+
]),
12+
};
13+
export default config;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { expect, test } from "@playwright/test";
2+
import { goToPage } from "./utils";
3+
4+
test("should be able to navigate to home page", async ({ page }) => {
5+
await goToPage(page);
6+
7+
const homePage = page.locator("#welcome-page");
8+
9+
await expect(homePage).toBeVisible();
10+
});

examples/system-test/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Page } from "@playwright/test";
2+
3+
const GH_PAGE = "https://axiscommunications.github.io/fluent-components/";
4+
const LOCAL_HOST = "http://127.0.0.1:3000/fluent-components/";
5+
6+
export function goToPage(page: Page, url?: string) {
7+
if (url) {
8+
return page.goto(url);
9+
}
10+
11+
const envUrl = isCi() ? GH_PAGE : LOCAL_HOST;
12+
return page.goto(envUrl);
13+
}
14+
15+
export function isCi(): boolean {
16+
return process.env.CI === "true";
17+
}

examples/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"extends": "../tsconfig.base.json",
33
"compilerOptions": {
44
"lib": ["es5", "es6", "dom", "dom.iterable", "ES2015", "es2017"],
5+
"types": ["node"],
56
"paths": {
67
"@axiscommunications/fluent-hooks": ["hooks/src"],
78
"@axiscommunications/fluent-password-input": [
@@ -18,5 +19,5 @@
1819
]
1920
}
2021
},
21-
"include": ["src"]
22+
"include": ["src", "system-test", "*.ts"]
2223
}

examples/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import path from "path";
55
// https://vitejs.dev/config/
66
export default defineConfig({
77
plugins: [react()],
8+
server: {
9+
port: 3000,
10+
},
811
base: "/fluent-components/",
912
resolve: {
1013
alias: {

pnpm-lock.yaml

Lines changed: 42 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)