From 0e0fa7bf54484666580a15f75b9dee60a0e34934 Mon Sep 17 00:00:00 2001 From: binit Date: Sat, 24 Jan 2026 21:38:09 +0530 Subject: [PATCH 1/2] feat: setup playright for e2e tests --- .github/workflows/playwright.yml | 27 +++++++++ .gitignore | 7 +++ package-lock.json | 71 +++++++++++++++++++++++- package.json | 14 +++-- playwright.config.ts | 94 ++++++++++++++++++++++++++++++++ 5 files changed, 205 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/playwright.yml create mode 100644 playwright.config.ts diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml new file mode 100644 index 0000000..3eb1314 --- /dev/null +++ b/.github/workflows/playwright.yml @@ -0,0 +1,27 @@ +name: Playwright Tests +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] +jobs: + test: + 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 ci + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Run Playwright tests + run: npx playwright test + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 diff --git a/.gitignore b/.gitignore index ee99180..6a419e3 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,10 @@ build/ #turbo repo .turbo + +# Playwright +/test-results/ +/playwright-report/ +/blob-report/ +/playwright/.cache/ +/playwright/.auth/ diff --git a/package-lock.json b/package-lock.json index 17f5a83..ca437a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,8 @@ ], "devDependencies": { "@changesets/cli": "^2.27.0", + "@playwright/test": "^1.58.0", + "@types/node": "^25.0.10", "prettier": "^3.0.0", "turbo": "^2.3.0" } @@ -4096,6 +4098,22 @@ "node": ">=14" } }, + "node_modules/@playwright/test": { + "version": "1.58.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.58.0.tgz", + "integrity": "sha512-fWza+Lpbj6SkQKCrU6si4iu+fD2dD3gxNHFhUPxsfXBPhnv3rRSQVd0NtBUT9Z/RhF/boCBcuUaMUSTRTopjZg==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.58.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@posthog/core": { "version": "1.11.0", "resolved": "https://registry.npmjs.org/@posthog/core/-/core-1.11.0.tgz", @@ -6658,9 +6676,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "25.0.3", - "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.3.tgz", - "integrity": "sha512-W609buLVRVmeW693xKfzHeIV6nJGGz98uCPfeXI1ELMLXVeKYZ9m15fAMSaUPBHYLGFsVRcMmSCksQOrZV9BYA==", + "version": "25.0.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.10.tgz", + "integrity": "sha512-zWW5KPngR/yvakJgGOmZ5vTBemDoSqF3AcV/LrO5u5wTWyEAVVh+IT39G4gtyAkh3CtTZs8aX/yRM82OfzHJRg==", "license": "MIT", "dependencies": { "undici-types": "~7.16.0" @@ -14309,6 +14327,53 @@ "pathe": "^2.0.3" } }, + "node_modules/playwright": { + "version": "1.58.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.58.0.tgz", + "integrity": "sha512-2SVA0sbPktiIY/MCOPX8e86ehA/e+tDNq+e5Y8qjKYti2Z/JG7xnronT/TXTIkKbYGWlCbuucZ6dziEgkoEjQQ==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.58.0" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.58.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.58.0.tgz", + "integrity": "sha512-aaoB1RWrdNi3//rOeKuMiS65UCcgOVljU46At6eFcOFPFHWtd2weHRRow6z/n+Lec0Lvu0k9ZPKJSjPugikirw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/playwright/node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/points-on-curve": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/points-on-curve/-/points-on-curve-0.2.0.tgz", diff --git a/package.json b/package.json index 5a22724..0a88702 100644 --- a/package.json +++ b/package.json @@ -12,18 +12,22 @@ "lint": "turbo lint", "clean": "turbo clean", "format": "prettier --write \"**/*.{ts,tsx,md}\"", + "test:e2e": "npx playwright test", + "test:e2e:watch": "npx playwright test --watch", + "show-report:e2e": "npx playwright show-report", "changeset": "changeset", "version-packages": "changeset version", "publish-packages": "changeset publish" }, "devDependencies": { - "turbo": "^2.3.0", "@changesets/cli": "^2.27.0", - "prettier": "^3.0.0" - } - , + "@playwright/test": "^1.58.0", + "@types/node": "^25.0.10", + "prettier": "^3.0.0", + "turbo": "^2.3.0" + }, "overrides": { "react": "19.2.3", "react-dom": "19.2.3" } -} \ No newline at end of file +} diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..1169a89 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,94 @@ +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: 'http://localhost:3000', + + /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ + trace:'on', + video: 'on', + screenshot: 'only-on-failure', + connectOptions: process.env.CI ? undefined : { + wsEndpoint: 'ws://127.0.0.1:3000/', + }, + }, + + /* Configure projects for major browsers */ + projects: [ + { + name: 'API', + testDir: './tests/api', + use:{ + + } + }, + { + name: 'web-chrome', + testDir: './tests/web', + use: { ...devices['Desktop Chrome'] }, + }, + + { + name: 'web-firefox', + testDir: './tests/web', + use: { ...devices['Desktop Firefox'] }, + }, + + { + name: 'web-webkit', + testDir: './tests/web', + 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://localhost:3000', + // reuseExistingServer: !process.env.CI, + // }, +}); From 164b69715533e875e797c7b12a0ff06ff5bc78c3 Mon Sep 17 00:00:00 2001 From: binit Date: Sat, 24 Jan 2026 21:48:07 +0530 Subject: [PATCH 2/2] fix: ci.yml --- .github/workflows/ci.yml | 21 +++++++++++++++++---- .github/workflows/playwright.yml | 27 --------------------------- 2 files changed, 17 insertions(+), 31 deletions(-) delete mode 100644 .github/workflows/playwright.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f3000d9..27e2afa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,28 +19,41 @@ jobs: with: fetch-depth: 2 - # 1️⃣ Upgrade to Node 22 (Required for MCP) + # 1 Upgrade to Node 22 (Required for MCP) - name: Setup Node.js 22 uses: actions/setup-node@v4 with: node-version: 22 cache: "npm" - # 2️⃣ Install Dependencies (With Dummy Env) + # 2 Install Dependencies (With Dummy Env) - name: Install Dependencies run: npm ci env: DATABASE_URL: "postgresql://dummy:password@localhost:5432/mydb" BETTER_AUTH_SECRET: "dummy_secret_for_install" - # 3️⃣ Generate Prisma Client (Direct Command) + # 3 Generate Prisma Client (Direct Command) # ⚠️ FIX: We run prisma directly here instead of via Turbo - name: Generate Prisma Client run: npx prisma generate --schema=apps/api/prisma/schema.prisma env: DATABASE_URL: "postgresql://dummy:password@localhost:5432/mydb" - # 4️⃣ Run Turbo Pipeline (Build & Lint only) + # 4 e2e Tests + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Run Playwright Tests + run: npx playwright test + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 + + + # 5 Run Turbo Pipeline (Build & Lint only) - name: Run Turbo Pipeline # ⚠️ FIX: Pass DATABASE_URL directly in the command line run: DATABASE_URL="postgresql://dummy:password@localhost:5432/mydb" npx turbo run build lint diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml deleted file mode 100644 index 3eb1314..0000000 --- a/.github/workflows/playwright.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Playwright Tests -on: - push: - branches: [ main, master ] - pull_request: - branches: [ main, master ] -jobs: - test: - 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 ci - - name: Install Playwright Browsers - run: npx playwright install --with-deps - - name: Run Playwright tests - run: npx playwright test - - uses: actions/upload-artifact@v4 - if: ${{ !cancelled() }} - with: - name: playwright-report - path: playwright-report/ - retention-days: 30