From 0031cd34260d006fd4473ae5fb29df76a26de73a Mon Sep 17 00:00:00 2001 From: pajotg <33227855+pajotg@users.noreply.github.com> Date: Thu, 6 Jun 2024 20:46:36 +0200 Subject: [PATCH] Playwright tests should not send sentry events (#75) * fix: ensure that sentry events are never sent during testing * fix: do not commit temp vite.config --- .gitignore | 2 ++ tests/user_feedback.spec.ts | 10 +--------- tests/utils.ts | 11 ++++++++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 42dd83f..784299c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,5 @@ dist-ssr /playwright-report/ /blob-report/ /playwright/.cache/ + +vite.config.ts.timestamp*.mjs \ No newline at end of file diff --git a/tests/user_feedback.spec.ts b/tests/user_feedback.spec.ts index 16059b9..83f091c 100644 --- a/tests/user_feedback.spec.ts +++ b/tests/user_feedback.spec.ts @@ -1,5 +1,5 @@ import { expect, test } from "@playwright/test"; -import { goToHomePage, openExample } from "./utils"; +import { goToHomePage } from "./utils"; test.beforeEach(goToHomePage); @@ -12,14 +12,6 @@ test("User Feedback", async ({ page }) => { await page.getByPlaceholder("Email").fill("test@ing"); await page.locator("textarea").fill("test123"); - // Make sure no requests are actually done - await page.route("**/api/2/envelope/*", (route) => { - route.fulfill({ - status: 200, - body: "", - }); - }); - // Wait for the user_report feedback const feedbackPromise = page.waitForRequest((request) => { if (!/.*\/api\/2\/envelope\/.*/.test(request.url())) { diff --git a/tests/utils.ts b/tests/utils.ts index 1dcece5..b48ad1d 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -1,6 +1,15 @@ import { promises as fs } from "node:fs"; import setupPlaywrightArduino from "@leaphy-robotics/playwright-arduino"; -import type { Page, PlaywrightTestArgs } from "@playwright/test"; +import { type Page, type PlaywrightTestArgs, test } from "@playwright/test"; + +// Prevent sentry events from actually being sent +test.beforeEach(async ({ context }) => { + await context.route("**/api/2/envelope/*", (route) => { + route.fulfill({ + status: 200, + }); + }); +}); export async function setupArduino({ page }: PlaywrightTestArgs) { await setupPlaywrightArduino(page);