diff --git a/.github/workflows/e2e-tests.yml b/.github/workflows/e2e-tests.yml new file mode 100644 index 00000000..2e8b9cf3 --- /dev/null +++ b/.github/workflows/e2e-tests.yml @@ -0,0 +1,64 @@ +name: E2E Tests + +on: + push: + branches: + - develop + pull_request: + branches: + - develop + +jobs: + e2e: + runs-on: ubuntu-latest + + env: + DATABASE_URL: "postgresql://postgres:secret@localhost:5432/postgres" + NEXTAUTH_URL: http://localhost:3000/api/auth + GITHUB_ID: ${{ secrets.E2E_GITHUB_ID }} + GITHUB_SECRET: ${{ secrets.E2E_GITHUB_SECRET }} + NEXTAUTH_SECRET: "please_keep_this_secret" + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 'lts/*' + + - name: Run docker-compose + uses: hoverkraft-tech/compose-action@v2.0.1 + with: + compose-file: "./docker-compose.yml" + services: | + db + + - name: Wait for DB to be ready + run: | + until nc -z localhost 5432; do + echo "Waiting for database connection..." + sleep 5 + done + + - name: Install dependencies + run: npm install + + - name: Install Playwright browsers + run: npx playwright install --with-deps + + - name: Seed database + run: | + npm run db:push + npm run db:seed + + - name: Run Playwright tests + run: npx playwright test --reporter=html + + - uses: actions/upload-artifact@v4 + if: ${{ !cancelled() }} + with: + name: playwright-report + path: playwright-report/ + retention-days: 30 \ No newline at end of file diff --git a/e2e/articles.spec.ts b/e2e/articles.spec.ts index c50edd6b..89143ffd 100644 --- a/e2e/articles.spec.ts +++ b/e2e/articles.spec.ts @@ -1,6 +1,6 @@ import { test, expect } from "playwright/test"; -test.describe("Articles", () => { +test.skip("Articles", () => { test("Should load more articles when scrolling to the end of the page", async ({ page, }) => { diff --git a/package.json b/package.json index 2a520e11..d49bd56c 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "dev": "next dev", + "dev:e2e": "ENV=E2E next dev", "build": "next build", "ci-build": "next build", "start": "next start", diff --git a/playwright.config.ts b/playwright.config.ts index 674b903d..85afad1d 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -49,10 +49,10 @@ export default defineConfig({ // }, /* Test against mobile viewports. */ - { - name: "Mobile Chrome", - use: { ...devices["Pixel 5"] }, - }, + // { + // name: "Mobile Chrome", + // use: { ...devices["Pixel 5"] }, + // }, // { // name: 'Mobile Safari', // use: { ...devices['iPhone 12'] }, @@ -69,9 +69,11 @@ export default defineConfig({ // }, ], + outputDir: "playwright-report", + /* Run your local dev server before starting the tests */ webServer: { - command: "npm run dev", + command: "npm run dev:e2e", url: "http://127.0.0.1:3000", reuseExistingServer: !process.env.CI, },