Skip to content

Commit

Permalink
chore: add playwright system test (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
axis-d0op authored Oct 27, 2023
1 parent d570cf6 commit 3f8d75b
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 7 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/verify-page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Verifies gh-page is up and running

on:
push:
branches:
- main
- playwright-base
workflow_dispatch:

jobs:
verify-gh-page:
runs-on: ubuntu-latest
steps:
# - name: Delay start
# run: sleep 30s
# shell: bash

- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: |
corepack enable
corepack prepare --activate
pnpm install --frozen-lockfile
- name: Run Playwright tests
run: pnpm stest
working-directory: ./examples

- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: examples/test-results/*
retention-days: 5
3 changes: 3 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ node_modules
dist
dist-ssr
*.local
/test-results/
/playwright-report/
/playwright/.cache/
6 changes: 5 additions & 1 deletion examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"check:unused-deps": "depcheck . --config=depcheck.yml",
"dev": "vite",
"lint": "tsc --noEmit && eslint . --cache",
"serve": "vite preview"
"serve": "vite preview",
"stest": "pnpm playwright test",
"stest:ui": "pnpm playwright test --ui"
},
"dependencies": {
"@axiscommunications/fluent-hooks": "workspace:*",
Expand All @@ -41,6 +43,8 @@
"vite": "^3.0.9"
},
"devDependencies": {
"@types/node": "^20.8.4",
"@playwright/test": "1.38.1",
"@types/react": "^17.0.67",
"@types/react-dom": "^17.0.21",
"eslint": "^8.52.0",
Expand Down
42 changes: 42 additions & 0 deletions examples/playwright.confg.base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Config, PlaywrightTestConfig } from "@playwright/test";

type UseConfig = Config["use"];
type Projects = Config["projects"];

export const chromium = ({ flags }: { flags?: string[] } = {}): UseConfig => ({
browserName: "chromium",
channel: process.env.BROWSER ?? "chrome",
viewport: { width: 1280, height: 720 },
permissions: ["clipboard-write", "clipboard-read"],
launchOptions: {
args: [
"--ignore-certificate-errors",
"--use-fake-ui-for-media-stream",
"--use-fake-device-for-media-stream",
...(flags ?? []),
],
},
});

export function createConfig(
projects: Projects,
addUseOptions: Partial<PlaywrightTestConfig["use"]> = {}
): PlaywrightTestConfig {
return {
forbidOnly: !!process.env.CI,
projects: projects,
use: {
// Context options
ignoreHTTPSErrors: true,
contextOptions: {
locale: "en_GB",
},
// Artifacts
screenshot: "only-on-failure",
trace: "on-first-retry",
...addUseOptions,
},
retries: process.env.CI ? 1 : 0,
reporter: process.env.CI ? [["github"], ["list"]] : [["list"]],
};
}
13 changes: 13 additions & 0 deletions examples/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PlaywrightTestConfig } from "@playwright/test";
import { chromium, createConfig } from "./playwright.confg.base";

const config: PlaywrightTestConfig = {
...createConfig([
{
name: "fluent-components:stest:chromium",
use: chromium(),
testMatch: ["system-test/**.stest.ts"],
},
]),
};
export default config;
10 changes: 10 additions & 0 deletions examples/system-test/home-page.stest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { expect, test } from "@playwright/test";
import { goToPage } from "./utils";

test("should be able to navigate to home page", async ({ page }) => {
await goToPage(page);

const homePage = page.locator("#welcome-page");

await expect(homePage).toBeVisible();
});
17 changes: 17 additions & 0 deletions examples/system-test/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Page } from "@playwright/test";

const GH_PAGE = "https://axiscommunications.github.io/fluent-components/";
const LOCAL_HOST = "http://127.0.0.1:3000/fluent-components/";

export function goToPage(page: Page, url?: string) {
if (url) {
return page.goto(url);
}

const envUrl = isCi() ? GH_PAGE : LOCAL_HOST;
return page.goto(envUrl);
}

export function isCi(): boolean {
return process.env.CI === "true";
}
3 changes: 2 additions & 1 deletion examples/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "../tsconfig.base.json",
"compilerOptions": {
"lib": ["es5", "es6", "dom", "dom.iterable", "ES2015", "es2017"],
"types": ["node"],
"paths": {
"@axiscommunications/fluent-hooks": ["hooks/src"],
"@axiscommunications/fluent-password-input": [
Expand All @@ -18,5 +19,5 @@
]
}
},
"include": ["src"]
"include": ["src", "system-test", "*.ts"]
}
3 changes: 3 additions & 0 deletions examples/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 3000,
},
base: "/fluent-components/",
resolve: {
alias: {
Expand Down
47 changes: 42 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3f8d75b

Please sign in to comment.