Skip to content

Commit 73ea2d6

Browse files
committed
feat(e2e): Migrate react-router-7-lazy-routes to use Spotlight correctly
Instead of using Playwright's webServer to spawn Spotlight (which runs in a separate process and can't share the event buffer), tests now call startSpotlight() directly in beforeAll hooks. This way: - Test process spawns Spotlight via `spotlight run -f json` - Spotlight auto-runs the app and streams events to stdout - Test process parses stdout and populates the event buffer - waitForSpotlightTransaction() works because it's in the same process Changes: - playwright.config.mjs: Empty webServer (Spotlight handles app startup) - src/index.tsx: Use Spotlight DSN workaround instead of tunnel - tests/*.ts: Add beforeAll/afterAll for Spotlight lifecycle - Deleted start-event-proxy.mjs (no longer needed)
1 parent 03eb6e5 commit 73ea2d6

File tree

5 files changed

+102
-58
lines changed

5 files changed

+102
-58
lines changed
Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
22

3-
const config = getPlaywrightConfig({
4-
startCommand: `pnpm start`,
5-
});
3+
// No webServer needed - Spotlight spawns the app via `spotlight run`
4+
// Tests call startSpotlight() directly in beforeAll hooks
5+
const config = getPlaywrightConfig(
6+
{},
7+
{
8+
// Override webServer to empty - Spotlight handles app startup
9+
webServer: [],
10+
},
11+
);
612

713
export default config;

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ function getRuntimeConfig(): { lazyRouteTimeout?: number; idleTimeout?: number }
5555

5656
const runtimeConfig = getRuntimeConfig();
5757

58+
// Use Spotlight DSN workaround - sends events directly to Spotlight sidecar
59+
// Port 8969 is Spotlight's default port
5860
Sentry.init({
5961
environment: 'qa', // dynamic sampling bias to keep transactions
60-
dsn: process.env.REACT_APP_E2E_TEST_DSN,
62+
dsn: 'http://spotlight@localhost:8969/0',
6163
integrations: [
6264
Sentry.reactRouterV7BrowserTracingIntegration({
6365
useEffect: React.useEffect,
@@ -75,8 +77,6 @@ Sentry.init({
7577
// for finer control
7678
tracesSampleRate: 1.0,
7779
release: 'e2e-test',
78-
79-
tunnel: 'http://localhost:3031',
8080
});
8181

8282
const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouterV7(createBrowserRouter);

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/start-event-proxy.mjs

Lines changed: 0 additions & 6 deletions
This file was deleted.

dev-packages/e2e-tests/test-applications/react-router-7-lazy-routes/tests/timeout-behaviour.test.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
import { expect, test } from '@playwright/test';
2-
import { waitForTransaction } from '@sentry-internal/test-utils';
2+
import {
3+
startSpotlight,
4+
waitForSpotlightTransaction,
5+
clearSpotlightEventBuffer,
6+
} from '@sentry-internal/test-utils';
7+
import * as path from 'path';
8+
9+
let spotlight: Awaited<ReturnType<typeof startSpotlight>>;
10+
11+
test.beforeAll(async () => {
12+
spotlight = await startSpotlight({
13+
cwd: path.resolve(__dirname, '..'),
14+
debug: !!process.env.DEBUG,
15+
});
16+
});
17+
18+
test.afterAll(() => {
19+
spotlight?.stop();
20+
});
21+
22+
test.beforeEach(() => {
23+
clearSpotlightEventBuffer();
24+
});
325

426
test('lazyRouteTimeout: Routes load within timeout window', async ({ page }) => {
5-
const transactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
27+
const transactionPromise = waitForSpotlightTransaction(async transactionEvent => {
628
return (
729
!!transactionEvent?.transaction &&
830
transactionEvent.contexts?.trace?.op === 'navigation' &&
@@ -27,7 +49,7 @@ test('lazyRouteTimeout: Routes load within timeout window', async ({ page }) =>
2749
});
2850

2951
test('lazyRouteTimeout: Infinity timeout always waits for routes', async ({ page }) => {
30-
const transactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
52+
const transactionPromise = waitForSpotlightTransaction(async transactionEvent => {
3153
return (
3254
!!transactionEvent?.transaction &&
3355
transactionEvent.contexts?.trace?.op === 'navigation' &&
@@ -51,7 +73,7 @@ test('lazyRouteTimeout: Infinity timeout always waits for routes', async ({ page
5173
});
5274

5375
test('idleTimeout: Captures all activity with increased timeout', async ({ page }) => {
54-
const transactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
76+
const transactionPromise = waitForSpotlightTransaction(async transactionEvent => {
5577
return (
5678
!!transactionEvent?.transaction &&
5779
transactionEvent.contexts?.trace?.op === 'navigation' &&
@@ -79,7 +101,7 @@ test('idleTimeout: Captures all activity with increased timeout', async ({ page
79101
});
80102

81103
test('idleTimeout: Finishes prematurely with low timeout', async ({ page }) => {
82-
const transactionPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
104+
const transactionPromise = waitForSpotlightTransaction(async transactionEvent => {
83105
return (
84106
!!transactionEvent?.transaction &&
85107
transactionEvent.contexts?.trace?.op === 'navigation' &&
@@ -107,7 +129,7 @@ test('idleTimeout: Finishes prematurely with low timeout', async ({ page }) => {
107129
});
108130

109131
test('idleTimeout: Pageload on deeply nested route', async ({ page }) => {
110-
const pageloadPromise = waitForTransaction('react-router-7-lazy-routes', async transactionEvent => {
132+
const pageloadPromise = waitForSpotlightTransaction(async transactionEvent => {
111133
return (
112134
!!transactionEvent?.transaction &&
113135
transactionEvent.contexts?.trace?.op === 'pageload' &&

0 commit comments

Comments
 (0)