Skip to content

Commit

Permalink
test(browser): Avoid using example.com for browser-integration-tests
Browse files Browse the repository at this point in the history
Mostly we already add a route for this anyhow, but it can be confusing. So let's just use a proper non-existing URL there to ensure we notice issues earlier.
  • Loading branch information
mydea committed Feb 6, 2025
1 parent f2a777a commit 6eed0b5
Show file tree
Hide file tree
Showing 72 changed files with 160 additions and 158 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.calls = {};
const xhr = new XMLHttpRequest();
xhr.open('GET', 'http://example.com');
xhr.open('GET', 'http://sentry-test-site.io');
xhr.onreadystatechange = function wat() {
window.calls[xhr.readyState] = window.calls[xhr.readyState] ? window.calls[xhr.readyState] + 1 : 1;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sentryTest(
async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

await page.route('http://example.com/', route => {
await page.route('http://sentry-test-site.io/', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ document.getElementById('go-background').addEventListener('click', () => {
});

document.getElementById('fetch').addEventListener('click', () => {
fetch('https://example.com', { method: 'POST', body: 'foo' });
fetch('https://sentry-test-site.io', { method: 'POST', body: 'foo' });
});

document.getElementById('xhr').addEventListener('click', () => {
const xhr = new XMLHttpRequest();
xhr.open('GET', 'https://example.com');
xhr.open('GET', 'https://sentry-test-site.io');
xhr.send();
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sentryTest('replay recording should contain fetch request span', async ({ getLoc
sentryTest.skip();
}

await page.route('https://example.com', route => {
await page.route('https://sentry-test-site.io', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
Expand All @@ -27,7 +27,7 @@ sentryTest('replay recording should contain fetch request span', async ({ getLoc

const { performanceSpans: spans0 } = getReplayRecordingContent(req0);

await Promise.all([page.waitForResponse('https://example.com'), page.locator('#fetch').click()]);
await Promise.all([page.waitForResponse('https://sentry-test-site.io'), page.locator('#fetch').click()]);

const { performanceSpans: spans1 } = getReplayRecordingContent(await reqPromise1);

Expand All @@ -40,7 +40,7 @@ sentryTest('replay recording should contain XHR request span', async ({ getLocal
sentryTest.skip();
}

await page.route('https://example.com', route => {
await page.route('https://sentry-test-site.io', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
Expand All @@ -57,7 +57,7 @@ sentryTest('replay recording should contain XHR request span', async ({ getLocal

const { performanceSpans: spans0 } = getReplayRecordingContent(req0);

await Promise.all([page.waitForResponse('https://example.com'), page.locator('#xhr').click()]);
await Promise.all([page.waitForResponse('https://sentry-test-site.io'), page.locator('#xhr').click()]);

const { performanceSpans: spans1 } = getReplayRecordingContent(await reqPromise1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ <h1 id="h2">Bottom</h1>
document.getElementById('out').innerHTML += 'mutationButton clicked<br>';
});
document.getElementById('windowOpenButton').addEventListener('click', () => {
window.open('https://example.com/', '_blank');
window.open('https://github.com/', '_blank');
});

// Do nothing on these elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ sentryTest('window.open() is considered for slow click', async ({ getLocalTestUr
sentryTest.skip();
}

await page.route('http://example.com/', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({}),
});
});

const url = await getLocalTestUrl({ testDir: __dirname });

Expand Down Expand Up @@ -63,5 +56,5 @@ sentryTest('window.open() is considered for slow click', async ({ getLocalTestUr
const pages = context.pages();

expect(pages.length).toBe(2);
expect(pages[1].url()).toBe('https://example.com/');
expect(pages[1].url()).toBe('https://github.com/');
});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2')));
fetch('http://sentry-test-site.io/0').then(fetch('http://sentry-test-site.io/1').then(fetch('http://sentry-test-site.io/2')));
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sentryTest('should create fetch spans with http timing @firefox', async ({ brows
if (shouldSkipTracingTest() || !supportedBrowsers.includes(browserName)) {
sentryTest.skip();
}
await page.route('http://example.com/*', async route => {
await page.route('http://sentry-test-site.io/*', async route => {
const request = route.request();
const postData = await request.postDataJSON();

Expand All @@ -33,7 +33,7 @@ sentryTest('should create fetch spans with http timing @firefox', async ({ brows
await page.pause();
requestSpans?.forEach((span, index) =>
expect(span).toMatchObject({
description: `GET http://example.com/${index}`,
description: `GET http://sentry-test-site.io/${index}`,
parent_span_id: tracingEvent.contexts?.trace?.span_id,
span_id: expect.stringMatching(/[a-f0-9]{16}/),
start_timestamp: expect.any(Number),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</head>
<body>
<div>Rendered Before Long Animation Frame</div>
<script src="https://example.com/path/to/script.js"></script>
<script src="https://sentry-test-site.io/path/to/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<button id="clickme">
click me to start the long animation!
</button>
<script src="https://example.com/path/to/script.js"></script>
<script src="https://sentry-test-site.io/path/to/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ sentryTest(
expect(uiSpans?.length).toBeGreaterThanOrEqual(1);

const topLevelUISpan = (uiSpans || []).find(
span => span.data?.['browser.script.invoker'] === 'https://example.com/path/to/script.js',
span => span.data?.['browser.script.invoker'] === 'https://sentry-test-site.io/path/to/script.js',
)!;
expect(topLevelUISpan).toEqual(
expect.objectContaining({
op: 'ui.long-animation-frame',
description: 'Main UI thread blocked',
parent_span_id: eventData.contexts?.trace?.span_id,
data: {
'code.filepath': 'https://example.com/path/to/script.js',
'code.filepath': 'https://sentry-test-site.io/path/to/script.js',
'browser.script.source_char_position': 0,
'browser.script.invoker': 'https://example.com/path/to/script.js',
'browser.script.invoker': 'https://sentry-test-site.io/path/to/script.js',
'browser.script.invoker_type': 'classic-script',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.long-animation-frame',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
Expand Down Expand Up @@ -98,7 +98,7 @@ sentryTest(
data: {
'browser.script.invoker': 'BUTTON#clickme.onclick',
'browser.script.invoker_type': 'event-listener',
'code.filepath': 'https://example.com/path/to/script.js',
'code.filepath': 'https://sentry-test-site.io/path/to/script.js',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.long-animation-frame',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</head>
<body>
<div>Rendered Before Long Task</div>
<script src="https://example.com/path/to/script.js"></script>
<script src="https://sentry-test-site.io/path/to/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<button id="clickme">
click me to start the long animation!
</button>
<script src="https://example.com/path/to/script.js"></script>
<script src="https://sentry-test-site.io/path/to/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ sentryTest(
expect(uiSpans?.length).toBeGreaterThanOrEqual(1);

const topLevelUISpan = (uiSpans || []).find(
span => span.data?.['browser.script.invoker'] === 'https://example.com/path/to/script.js',
span => span.data?.['browser.script.invoker'] === 'https://sentry-test-site.io/path/to/script.js',
)!;
expect(topLevelUISpan).toEqual(
expect.objectContaining({
op: 'ui.long-animation-frame',
description: 'Main UI thread blocked',
parent_span_id: eventData.contexts?.trace?.span_id,
data: {
'code.filepath': 'https://example.com/path/to/script.js',
'code.filepath': 'https://sentry-test-site.io/path/to/script.js',
'browser.script.source_char_position': 0,
'browser.script.invoker': 'https://example.com/path/to/script.js',
'browser.script.invoker': 'https://sentry-test-site.io/path/to/script.js',
'browser.script.invoker_type': 'classic-script',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.long-animation-frame',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
Expand Down Expand Up @@ -100,7 +100,7 @@ sentryTest(
data: {
'browser.script.invoker': 'BUTTON#clickme.onclick',
'browser.script.invoker_type': 'event-listener',
'code.filepath': 'https://example.com/path/to/script.js',
'code.filepath': 'https://sentry-test-site.io/path/to/script.js',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.long-animation-frame',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.browser.metrics',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</head>
<body>
<div>Rendered Before Long Task</div>
<script src="https://example.com/path/to/script.js"></script>

<button id="myButton">Start long task</button>
<h1 id="myHeading">Heading</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ sentryTest(
}
const url = await getLocalTestUrl({ testDir: __dirname });

await page.route('**/path/to/script.js', route => route.fulfill({ path: `${__dirname}/assets/script.js` }));

await page.goto(url);

const navigationTransactionEventPromise = getFirstSentryEnvelopeRequest<Event>(page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</head>
<body>
<div>Rendered Before Long Task</div>
<script src="https://example.com/path/to/script.js"></script>
<script src="https://sentry-test-site.io/path/to/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</head>
<body>
<div>Rendered Before Long Task</div>
<script src="https://example.com/path/to/script.js"></script>
<script src="https://sentry-test-site.io/path/to/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</head>
<body>
<div>Rendered Before Long Task</div>
<script src="https://example.com/path/to/script.js"></script>
<script src="https://sentry-test-site.io/path/to/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ window.Sentry = Sentry;
Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [Sentry.browserTracingIntegration()],
tracePropagationTargets: ['http://example.com'],
tracePropagationTargets: ['http://sentry-test-site.io'],
tracesSampleRate: 1,
});
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2')));
fetch('http://sentry-test-site.io/0').then(fetch('http://sentry-test-site.io/1').then(fetch('http://sentry-test-site.io/2')));
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sentryTest(
const requests = (
await Promise.all([
page.goto(url),
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://sentry-test-site.io/${idx}`))),
])
)[1];

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2')));
fetch('http://sentry-test-site.io/0').then(fetch('http://sentry-test-site.io/1').then(fetch('http://sentry-test-site.io/2')));
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ sentryTest(
const requests = (
await Promise.all([
page.goto(url),
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://sentry-test-site.io/${idx}`))),
])
)[1];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [Sentry.browserTracingIntegration({ instrumentNavigation: false, instrumentPageLoad: false })],
tracesSampleRate: 1,
tracePropagationTargets: ['example.com'],
tracePropagationTargets: ['sentry-test-site.io'],
release: '1.1.1',
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ btnUpdateName.addEventListener('click', () => {
});

btnMakeRequest.addEventListener('click', () => {
fetch('https://example.com/api');
fetch('https://sentry-test-site.io/api');
});

btnCaptureError.addEventListener('click', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn

const url = await getLocalTestUrl({ testDir: __dirname });

await page.route('http://sentry-test-site.io/**/*', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({}),
});
});

await page.goto(url);

/*
Expand Down Expand Up @@ -168,7 +176,7 @@ sentryTest('updates the DSC when the txn name is updated and high-quality', asyn
});

async function makeRequestAndGetBaggageItems(page: Page): Promise<string[]> {
const requestPromise = page.waitForRequest('https://example.com/*');
const requestPromise = page.waitForRequest('https://sentry-test-site.io/*');
await page.locator('#btnMakeRequest').click();
const request = await requestPromise;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</head>
<body>
<div id="content"></div>
<img src="https://example.com/path/to/image.png" />
<img src="https://sentry-test-site.io/path/to/image.png" />
<button type="button">Test button</button>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<meta charset="utf-8" />
</head>
<body>
<img src="https://example.com/path/to/image.svg" />
<script src="https://example.com/path/to/script.js"></script>
<link href="https://example.com/path/to/style.css" type="text/css" rel="stylesheet" />
<img src="https://sentry-test-site.io/path/to/image.svg" />
<script src="https://sentry-test-site.io/path/to/script.js"></script>
<link href="https://sentry-test-site.io/path/to/style.css" type="text/css" rel="stylesheet" />
<span>Rendered</span>
</body>
</html>
Loading

0 comments on commit 6eed0b5

Please sign in to comment.