Skip to content

Commit

Permalink
chore: added e2e tests with playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
lungarella-raffaele committed Jan 20, 2025
1 parent e7eaec4 commit c49e2f1
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 615 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# name: Playwright Tests
# on:
# push:
# branches: [main]
# pull_request:
# branches: [main]
# jobs:
# test_e2e:
# timeout-minutes: 60
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v4
# with:
# node-version: lts/*
# - name: Install dependencies
# run: npm install -g pnpm && pnpm install
# - name: Install Playwright Browsers
# run: pnpm exec playwright install --with-deps
# - name: Run Playwright tests
# run: pnpm exec playwright test
# - uses: actions/upload-artifact@v4
# if: ${{ !cancelled() }}
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 30

name: Playwright Tests
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test_all:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm install -g pnpm && pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Set environment variable for baseURL
run: echo "BASE_URL=https://emis-barber-shop.vercel.app/" >> $GITHUB_ENV
- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ vite.config.ts.timestamp-*

# Editors
.zed

# Playwright
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.13.0
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"format": "prettier --write .",
"lint": "prettier --check . && eslint .",
"test:unit": "vitest",
"test:e2e": "pnpm exec playwright test",
"test:report": "pnpm exec playwright show-report",
"test:codegen": "pnpm exec playwright codegen http://localhost:5173",
"test": "npm run test:unit -- --run",
"db:push": "drizzle-kit push",
"db:migrate": "drizzle-kit migrate",
Expand All @@ -19,11 +22,13 @@
"devDependencies": {
"@eslint/compat": "^1.2.5",
"@internationalized/date": "^3.7.0",
"@playwright/test": "^1.49.1",
"@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/adapter-vercel": "^5.5.3",
"@sveltejs/kit": "^2.16.0",
"@sveltejs/vite-plugin-svelte": "^5.0.3",
"@types/better-sqlite3": "^7.6.12",
"@types/node": "^22.10.7",
"autoprefixer": "^10.4.20",
"bits-ui": "1.0.0-next.77",
"clsx": "^2.1.1",
Expand All @@ -49,7 +54,7 @@
"typescript-eslint": "^8.20.0",
"vaul-svelte": "1.0.0-next.3",
"vite": "^6.0.7",
"vitest": "^2.1.8",
"vitest": "^3.0.0",
"zod": "^3.24.1"
},
"dependencies": {
Expand Down
79 changes: 79 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { defineConfig, devices } from '@playwright/test';

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// import dotenv from 'dotenv';
// import path from 'path';
// 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: process.env.BASE_URL || '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: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
Loading

0 comments on commit c49e2f1

Please sign in to comment.