Skip to content

Commit a374baf

Browse files
authored
test(browser): Update tests that need changes for getLocalTestUrl (#14324)
Extracted these out of #11904 - these are all the tests that required changing any (test) code for them to pass with `getLocalTestUrl` vs `getLocalTestPath`.
1 parent 72751da commit a374baf

File tree

21 files changed

+128
-91
lines changed

21 files changed

+128
-91
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
window.addEventListener('error', function (event) {
2-
Sentry.captureException(event);
3-
});
4-
5-
window.thisDoesNotExist();
1+
Sentry.captureException(new ErrorEvent('something', { message: 'test error' }));

dev-packages/browser-integration-tests/suites/public-api/captureException/errorEvent/test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import type { Event } from '@sentry/types';
44
import { sentryTest } from '../../../../utils/fixtures';
55
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
66

7-
sentryTest('should capture an ErrorEvent', async ({ getLocalTestPath, page }) => {
8-
const url = await getLocalTestPath({ testDir: __dirname });
7+
sentryTest('should capture an ErrorEvent', async ({ getLocalTestUrl, page }) => {
8+
const url = await getLocalTestUrl({ testDir: __dirname });
99

1010
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
1111

1212
expect(eventData.exception?.values).toHaveLength(1);
1313
expect(eventData.exception?.values?.[0]).toMatchObject({
1414
type: 'ErrorEvent',
15-
value: 'Event `ErrorEvent` captured as exception with message `Script error.`',
15+
value: 'Event `ErrorEvent` captured as exception with message `test error`',
1616
mechanism: {
1717
type: 'generic',
1818
handled: true,

dev-packages/browser-integration-tests/suites/public-api/instrumentation/xhr/onreadystatechange/subject.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
window.calls = {};
22
const xhr = new XMLHttpRequest();
3-
xhr.open('GET', 'test');
3+
xhr.open('GET', 'http://example.com');
44
xhr.onreadystatechange = function wat() {
55
window.calls[xhr.readyState] = window.calls[xhr.readyState] ? window.calls[xhr.readyState] + 1 : 1;
66
};

dev-packages/browser-integration-tests/suites/public-api/instrumentation/xhr/onreadystatechange/test.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@ import { sentryTest } from '../../../../../utils/fixtures';
44

55
sentryTest(
66
'should not call XMLHttpRequest onreadystatechange more than once per state',
7-
async ({ getLocalTestPath, page }) => {
8-
const url = await getLocalTestPath({ testDir: __dirname });
7+
async ({ getLocalTestUrl, page }) => {
8+
const url = await getLocalTestUrl({ testDir: __dirname });
9+
10+
await page.route('http://example.com/', route => {
11+
return route.fulfill({
12+
status: 200,
13+
contentType: 'application/json',
14+
body: JSON.stringify({}),
15+
});
16+
});
917

1018
await page.goto(url);
1119

12-
const calls = await page.evaluate(() => {
13-
// @ts-expect-error window.calls defined in subject.js
14-
return window.calls;
15-
});
20+
// Wait until XHR is done
21+
await page.waitForFunction('window.calls["4"]');
1622

17-
expect(calls).toEqual({ '4': 1 });
23+
const calls = await page.evaluate('window.calls');
24+
25+
expect(calls).toEqual({
26+
'2': 1,
27+
'3': 1,
28+
'4': 1,
29+
});
1830
},
1931
);

dev-packages/browser-integration-tests/suites/replay/captureReplay/test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { expect } from '@playwright/test';
22
import { SDK_VERSION } from '@sentry/browser';
33

4-
import { sentryTest } from '../../../utils/fixtures';
4+
import { TEST_HOST, sentryTest } from '../../../utils/fixtures';
55
import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';
66

7-
sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalTestPath, page }) => {
7+
sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalTestUrl, page }) => {
88
if (shouldSkipReplayTest()) {
99
sentryTest.skip();
1010
}
1111

1212
const reqPromise0 = waitForReplayRequest(page, 0);
1313
const reqPromise1 = waitForReplayRequest(page, 1);
1414

15-
const url = await getLocalTestPath({ testDir: __dirname });
15+
const url = await getLocalTestUrl({ testDir: __dirname });
1616

1717
await page.goto(url);
1818
const replayEvent0 = getReplayEvent(await reqPromise0);
@@ -26,7 +26,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
2626
timestamp: expect.any(Number),
2727
error_ids: [],
2828
trace_ids: [],
29-
urls: [expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/)],
29+
urls: [`${TEST_HOST}/index.html`],
3030
replay_id: expect.stringMatching(/\w{32}/),
3131
replay_start_timestamp: expect.any(Number),
3232
segment_id: 0,
@@ -49,7 +49,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
4949
name: 'sentry.javascript.browser',
5050
},
5151
request: {
52-
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
52+
url: `${TEST_HOST}/index.html`,
5353
headers: {
5454
'User-Agent': expect.stringContaining(''),
5555
},
@@ -86,7 +86,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
8686
name: 'sentry.javascript.browser',
8787
},
8888
request: {
89-
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
89+
url: `${TEST_HOST}/index.html`,
9090
headers: {
9191
'User-Agent': expect.stringContaining(''),
9292
},

dev-packages/browser-integration-tests/suites/replay/captureReplayFromReplayPackage/test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { expect } from '@playwright/test';
22
import { SDK_VERSION } from '@sentry/browser';
33

4-
import { sentryTest } from '../../../utils/fixtures';
4+
import { TEST_HOST, sentryTest } from '../../../utils/fixtures';
55
import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';
66

7-
sentryTest('should capture replays (@sentry-internal/replay export)', async ({ getLocalTestPath, page }) => {
7+
sentryTest('should capture replays (@sentry-internal/replay export)', async ({ getLocalTestUrl, page }) => {
88
if (shouldSkipReplayTest()) {
99
sentryTest.skip();
1010
}
1111

1212
const reqPromise0 = waitForReplayRequest(page, 0);
1313
const reqPromise1 = waitForReplayRequest(page, 1);
1414

15-
const url = await getLocalTestPath({ testDir: __dirname });
15+
const url = await getLocalTestUrl({ testDir: __dirname });
1616

1717
await page.goto(url);
1818
const replayEvent0 = getReplayEvent(await reqPromise0);
@@ -26,7 +26,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
2626
timestamp: expect.any(Number),
2727
error_ids: [],
2828
trace_ids: [],
29-
urls: [expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/)],
29+
urls: [`${TEST_HOST}/index.html`],
3030
replay_id: expect.stringMatching(/\w{32}/),
3131
replay_start_timestamp: expect.any(Number),
3232
segment_id: 0,
@@ -49,7 +49,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
4949
name: 'sentry.javascript.browser',
5050
},
5151
request: {
52-
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
52+
url: `${TEST_HOST}/index.html`,
5353
headers: {
5454
'User-Agent': expect.stringContaining(''),
5555
},
@@ -86,7 +86,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
8686
name: 'sentry.javascript.browser',
8787
},
8888
request: {
89-
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
89+
url: `${TEST_HOST}/index.html`,
9090
headers: {
9191
'User-Agent': expect.stringContaining(''),
9292
},

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts

+32-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from '@playwright/test';
22

3-
import { sentryTest } from '../../../utils/fixtures';
3+
import { TEST_HOST, sentryTest } from '../../../utils/fixtures';
44
import {
55
expectedCLSPerformanceSpan,
66
expectedClickBreadcrumb,
@@ -30,7 +30,7 @@ well as the correct DOM snapshots and updates are recorded and sent.
3030
*/
3131
sentryTest(
3232
'record page navigations and performance entries across multiple pages',
33-
async ({ getLocalTestPath, page, browserName }) => {
33+
async ({ getLocalTestUrl, page, browserName }) => {
3434
// We only test this against the NPM package and replay bundles
3535
// and only on chromium as most performance entries are only available in chromium
3636
if (shouldSkipReplayTest() || browserName !== 'chromium') {
@@ -48,7 +48,7 @@ sentryTest(
4848
const reqPromise8 = waitForReplayRequest(page, 8);
4949
const reqPromise9 = waitForReplayRequest(page, 9);
5050

51-
const url = await getLocalTestPath({ testDir: __dirname });
51+
const url = await getLocalTestUrl({ testDir: __dirname });
5252

5353
const [req0] = await Promise.all([reqPromise0, page.goto(url)]);
5454
const replayEvent0 = getReplayEvent(req0);
@@ -72,7 +72,7 @@ sentryTest(
7272
const collectedPerformanceSpans = [...recording0.performanceSpans, ...recording1.performanceSpans];
7373
const collectedBreadcrumbs = [...recording0.breadcrumbs, ...recording1.breadcrumbs];
7474

75-
expect(collectedPerformanceSpans.length).toEqual(8);
75+
expect(collectedPerformanceSpans.length).toBeGreaterThanOrEqual(6);
7676
expect(collectedPerformanceSpans).toEqual(
7777
expect.arrayContaining([
7878
expectedNavigationPerformanceSpan,
@@ -112,7 +112,7 @@ sentryTest(
112112
const collectedPerformanceSpansAfterReload = [...recording2.performanceSpans, ...recording3.performanceSpans];
113113
const collectedBreadcrumbsAdterReload = [...recording2.breadcrumbs, ...recording3.breadcrumbs];
114114

115-
expect(collectedPerformanceSpansAfterReload.length).toEqual(8);
115+
expect(collectedPerformanceSpansAfterReload.length).toBeGreaterThanOrEqual(6);
116116
expect(collectedPerformanceSpansAfterReload).toEqual(
117117
expect.arrayContaining([
118118
expectedReloadPerformanceSpan,
@@ -146,7 +146,8 @@ sentryTest(
146146
url: expect.stringContaining('page-0.html'),
147147
headers: {
148148
// @ts-expect-error this is fine
149-
'User-Agent': expect.stringContaining(''),
149+
'User-Agent': expect.any(String),
150+
Referer: `${TEST_HOST}/index.html`,
150151
},
151152
},
152153
}),
@@ -168,7 +169,8 @@ sentryTest(
168169
url: expect.stringContaining('page-0.html'),
169170
headers: {
170171
// @ts-expect-error this is fine
171-
'User-Agent': expect.stringContaining(''),
172+
'User-Agent': expect.any(String),
173+
Referer: `${TEST_HOST}/index.html`,
172174
},
173175
},
174176
}),
@@ -210,13 +212,12 @@ sentryTest(
210212
getExpectedReplayEvent({
211213
segment_id: 6,
212214
urls: ['/spa'],
213-
214215
request: {
215-
// @ts-expect-error this is fine
216-
url: expect.stringContaining('page-0.html'),
216+
url: `${TEST_HOST}/spa`,
217217
headers: {
218218
// @ts-expect-error this is fine
219-
'User-Agent': expect.stringContaining(''),
219+
'User-Agent': expect.any(String),
220+
Referer: `${TEST_HOST}/index.html`,
220221
},
221222
},
222223
}),
@@ -235,11 +236,11 @@ sentryTest(
235236
urls: [],
236237

237238
request: {
238-
// @ts-expect-error this is fine
239-
url: expect.stringContaining('page-0.html'),
239+
url: `${TEST_HOST}/spa`,
240240
headers: {
241241
// @ts-expect-error this is fine
242-
'User-Agent': expect.stringContaining(''),
242+
'User-Agent': expect.any(String),
243+
Referer: `${TEST_HOST}/index.html`,
243244
},
244245
},
245246
}),
@@ -279,6 +280,14 @@ sentryTest(
279280
expect(replayEvent8).toEqual(
280281
getExpectedReplayEvent({
281282
segment_id: 8,
283+
request: {
284+
url: `${TEST_HOST}/index.html`,
285+
headers: {
286+
// @ts-expect-error this is fine
287+
'User-Agent': expect.any(String),
288+
Referer: `${TEST_HOST}/spa`,
289+
},
290+
},
282291
}),
283292
);
284293
expect(normalize(recording8.fullSnapshots)).toMatchSnapshot('seg-8-snap-full');
@@ -293,6 +302,14 @@ sentryTest(
293302
getExpectedReplayEvent({
294303
segment_id: 9,
295304
urls: [],
305+
request: {
306+
url: `${TEST_HOST}/index.html`,
307+
headers: {
308+
// @ts-expect-error this is fine
309+
'User-Agent': expect.any(String),
310+
Referer: `${TEST_HOST}/spa`,
311+
},
312+
},
296313
}),
297314
);
298315
expect(recording9.fullSnapshots.length).toEqual(0);
@@ -304,7 +321,7 @@ sentryTest(
304321
];
305322
const collectedBreadcrumbsAfterIndexNavigation = [...recording8.breadcrumbs, ...recording9.breadcrumbs];
306323

307-
expect(collectedPerformanceSpansAfterIndexNavigation.length).toEqual(8);
324+
expect(collectedPerformanceSpansAfterIndexNavigation.length).toBeGreaterThanOrEqual(6);
308325
expect(collectedPerformanceSpansAfterIndexNavigation).toEqual(
309326
expect.arrayContaining([
310327
expectedNavigationPerformanceSpan,

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-0-snap-full

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"type": 2,
7474
"tagName": "a",
7575
"attributes": {
76-
"href": "/page-0.html"
76+
"href": "http://sentry-test.io/page-0.html"
7777
},
7878
"childNodes": [
7979
{
@@ -110,4 +110,4 @@
110110
},
111111
"timestamp": [timestamp]
112112
}
113-
]
113+
]

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-0-snap-full-chromium

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"type": 2,
7474
"tagName": "a",
7575
"attributes": {
76-
"href": "/page-0.html"
76+
"href": "http://sentry-test.io/page-0.html"
7777
},
7878
"childNodes": [
7979
{

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-2-snap-full

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"type": 2,
7474
"tagName": "a",
7575
"attributes": {
76-
"href": "/page-0.html"
76+
"href": "http://sentry-test.io/page-0.html"
7777
},
7878
"childNodes": [
7979
{
@@ -110,4 +110,4 @@
110110
},
111111
"timestamp": [timestamp]
112112
}
113-
]
113+
]

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-2-snap-full-chromium

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"type": 2,
7474
"tagName": "a",
7575
"attributes": {
76-
"href": "/page-0.html"
76+
"href": "http://sentry-test.io/page-0.html"
7777
},
7878
"childNodes": [
7979
{

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-4-snap-full

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"type": 2,
117117
"tagName": "a",
118118
"attributes": {
119-
"href": "/index.html"
119+
"href": "http://sentry-test.io/index.html"
120120
},
121121
"childNodes": [
122122
{
@@ -153,4 +153,4 @@
153153
},
154154
"timestamp": [timestamp]
155155
}
156-
]
156+
]

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-4-snap-full-chromium

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
"type": 2,
117117
"tagName": "a",
118118
"attributes": {
119-
"href": "/index.html"
119+
"href": "http://sentry-test.io/index.html"
120120
},
121121
"childNodes": [
122122
{

dev-packages/browser-integration-tests/suites/replay/multiple-pages/test.ts-snapshots/seg-8-snap-full

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"type": 2,
7474
"tagName": "a",
7575
"attributes": {
76-
"href": "/page-0.html"
76+
"href": "http://sentry-test.io/page-0.html"
7777
},
7878
"childNodes": [
7979
{
@@ -110,4 +110,4 @@
110110
},
111111
"timestamp": [timestamp]
112112
}
113-
]
113+
]

0 commit comments

Comments
 (0)