From b042251ad3b552407b690cd75054cc3b11527e46 Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Sat, 23 Mar 2024 19:46:10 -0400 Subject: [PATCH] Hopefully fix e2e tests on CI --- .github/workflows/playwright.yml | 39 ++++++++++++++++++++++++++++---- src/middleware.ts | 12 ++++------ 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 82e612f2..f2d3cbcc 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -1,11 +1,27 @@ -name: Playwright Tests +name: Run test suites on: push: branches: [main, master] pull_request: branches: [main, master] jobs: - test: + generate-test-run-id: + name: Generate Test Run ID + runs-on: ubuntu-latest + steps: + - run: yarn add uuid + shell: sh + - uses: actions/github-script@v6 + id: uuid + with: + result-encoding: string + script: return require("uuid").v4() + outputs: + testRunId: ${{ steps.uuid.outputs.result }} + e2e-test: + if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' + name: Playwright e2e tests + needs: [generate-test-run-id] timeout-minutes: 60 runs-on: ubuntu-latest steps: @@ -18,12 +34,27 @@ jobs: - name: Install Playwright Browsers run: pnpm exec playwright install --with-deps - name: Run Playwright tests - run: pnpm exec playwright test + run: pnpm test:e2e env: - NEXT_PUBLIC_APP_URL: ${{ needs.preview-branch.outputs.url }} + NEXT_PUBLIC_APP_URL: ${{ github.event.deployment_status.environment_url }} + RECORD_REPLAY_TEST_RUN_ID: ${{ needs.generate-test-run-id.outputs.testRunId }} - uses: actions/upload-artifact@v4 if: always() with: name: playwright-report path: playwright-report/ retention-days: 30 + unit-test: + name: Unit Tests + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: "16" + - name: Install dependencies + run: npm install -g pnpm && pnpm install + - name: Run tests + run: pnpm test diff --git a/src/middleware.ts b/src/middleware.ts index 8e61cd1b..d592bdae 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -46,15 +46,13 @@ export async function middleware(request: NextRequest) { // Require authentication for protected routes if (pathname.startsWith("/org") || pathname.startsWith("/team")) { - // e2e tests + // Support e2e test and Support workflows const url = new URL(nextUrl); - if (url.searchParams.has("e2e")) { - const apiKey = url.searchParams.get("apiKey"); - if (apiKey) { - response.headers.set(HEADERS.accessToken, apiKey); + const apiKey = url.searchParams.get("apiKey"); + if (apiKey) { + response.headers.set(HEADERS.accessToken, apiKey); - return response; - } + return response; } const session = await getSession(request, response);