Skip to content

Commit 52a4fa1

Browse files
author
cod1k
committed
Update Playwright config to use dynamic app port variable
Replaced hardcoded port value with a dynamic variable for better maintainability and consistency. This change ensures the port is defined in a single location, reducing the risk of errors during updates.
1 parent 5929c8c commit 52a4fa1

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

dev-packages/e2e-tests/test-applications/cloudflare-workers/playwright.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ if (!testEnv) {
55
throw new Error('No test env defined');
66
}
77

8+
const APP_PORT = 38787;
9+
810
const config = getPlaywrightConfig(
911
{
10-
startCommand: 'pnpm dev',
11-
port: 8787,
12+
startCommand: `pnpm dev --port ${APP_PORT}`,
13+
port: APP_PORT,
1214
},
1315
{
1416
// This comes with the risk of tests leaking into each other but the tests run quite slow so we should parallelize

dev-packages/e2e-tests/test-applications/cloudflare-workers/tests/index.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
import { expect, test } from '@playwright/test';
22
import { waitForError } from '@sentry-internal/test-utils';
33

4-
test('Index page', async ({ page }) => {
5-
const result = await page.goto('http://localhost:8787/');
6-
expect(result?.status?.()).toBe(200);
7-
await expect(page.textContent('body > pre')).resolves.toBe('Hello World!');
4+
test('Index page', async ({ baseURL }) => {
5+
const result = await fetch(baseURL!);
6+
expect(result.status).toBe(200);
7+
await expect(result.text()).resolves.toBe('Hello World!');
88
})
99

10-
test('worker\'s withSentry', async () => {
10+
test('worker\'s withSentry', async ({baseURL}) => {
1111
const eventWaiter = waitForError('cloudflare-workers', (event) => {
1212
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare';
1313
});
14-
const response = await fetch('http://localhost:8787/throwException');
14+
const response = await fetch(`${baseURL}/throwException`);
1515
expect(response.status).toBe(500);
1616
const event = await eventWaiter;
1717
expect(event.exception?.values?.[0]?.value).toBe('To be recorded in Sentry.');
1818
})
1919

20-
test('RPC method which throws an exception to be logged to sentry', async () => {
20+
test('RPC method which throws an exception to be logged to sentry', async ({baseURL}) => {
2121
const eventWaiter = waitForError('cloudflare-workers', (event) => {
2222
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
2323
});
24-
const response = await fetch('http://localhost:8787/rpc/throwException');
24+
const response = await fetch(`${baseURL}/rpc/throwException`);
2525
expect(response.status).toBe(500);
2626
const event = await eventWaiter;
2727
expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry.');
2828
});
29-
test('Request processed by DurableObject\'s fetch is recorded', async () => {
29+
test('Request processed by DurableObject\'s fetch is recorded', async ({baseURL}) => {
3030
const eventWaiter = waitForError('cloudflare-workers', (event) => {
3131
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
3232
});
33-
const response = await fetch('http://localhost:8787/pass-to-object/throwException');
33+
const response = await fetch(`${baseURL}/pass-to-object/throwException`);
3434
expect(response.status).toBe(500);
3535
const event = await eventWaiter;
3636
expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry.');

0 commit comments

Comments
 (0)