From ecbfc7ecb02747f1fe907471de8e8d6a57e91df6 Mon Sep 17 00:00:00 2001 From: Jon Taylor Date: Thu, 20 Jun 2024 17:26:58 +0100 Subject: [PATCH] added playwright --- .gitignore | 4 +++ package.json | 4 ++- playwright.config.ts | 79 ++++++++++++++++++++++++++++++++++++++++++++ src/App.tsx | 1 + yarn.lock | 26 +++++++++++++++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 playwright.config.ts diff --git a/.gitignore b/.gitignore index a547bf3..b88c813 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ dist-ssr *.njsproj *.sln *.sw? +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ diff --git a/package.json b/package.json index bd05400..8b3d3e5 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dev": "vite", "build": "tsc && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "test": "npx playwright test", "preview": "vite preview" }, "dependencies": { @@ -25,6 +26,7 @@ "tailwind-merge": "^2.3.0" }, "devDependencies": { + "@playwright/test": "^1.44.1", "@types/audioworklet": "^0.0.55", "@types/node": "^20.14.5", "@types/react": "^18.2.66", @@ -47,4 +49,4 @@ "vite-plugin-static-copy": "^1.0.5", "vite-plugin-webfont-dl": "^3.9.4" } -} +} \ No newline at end of file diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..a61f5f2 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,79 @@ +import { defineConfig, devices } from "@playwright/test"; + +/** + * Read environment variables from file. + * https://github.com/motdotla/dotenv + */ +// import dotenv from 'dotenv'; +// dotenv.config({ path: path.resolve(__dirname, '.env') }); + +/** + * See https://playwright.dev/docs/test-configuration. + */ +export default defineConfig({ + testDir: "./tests", + /* Run tests in files in parallel */ + fullyParallel: true, + /* Fail the build on CI if you accidentally left test.only in the source code. */ + forbidOnly: !!process.env.CI, + /* Retry on CI only */ + retries: process.env.CI ? 2 : 0, + /* Opt out of parallel tests on CI. */ + workers: process.env.CI ? 1 : undefined, + /* Reporter to use. See https://playwright.dev/docs/test-reporters */ + reporter: "html", + /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ + use: { + /* Base URL to use in actions like `await page.goto('/')`. */ + baseURL: "http://localhost:5173/", + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace: "on-first-retry", + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: "chromium", + use: { ...devices["Desktop Chrome"] }, + }, + + { + name: "firefox", + use: { ...devices["Desktop Firefox"] }, + }, + + { + name: "webkit", + use: { ...devices["Desktop Safari"] }, + }, + + /* Test against mobile viewports. */ + // { + // name: 'Mobile Chrome', + // use: { ...devices['Pixel 5'] }, + // }, + // { + // name: 'Mobile Safari', + // use: { ...devices['iPhone 12'] }, + // }, + + /* Test against branded browsers. */ + // { + // name: 'Microsoft Edge', + // use: { ...devices['Desktop Edge'], channel: 'msedge' }, + // }, + // { + // name: 'Google Chrome', + // use: { ...devices['Desktop Chrome'], channel: 'chrome' }, + // }, + ], + + /* Run your local dev server before starting the tests */ + webServer: { + command: "yarn run dev", + url: "http://localhost:5173/", + timeout: 10 * 1000, + reuseExistingServer: !process.env.CI, + }, +}); diff --git a/src/App.tsx b/src/App.tsx index 0906bb8..15da914 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -191,6 +191,7 @@ export default function App() {