Skip to content

Commit

Permalink
wip: Debug E2E test failures in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
flozia committed Sep 5, 2024
1 parent c37e0b3 commit 4bf3d6b
Show file tree
Hide file tree
Showing 20 changed files with 968 additions and 950 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ E2E_TEST_ACCOUNT_EMAIL_ZERO_BROKERS=
E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES_ZERO_BROKERS=
E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED=

E2E_TEST_PAYPAL_LOGIN =
E2E_TEST_PAYPAL_PASSWORD =
E2E_TEST_PAYPAL_LOGIN=
E2E_TEST_PAYPAL_PASSWORD=

# Monitor Premium features
# Link to start user on the subscription process. PREMIUM_ENABLED must be set to `true`.
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Build

on:
pull_request:
types: [closed]
on: [push]

jobs:
npm-build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker_build_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Build Docker image and publish

on:
pull_request:
types: [closed]
push:
branches: [ main ]
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/docker_check.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Build Docker image check
on:
pull_request:
types: [closed]
jobs:
docker_build:
name: Build Docker image
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/e2e_cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: npm run e2e
timeout-minutes: 40
env:
E2E_TEST_ENV: ${{ inputs.environment != null && inputs.environment || 'local' }}
E2E_TEST_ENV: ${{ inputs.environment != null && inputs.environment || 'stage' }}
E2E_TEST_BASE_URL: ${{ secrets.E2E_TEST_BASE_URL }}
E2E_TEST_ACCOUNT_EMAIL: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL }}
E2E_TEST_ACCOUNT_PASSWORD: ${{ secrets.E2E_TEST_ACCOUNT_PASSWORD }}
Expand Down Expand Up @@ -76,6 +76,7 @@ jobs:
name: test-results
path: src/e2e/test-results/
retention-days: 30

- name: Send GitHub Action trigger data to Slack workflow
id: slack
uses: slackapi/[email protected]
Expand All @@ -89,7 +90,7 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Link to job:* *<https://github.com/mozilla/blurts-server/actions/runs/${{ github.run_id }}|Monitor E2E tests>*"
"text": "*Link to job:* *<https://github.com/mozilla/blurts-server/actions/runs/${{ github.run_id }}|Monitor e2e tests>*"
}
},
{
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/e2e_pr_full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
PLAYWRIGHT_VERSION=$(npx playwright --version | sed 's/Version //')
echo "Playwright Version: $PLAYWRIGHT_VERSION"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Cache Playwright Browsers for Playwright's Version
id: cache-playwright-browsers
uses: actions/cache@v4
Expand All @@ -56,24 +55,31 @@ jobs:

- name: Run Playwright tests
if: github.actor != 'dependabot[bot]'
run: npm run e2e
run: npm run e2e -- --update-snapshots
timeout-minutes: 40
env:
E2E_TEST_ENV: ${{ inputs.environment != null && inputs.environment || 'local' }}
E2E_TEST_BASE_URL: ${{ secrets.E2E_TEST_BASE_URL }}
E2E_TEST_ENV: local
E2E_TEST_BASE_URL: http://localhost:6060
E2E_TEST_ACCOUNT_EMAIL: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL }}
E2E_TEST_ACCOUNT_PASSWORD: ${{ secrets.E2E_TEST_ACCOUNT_PASSWORD }}
E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES }}
E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED }}
E2E_TEST_PAYPAL_LOGIN: ${{ secrets.E2E_TEST_PAYPAL_LOGIN }}
E2E_TEST_ACCOUNT_PASSWORD: ${{ secrets.E2E_TEST_ACCOUNT_PASSWORD }}
E2E_TEST_PAYPAL_LOGIN: ${{ secrets.E2E_TEST_PAYPAL_LOGIN }}
E2E_TEST_PAYPAL_PASSWORD: ${{ secrets.E2E_TEST_PAYPAL_PASSWORD }}
ADMINS: ${{ secrets.ADMINS }}
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET }}
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET_LOCAL }}
OAUTH_ACCOUNT_URI: ${{ secrets.OAUTH_ACCOUNT_URI }}
ONEREP_API_KEY: ${{ secrets.ONEREP_API_KEY }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
DATABASE_URL: postgres://postgres:postgres@localhost:5432/blurts
HIBP_KANON_API_TOKEN: ${{ secrets.HIBP_KANON_API_TOKEN }}
HIBP_API_TOKEN: ${{ secrets.HIBP_API_TOKEN }}
HIBP_KANON_API_ROOT: "http://localhost:6060/api/mock/hibp"
ONEREP_API_BASE: "http://localhost:6060/api/mock/onerep/"
PREMIUM_PRODUCT_ID: ${{ secrets.STAGE_PREMIUM_PRODUCT_ID }}
PREMIUM_PLAN_ID_MONTHLY_US: ${{ secrets.STAGE_PREMIUM_PLAN_ID_MONTHLY_US }}
PREMIUM_PLAN_ID_YEARLY_US: ${{ secrets.STAGE_PREMIUM_PLAN_ID_YEARLY_US }}
REDIS_URL: "redis://redis.mock"
- uses: actions/upload-artifact@v4
if: always()
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/e2e_pr_smoke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ jobs:
PLAYWRIGHT_VERSION=$(npx playwright --version | sed 's/Version //')
echo "Playwright Version: $PLAYWRIGHT_VERSION"
echo "PLAYWRIGHT_VERSION=$PLAYWRIGHT_VERSION" >> $GITHUB_ENV
- name: Cache Playwright Browsers for Playwright's Version
id: cache-playwright-browsers
uses: actions/cache@v4
Expand All @@ -65,7 +64,7 @@ jobs:
E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL_ZERO_BREACHES }}
E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED: ${{ secrets.E2E_TEST_ACCOUNT_EMAIL_EXPOSURES_STARTED }}
E2E_TEST_ACCOUNT_PASSWORD: ${{ secrets.E2E_TEST_ACCOUNT_PASSWORD }}
E2E_TEST_PAYPAL_LOGIN: ${{ secrets.E2E_TEST_PAYPAL_LOGIN }}
E2E_TEST_PAYPAL_LOGIN: ${{ secrets.E2E_TEST_PAYPAL_LOGIN }}
E2E_TEST_PAYPAL_PASSWORD: ${{ secrets.E2E_TEST_PAYPAL_PASSWORD }}
ADMINS: ${{ secrets.ADMINS }}
OAUTH_CLIENT_SECRET: ${{ secrets.OAUTH_CLIENT_SECRET_LOCAL }}
Expand All @@ -78,9 +77,6 @@ jobs:
HIBP_API_TOKEN: ${{ secrets.HIBP_API_TOKEN }}
HIBP_KANON_API_ROOT: "http://localhost:6060/api/mock/hibp"
ONEREP_API_BASE: "http://localhost:6060/api/mock/onerep/"
# MNTOR-3516: Our tests are currently set up to expect accounts to act like
# old user accounts, so let's pretend they all are:
BROKER_SCAN_RELEASE_DATE: "3000-12-31"
REDIS_URL: "redis://redis.mock"
- uses: actions/upload-artifact@v4
if: always()
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/preview_deploy_gcp.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: Deploy Preview

