test(playwright): install playwright

This commit is contained in:
Mona Mayrhofer 2025-04-03 14:27:24 +02:00
parent 85afa969f1
commit b3018ccfc9
No known key found for this signature in database
GPG key ID: 5C83114FA383C6A0
7 changed files with 74 additions and 2 deletions

View file

@ -10,7 +10,8 @@
"typecheck": "react-router typegen && tsc",
"lint": "biome lint . && stylelint **/*.css",
"preview": "vite preview",
"test": "vitest"
"test": "vitest",
"playwright": "playwright test"
},
"dependencies": {
"@pigment-css/react": "0.0.30",
@ -27,6 +28,7 @@
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@pigment-css/vite-plugin": "0.0.30",
"@playwright/test": "1.50.1",
"@react-router/dev": "7.4.1",
"@types/lodash": "4.17.16",
"@types/node": "22.13.17",

View file

@ -0,0 +1,44 @@
import { defineConfig, devices } from "@playwright/test";
export default defineConfig({
// Look for test files in the "tests" directory, relative to this configuration file.
testDir: "tests",
// Run all tests in parallel.
fullyParallel: true,
...(process.env["CI"]
? {
// Fail the build on CI if you accidentally left test.only in the source code.
forbidOnly: true,
// Retry on CI only.
retries: 2,
// Opt out of parallel tests on CI.
workers: 1,
}
: {}),
// Reporter to use
reporter: "html",
use: {
// Base URL to use in actions like `await page.goto('/')`.
baseURL: "http://localhost:5173",
// Collect trace when retrying the failed test.
trace: "on-first-retry",
},
// Configure projects for major browsers.
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
},
],
// Run your local dev server before starting the tests.
// webServer: {
// command: "npm run start",
// url: "http://localhost:3000",
// reuseExistingServer: !process.env["CI"],
// },
});

View file

@ -0,0 +1,18 @@
import { expect, test } from '@playwright/test';
test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
});
test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');
// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();
// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});

View file

@ -1,7 +1,7 @@
{
"files": [],
"extends": "../../tsconfig.base.json",
"include": ["app", "*.ts"],
"include": ["app", "*.ts", "tests"],
"compilerOptions": {
"types": ["vitest/importMeta", "vite/client", "node"],
"rootDirs": [".", "./.react-router/types"],