From d9fbc3b13e4e34483a0c713df75c5ae2348a82d3 Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Wed, 18 Dec 2024 13:15:27 -0500 Subject: [PATCH 1/9] update gh action to run tests on Vercel --- .github/workflows/Playwright.yml | 32 ++++++++++++++++++++++++-------- CHANGELOG.md | 1 + playwright.config.ts | 2 +- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/.github/workflows/Playwright.yml b/.github/workflows/Playwright.yml index 1a89fc81..3c9f3809 100644 --- a/.github/workflows/Playwright.yml +++ b/.github/workflows/Playwright.yml @@ -21,22 +21,38 @@ jobs: - name: Install Playwright run: npx playwright install --with-deps - - name: Build app - run: NODE_ENV=test npm run build + # Step 1: Retrieve the Vercel Preview URL + - name: vercel-preview-url + uses: zentered/vercel-preview-url@v1.1.9 + id: vercel_preview_url + env: + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + GITHUB_REF: "main" + GITHUB_REPOSITORY: "your-repo/your-project" + with: + vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID }} - - name: Start the app - run: | - NODE_ENV=test npm start & - sleep 5 - shell: bash + # Step 2: Wait for the Vercel deployment to be ready + - uses: UnlyEd/github-action-await-vercel@v1 + id: await-vercel + env: + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + with: + deployment-url: ${{ steps.vercel_preview_url.outputs.preview_url }} + timeout: 420 + poll-interval: 15 - name: Run your tests + env: + BASE_URL: ${{ steps.vercel_preview_url.outputs.preview_url }} run: npm run playwright - name: Set the world parameters as an env var + env: + BASE_URL: ${{ steps.vercel_preview_url.outputs.preview_url }} # WORLD_PARAMETERS set here will override anything set in cucumber.json run: | - echo "WORLD_PARAMETERS={\"headless\": true}" >> $GITHUB_ENV + echo "WORLD_PARAMETERS={\"appUrl\": \"$BASE_URL\", \"headless\": true}" >> $GITHUB_ENV - name: Run Cucumber tests run: npm run cucumber -- playwright/features --world-parameters '${{ env.WORLD_PARAMETERS }}' diff --git a/CHANGELOG.md b/CHANGELOG.md index c7755440..22d242ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Remove Kristo, Jiayong, and Olivia and add Kyle as codeowners - Deploy to new Terraform ECS cluster in production - Deploy only to the new Terraform ECS clusters +- Update GH action to run playwright and cucumber tests on Vercel deployment ## [0.18.9] diff --git a/playwright.config.ts b/playwright.config.ts index dd255b66..79da4653 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -22,7 +22,7 @@ const config: PlaywrightTestConfig = { use: { headless: true, // Base URL to use in actions like `await page.goto('/')`. - baseURL: "http://localhost:3000", + baseURL: process.env.BASE_URL, /* When running tests locally, record a trace for each test, but remove it from successful runs. * On CI, turn this feature off. See https://playwright.dev/docs/trace-viewer */ From 8ebf2ea81e4a104a5055a2e32e4d4e530ce9d5c8 Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Wed, 18 Dec 2024 13:27:22 -0500 Subject: [PATCH 2/9] update repo --- .github/workflows/Playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Playwright.yml b/.github/workflows/Playwright.yml index 3c9f3809..7685965a 100644 --- a/.github/workflows/Playwright.yml +++ b/.github/workflows/Playwright.yml @@ -28,7 +28,7 @@ jobs: env: VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} GITHUB_REF: "main" - GITHUB_REPOSITORY: "your-repo/your-project" + GITHUB_REPOSITORY: "NYPL/sfr-bookfinder-front-end" with: vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID }} From 9690da5af4ad1e2a3bf186a70294a8900724ffcc Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Wed, 18 Dec 2024 13:46:14 -0500 Subject: [PATCH 3/9] run tests on deployment success --- .github/workflows/Playwright.yml | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/.github/workflows/Playwright.yml b/.github/workflows/Playwright.yml index 7685965a..939d036e 100644 --- a/.github/workflows/Playwright.yml +++ b/.github/workflows/Playwright.yml @@ -1,12 +1,15 @@ name: Playwright Tests for Digital Research Books on: - pull_request: + deployment_status: jobs: tests: + if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' name: Run Tests runs-on: ubuntu-latest + env: + BASE_URL: ${{ github.event.deployment_status.target_url }} steps: - name: Checkout uses: actions/checkout@v4 @@ -21,35 +24,10 @@ jobs: - name: Install Playwright run: npx playwright install --with-deps - # Step 1: Retrieve the Vercel Preview URL - - name: vercel-preview-url - uses: zentered/vercel-preview-url@v1.1.9 - id: vercel_preview_url - env: - VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} - GITHUB_REF: "main" - GITHUB_REPOSITORY: "NYPL/sfr-bookfinder-front-end" - with: - vercel_project_id: ${{ secrets.VERCEL_PROJECT_ID }} - - # Step 2: Wait for the Vercel deployment to be ready - - uses: UnlyEd/github-action-await-vercel@v1 - id: await-vercel - env: - VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} - with: - deployment-url: ${{ steps.vercel_preview_url.outputs.preview_url }} - timeout: 420 - poll-interval: 15 - - name: Run your tests - env: - BASE_URL: ${{ steps.vercel_preview_url.outputs.preview_url }} run: npm run playwright - name: Set the world parameters as an env var - env: - BASE_URL: ${{ steps.vercel_preview_url.outputs.preview_url }} # WORLD_PARAMETERS set here will override anything set in cucumber.json run: | echo "WORLD_PARAMETERS={\"appUrl\": \"$BASE_URL\", \"headless\": true}" >> $GITHUB_ENV From a4ffd82e021e22d34256015a29b77e533121148a Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Wed, 18 Dec 2024 13:55:53 -0500 Subject: [PATCH 4/9] readd build step --- .github/workflows/Playwright.yml | 3 +++ playwright.config.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Playwright.yml b/.github/workflows/Playwright.yml index 939d036e..b9d88ed7 100644 --- a/.github/workflows/Playwright.yml +++ b/.github/workflows/Playwright.yml @@ -24,6 +24,9 @@ jobs: - name: Install Playwright run: npx playwright install --with-deps + - name: Build app + run: NODE_ENV=test npm run build + - name: Run your tests run: npm run playwright diff --git a/playwright.config.ts b/playwright.config.ts index 79da4653..dd255b66 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -22,7 +22,7 @@ const config: PlaywrightTestConfig = { use: { headless: true, // Base URL to use in actions like `await page.goto('/')`. - baseURL: process.env.BASE_URL, + baseURL: "http://localhost:3000", /* When running tests locally, record a trace for each test, but remove it from successful runs. * On CI, turn this feature off. See https://playwright.dev/docs/trace-viewer */ From 2b837dc319f31507e5ed14b0c82a257736b0ebf5 Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Wed, 18 Dec 2024 14:32:11 -0500 Subject: [PATCH 5/9] update baseUrl for pw tests and temp disable slack notifs --- .github/workflows/Playwright.yml | 18 +++++++++--------- playwright.config.ts | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Playwright.yml b/.github/workflows/Playwright.yml index b9d88ed7..6c5b20f1 100644 --- a/.github/workflows/Playwright.yml +++ b/.github/workflows/Playwright.yml @@ -43,12 +43,12 @@ jobs: CUCUMBER_PUBLISH_TOKEN: ${{ secrets.CUCUMBER_PUBLISH_TOKEN }} CUCUMBER_PUBLISH_ENABLED: true - - name: Slack Notification - if: ${{ always() }} - uses: rtCamp/action-slack-notify@v2 - env: - SLACK_CHANNEL: test_reports - SLACK_MESSAGE: https://reports.cucumber.io/report-collections/01dbd6e8-653b-4597-b901-6caf2e653b07 - SLACK_TITLE: DRB Cucumber/Playwright Test Results - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - SLACK_USERNAME: nyplorgBot + # - name: Slack Notification + # if: ${{ always() }} + # uses: rtCamp/action-slack-notify@v2 + # env: + # SLACK_CHANNEL: test_reports + # SLACK_MESSAGE: https://reports.cucumber.io/report-collections/01dbd6e8-653b-4597-b901-6caf2e653b07 + # SLACK_TITLE: DRB Cucumber/Playwright Test Results + # SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + # SLACK_USERNAME: nyplorgBot diff --git a/playwright.config.ts b/playwright.config.ts index dd255b66..79da4653 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -22,7 +22,7 @@ const config: PlaywrightTestConfig = { use: { headless: true, // Base URL to use in actions like `await page.goto('/')`. - baseURL: "http://localhost:3000", + baseURL: process.env.BASE_URL, /* When running tests locally, record a trace for each test, but remove it from successful runs. * On CI, turn this feature off. See https://playwright.dev/docs/trace-viewer */ From e98041a51f7977b7248c88c58eed61eee547b4de Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Wed, 18 Dec 2024 15:40:11 -0500 Subject: [PATCH 6/9] skip login test and add edd login test --- playwright/features/edd.feature | 10 ++++++++-- playwright/integration/auth.spec.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/playwright/features/edd.feature b/playwright/features/edd.feature index a32a515f..a0781008 100644 --- a/playwright/features/edd.feature +++ b/playwright/features/edd.feature @@ -4,5 +4,11 @@ Feature: EDD Request Process Given I go to the "home" page When I fill in the "homepage search box" with "Africa" And I click the "search button" - And I click the "requestable checkbox" - Then the "first login for options button" should be displayed + And I click the "requestable checkbox" + And I click the "first login for options button" + And I fill in the "username field" with "catalog username" + And I fill in the "password field" with "catalog password" + And I click the "login button" + And the "first request button" should be displayed + And I click the "first request button" + Then the "delivery location heading" should be displayed diff --git a/playwright/integration/auth.spec.ts b/playwright/integration/auth.spec.ts index fcdb1db0..429ad51a 100644 --- a/playwright/integration/auth.spec.ts +++ b/playwright/integration/auth.spec.ts @@ -14,7 +14,7 @@ test.beforeEach(async ({ context }) => { test.afterEach(() => server.resetHandlers()); test.afterAll(() => server.close()); -test.describe("Cookie authentication", () => { +test.skip("Cookie authentication", () => { test("redirects to NYPL log in page with no cookie", async ({ page }) => { await page.goto(`${LIMITED_ACCESS_EDITION_PATH}`); await page.getByTestId(LOGIN_TO_READ_TEST_ID).click(); From f22d1615dd71080e62cbfa99fba607ec669a406b Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Thu, 19 Dec 2024 12:07:03 -0500 Subject: [PATCH 7/9] try running tests on local with updated hostname --- .github/workflows/Playwright.yml | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Playwright.yml b/.github/workflows/Playwright.yml index 6c5b20f1..a9d34823 100644 --- a/.github/workflows/Playwright.yml +++ b/.github/workflows/Playwright.yml @@ -1,15 +1,12 @@ name: Playwright Tests for Digital Research Books on: - deployment_status: + pull_request: jobs: tests: - if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' name: Run Tests runs-on: ubuntu-latest - env: - BASE_URL: ${{ github.event.deployment_status.target_url }} steps: - name: Checkout uses: actions/checkout@v4 @@ -18,6 +15,19 @@ jobs: with: node-version-file: ".nvmrc" + - name: Set environment for branch + run: | + if [[ $GITHUB_REF_NAME == 'production' ]]; then + echo "BASE_URL=https://drb-qa.nypl.org/" >> "$GITHUB_ENV" + else + echo "BASE_URL=http://local.nypl.org:3000/" >> "$GITHUB_ENV" + fi + + - name: Add hosts to /etc/hosts + if: github.ref != 'production' + run: | + sudo echo "127.0.0.1 local.nypl.org" | sudo tee -a /etc/hosts + - name: Install Test Dependencies run: npm i @cucumber/cucumber@8.11.1 @playwright/test@1.29.1 @@ -27,6 +37,13 @@ jobs: - name: Build app run: NODE_ENV=test npm run build + - name: Start the app + if: github.ref != 'production' + run: | + NODE_ENV=test npm start & + sleep 5 + shell: bash + - name: Run your tests run: npm run playwright From 6fe18f08a5338f6a0f05f67017f6f73c97e6771d Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Thu, 19 Dec 2024 13:27:22 -0500 Subject: [PATCH 8/9] update changelog and reenable slack notifs --- .github/workflows/Playwright.yml | 18 +++++++++--------- CHANGELOG.md | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Playwright.yml b/.github/workflows/Playwright.yml index a9d34823..f4e2f946 100644 --- a/.github/workflows/Playwright.yml +++ b/.github/workflows/Playwright.yml @@ -60,12 +60,12 @@ jobs: CUCUMBER_PUBLISH_TOKEN: ${{ secrets.CUCUMBER_PUBLISH_TOKEN }} CUCUMBER_PUBLISH_ENABLED: true - # - name: Slack Notification - # if: ${{ always() }} - # uses: rtCamp/action-slack-notify@v2 - # env: - # SLACK_CHANNEL: test_reports - # SLACK_MESSAGE: https://reports.cucumber.io/report-collections/01dbd6e8-653b-4597-b901-6caf2e653b07 - # SLACK_TITLE: DRB Cucumber/Playwright Test Results - # SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - # SLACK_USERNAME: nyplorgBot + - name: Slack Notification + if: ${{ always() }} + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_CHANNEL: test_reports + SLACK_MESSAGE: https://reports.cucumber.io/report-collections/01dbd6e8-653b-4597-b901-6caf2e653b07 + SLACK_TITLE: DRB Cucumber/Playwright Test Results + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} + SLACK_USERNAME: nyplorgBot diff --git a/CHANGELOG.md b/CHANGELOG.md index 22d242ed..cefcd5de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - Remove Kristo, Jiayong, and Olivia and add Kyle as codeowners - Deploy to new Terraform ECS cluster in production - Deploy only to the new Terraform ECS clusters -- Update GH action to run playwright and cucumber tests on Vercel deployment +- Update GH action to run tests against local.nypl.org and QA for prod PRs ## [0.18.9] From 1e1b3e5b78fc1f521eac1e053e3b2a464cc0a009 Mon Sep 17 00:00:00 2001 From: Jackie Quach Date: Tue, 31 Dec 2024 11:11:53 -0500 Subject: [PATCH 9/9] update auth tests --- mocks/mockEnv.ts | 2 +- playwright/integration/auth.spec.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mocks/mockEnv.ts b/mocks/mockEnv.ts index 451550b0..fce05f98 100644 --- a/mocks/mockEnv.ts +++ b/mocks/mockEnv.ts @@ -1,4 +1,4 @@ -export const NYPL_LOGIN_URL = "https://login.nypl.org/auth/login?redirect_uri="; +export const NYPL_LOGIN_URL = "login.nypl.org"; export const API_URL = "https://backend.msw"; export const FULFILL_PATH = "/fulfill/9351827"; export const LIMITED_ACCESS_EDITION_PATH = "/edition/6977884"; diff --git a/playwright/integration/auth.spec.ts b/playwright/integration/auth.spec.ts index 429ad51a..6615ed90 100644 --- a/playwright/integration/auth.spec.ts +++ b/playwright/integration/auth.spec.ts @@ -14,15 +14,15 @@ test.beforeEach(async ({ context }) => { test.afterEach(() => server.resetHandlers()); test.afterAll(() => server.close()); -test.skip("Cookie authentication", () => { - test("redirects to NYPL log in page with no cookie", async ({ page }) => { +test.describe("Cookie authentication", () => { + test("redirects to NYPL login page with no cookie", async ({ page }) => { await page.goto(`${LIMITED_ACCESS_EDITION_PATH}`); await page.getByTestId(LOGIN_TO_READ_TEST_ID).click(); - await page.waitForURL(`**${NYPL_LOGIN_URL}**`); + await page.waitForURL(/.*login.nypl.org.*/); const url = new URL(page.url()); - const redirectUri = url.searchParams.get("redirect_uri"); + const service = url.searchParams.get("service"); - expect(redirectUri).toContain(LIMITED_ACCESS_EDITION_PATH); + expect(service).toContain(NYPL_LOGIN_URL); }); test("redirects to NYPL login page with expired cookie", async ({ @@ -34,11 +34,11 @@ test.skip("Cookie authentication", () => { await page.goto(`${LIMITED_ACCESS_EDITION_PATH}`); await page.getByTestId(LOGIN_TO_READ_TEST_ID).click(); - await page.waitForURL(`**${NYPL_LOGIN_URL}**`); + await page.waitForURL(/.*login.nypl.org.*/); const url = new URL(page.url()); - const redirectUri = url.searchParams.get("redirect_uri"); + const service = url.searchParams.get("service"); - expect(redirectUri).toContain(LIMITED_ACCESS_EDITION_PATH); + expect(service).toContain(NYPL_LOGIN_URL); }); // TODO: logging in from localhost does not work