on:
on:
pull_request:
types: [closed]

env:
PROJECT_ID: ${{ secrets.GCP_PROJECT }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/reference_linter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: Lint Reference Files
on:
push:
pull_request:
types: [closed]
workflow_dispatch:
jobs:
l10n-lint:
runs-on: ubuntu-latest
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: Unit Tests

on:
pull_request:
types: [closed]
on: [push]

jobs:
unit-tests:
Expand Down
5 changes: 2 additions & 3 deletions playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default defineConfig({
forbidOnly: !!process.env.CI,

/* Limit the number of failures */
maxFailures: process.env.CI ? 1 : undefined,
maxFailures: 1,

/* Retry on CI only */
retries: process.env.CI ? 1 : 0,
Expand All @@ -68,8 +68,7 @@ export default defineConfig({
actionTimeout: 0,

/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.E2E_TEST_BASE_URL ?? 'https://stage.firefoxmonitor.nonprod.cloudops.mozgcp.net',
// baseURL: 'http://localhost:6060',
baseURL: process.env.E2E_TEST_BASE_URL,

/* automatically take screenshot only on failures */
screenshot: 'only-on-failure',
Expand Down
22 changes: 4 additions & 18 deletions src/app/functions/server/isPrePlusUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import "server-only";
import { Session } from "next-auth";
import { parseIso8601Datetime } from "../../../utils/parse";
import { isPrePlusDate } from "../universal/isPrePlusDate";

/**
* Determine whether the user's account predates Monitor Plus
Expand All @@ -20,22 +20,8 @@ export function isPrePlusUser(user: Session["user"]): boolean {
return false;
}

const brokerScanReleaseDateParts = (
process.env.BROKER_SCAN_RELEASE_DATE ?? ""
).split("-");
if (brokerScanReleaseDateParts[0] === "") {
brokerScanReleaseDateParts[0] = "2023";
}
const brokerScanReleaseDate = new Date(
Date.UTC(
Number.parseInt(brokerScanReleaseDateParts[0], 10),
Number.parseInt(brokerScanReleaseDateParts[1] ?? "12", 10) - 1,
Number.parseInt(brokerScanReleaseDateParts[2] ?? "05", 10),
),
);

return (
(parseIso8601Datetime(user.subscriber.created_at)?.getTime() ?? 0) <
brokerScanReleaseDate.getTime()
return isPrePlusDate(
process.env.BROKER_SCAN_RELEASE_DATE ?? "",
user.subscriber.created_at,
);
}
27 changes: 27 additions & 0 deletions src/app/functions/universal/isPrePlusDate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { parseIso8601Datetime } from "../../../utils/parse";

export function isPrePlusDate(
plusReleaseDateString: string,
dateStringToCompare: string,
) {
const brokerScanReleaseDateParts = plusReleaseDateString.split("-");
if (brokerScanReleaseDateParts[0] === "") {
brokerScanReleaseDateParts[0] = "2023";
}
const brokerScanReleaseDate = new Date(
Date.UTC(
Number.parseInt(brokerScanReleaseDateParts[0], 10),
Number.parseInt(brokerScanReleaseDateParts[1] ?? "12", 10) - 1,
Number.parseInt(brokerScanReleaseDateParts[2] ?? "05", 10),
),
);

return (
(parseIso8601Datetime(dateStringToCompare)?.getTime() ?? 0) <
brokerScanReleaseDate.getTime()
);
}
2 changes: 1 addition & 1 deletion src/e2e/pages/purchasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class PurchasePage {
(await this.planDetails.textContent()) as string,
);
expect(planDetails).toContain(
`${process.env.E2E_TEST_ENV === "prod" ? "yearly" : "every 2 months"}`,
`${process.env.E2E_TEST_ENV === "production" ? "yearly" : "every 2 months"}`,
);
}

Expand Down
15 changes: 14 additions & 1 deletion src/e2e/pages/welcomeScanPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export class WelcomePage {
readonly modalConfirmButton: Locator;
readonly modalEditButton: Locator;

readonly findExposuresTitle: Locator;

constructor(page: Page) {
this.page = page;

Expand Down Expand Up @@ -67,9 +69,11 @@ export class WelcomePage {
this.isThisCorrectModal = page.getByLabel("Is this correct?");
this.modalConfirmButton = page.getByRole("button", { name: "Confirm" });
this.modalEditButton = page.getByRole("button", { name: "Edit" });

this.findExposuresTitle = page.getByText("Scanning for exposures…");
}

async goThroughFirstScan() {
async goThroughFirstScan(options: { skipProgressIndicator: boolean }) {
// confirm get started step elements
expect(await this.getStartedStep.count()).toEqual(3);
await expect(this.page.getByText("Get started")).toBeVisible();
Expand All @@ -88,6 +92,15 @@ export class WelcomePage {
await this.findExposuresButton.click();

await this.modalConfirmButton.click();
await this.findExposuresTitle.waitFor();

// reloading page skips the loader and routes directly to the dashboard
if (options.skipProgressIndicator) {
// wait for scan to be finished before reloading the page
await this.page.waitForTimeout(10000);
await this.page.reload();
}

// Waiting for scan to complete
const dashboardPage = new DashboardPage(this.page);
await dashboardPage.actionNeededTab.waitFor();
Expand Down
17 changes: 13 additions & 4 deletions src/e2e/specs/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import { isPrePlusDate } from "../../app/functions/universal/isPrePlusDate.js";
import { test, expect } from "../fixtures/basePage.js";

test.describe(`${process.env.E2E_TEST_ENV} - Authentication flow verification @smoke`, () => {
Expand All @@ -14,7 +15,7 @@ test.describe(`${process.env.E2E_TEST_ENV} - Authentication flow verification @s
authPage,
landingPage,
}, testInfo) => {
// speed up test by ignore non necessary requests
// speed up test by ignoring non-necessary requests
await page.route(/(analytics)/, async (route) => {
await route.abort();
});
Expand All @@ -23,12 +24,20 @@ test.describe(`${process.env.E2E_TEST_ENV} - Authentication flow verification @s
await landingPage.goToSignIn();

// Fill out sign up form
const randomEmail = `${Date.now()}[email protected]`;
const currentTimestamp = Date.now();
const randomEmail = `${currentTimestamp}[email protected]`;
await authPage.signUp(randomEmail, page);

// assert successful login
const successUrl = `${process.env.E2E_TEST_BASE_URL}/user/welcome`;
expect(page.url()).toBe(successUrl);
const successUrlSlugs = isPrePlusDate(
process.env.BROKER_SCAN_RELEASE_DATE ?? "",
new Date(currentTimestamp).toUTCString(),
)
? "/user/dashboard"
: "/user/welcome";
expect(page.url()).toBe(
`${process.env.E2E_TEST_BASE_URL}${successUrlSlugs}`,
);

await testInfo.attach(
`${process.env.E2E_TEST_ENV}-signup-monitor-dashboard.png`,
Expand Down
Loading

0 comments on commit 4bf3d6b

Please sign in to comment.