Skip to content

test(browser): Update tests that need changes for getLocalTestUrl #14324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
window.addEventListener('error', function (event) {
Sentry.captureException(event);
});

window.thisDoesNotExist();
Sentry.captureException(new ErrorEvent('something', { message: 'test error' }));
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { Event } from '@sentry/types';
import { sentryTest } from '../../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';

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

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

expect(eventData.exception?.values).toHaveLength(1);
expect(eventData.exception?.values?.[0]).toMatchObject({
type: 'ErrorEvent',
value: 'Event `ErrorEvent` captured as exception with message `Script error.`',
value: 'Event `ErrorEvent` captured as exception with message `test error`',
mechanism: {
type: 'generic',
handled: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
window.calls = {};
const xhr = new XMLHttpRequest();
xhr.open('GET', 'test');
xhr.open('GET', 'http://example.com');
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 @@ -4,16 +4,28 @@ import { sentryTest } from '../../../../../utils/fixtures';

sentryTest(
'should not call XMLHttpRequest onreadystatechange more than once per state',
async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });
async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

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

await page.goto(url);

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

expect(calls).toEqual({ '4': 1 });
const calls = await page.evaluate('window.calls');

expect(calls).toEqual({
'2': 1,
'3': 1,
'4': 1,
});
},
);
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { expect } from '@playwright/test';
import { SDK_VERSION } from '@sentry/browser';

import { sentryTest } from '../../../utils/fixtures';
import { TEST_HOST, sentryTest } from '../../../utils/fixtures';
import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';

sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalTestPath, page }) => {
sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalTestUrl, page }) => {
if (shouldSkipReplayTest()) {
sentryTest.skip();
}

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

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

await page.goto(url);
const replayEvent0 = getReplayEvent(await reqPromise0);
Expand All @@ -26,7 +26,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
timestamp: expect.any(Number),
error_ids: [],
trace_ids: [],
urls: [expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/)],
urls: [`${TEST_HOST}/index.html`],
replay_id: expect.stringMatching(/\w{32}/),
replay_start_timestamp: expect.any(Number),
segment_id: 0,
Expand All @@ -49,7 +49,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
name: 'sentry.javascript.browser',
},
request: {
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
url: `${TEST_HOST}/index.html`,
headers: {
'User-Agent': expect.stringContaining(''),
},
Expand Down Expand Up @@ -86,7 +86,7 @@ sentryTest('should capture replays (@sentry/browser export)', async ({ getLocalT
name: 'sentry.javascript.browser',
},
request: {
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
url: `${TEST_HOST}/index.html`,
headers: {
'User-Agent': expect.stringContaining(''),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { expect } from '@playwright/test';
import { SDK_VERSION } from '@sentry/browser';

import { sentryTest } from '../../../utils/fixtures';
import { TEST_HOST, sentryTest } from '../../../utils/fixtures';
import { getReplayEvent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers';

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

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

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

await page.goto(url);
const replayEvent0 = getReplayEvent(await reqPromise0);
Expand All @@ -26,7 +26,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
timestamp: expect.any(Number),
error_ids: [],
trace_ids: [],
urls: [expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/)],
urls: [`${TEST_HOST}/index.html`],
replay_id: expect.stringMatching(/\w{32}/),
replay_start_timestamp: expect.any(Number),
segment_id: 0,
Expand All @@ -49,7 +49,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
name: 'sentry.javascript.browser',
},
request: {
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
url: `${TEST_HOST}/index.html`,
headers: {
'User-Agent': expect.stringContaining(''),
},
Expand Down Expand Up @@ -86,7 +86,7 @@ sentryTest('should capture replays (@sentry-internal/replay export)', async ({ g
name: 'sentry.javascript.browser',
},
request: {
url: expect.stringMatching(/\/dist\/([\w-]+)\/index\.html$/),
url: `${TEST_HOST}/index.html`,
headers: {
'User-Agent': expect.stringContaining(''),
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from '@playwright/test';

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

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

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

expect(collectedPerformanceSpans.length).toEqual(8);
expect(collectedPerformanceSpans.length).toBeGreaterThanOrEqual(6);
expect(collectedPerformanceSpans).toEqual(
expect.arrayContaining([
expectedNavigationPerformanceSpan,
Expand Down Expand Up @@ -112,7 +112,7 @@ sentryTest(
const collectedPerformanceSpansAfterReload = [...recording2.performanceSpans, ...recording3.performanceSpans];
const collectedBreadcrumbsAdterReload = [...recording2.breadcrumbs, ...recording3.breadcrumbs];

expect(collectedPerformanceSpansAfterReload.length).toEqual(8);
expect(collectedPerformanceSpansAfterReload.length).toBeGreaterThanOrEqual(6);
expect(collectedPerformanceSpansAfterReload).toEqual(
expect.arrayContaining([
expectedReloadPerformanceSpan,
Expand Down Expand Up @@ -146,7 +146,8 @@ sentryTest(
url: expect.stringContaining('page-0.html'),
headers: {
// @ts-expect-error this is fine
'User-Agent': expect.stringContaining(''),
'User-Agent': expect.any(String),
Referer: `${TEST_HOST}/index.html`,
},
},
}),
Expand All @@ -168,7 +169,8 @@ sentryTest(
url: expect.stringContaining('page-0.html'),
headers: {
// @ts-expect-error this is fine
'User-Agent': expect.stringContaining(''),
'User-Agent': expect.any(String),
Referer: `${TEST_HOST}/index.html`,
},
},
}),
Expand Down Expand Up @@ -210,13 +212,12 @@ sentryTest(
getExpectedReplayEvent({
segment_id: 6,
urls: ['/spa'],

request: {
// @ts-expect-error this is fine
url: expect.stringContaining('page-0.html'),
url: `${TEST_HOST}/spa`,
headers: {
// @ts-expect-error this is fine
'User-Agent': expect.stringContaining(''),
'User-Agent': expect.any(String),
Referer: `${TEST_HOST}/index.html`,
},
},
}),
Expand All @@ -235,11 +236,11 @@ sentryTest(
urls: [],

request: {
// @ts-expect-error this is fine
url: expect.stringContaining('page-0.html'),
url: `${TEST_HOST}/spa`,
headers: {
// @ts-expect-error this is fine
'User-Agent': expect.stringContaining(''),
'User-Agent': expect.any(String),
Referer: `${TEST_HOST}/index.html`,
},
},
}),
Expand Down Expand Up @@ -279,6 +280,14 @@ sentryTest(
expect(replayEvent8).toEqual(
getExpectedReplayEvent({
segment_id: 8,
request: {
url: `${TEST_HOST}/index.html`,
headers: {
// @ts-expect-error this is fine
'User-Agent': expect.any(String),
Referer: `${TEST_HOST}/spa`,
},
},
}),
);
expect(normalize(recording8.fullSnapshots)).toMatchSnapshot('seg-8-snap-full');
Expand All @@ -293,6 +302,14 @@ sentryTest(
getExpectedReplayEvent({
segment_id: 9,
urls: [],
request: {
url: `${TEST_HOST}/index.html`,
headers: {
// @ts-expect-error this is fine
'User-Agent': expect.any(String),
Referer: `${TEST_HOST}/spa`,
},
},
}),
);
expect(recording9.fullSnapshots.length).toEqual(0);
Expand All @@ -304,7 +321,7 @@ sentryTest(
];
const collectedBreadcrumbsAfterIndexNavigation = [...recording8.breadcrumbs, ...recording9.breadcrumbs];

expect(collectedPerformanceSpansAfterIndexNavigation.length).toEqual(8);
expect(collectedPerformanceSpansAfterIndexNavigation.length).toBeGreaterThanOrEqual(6);
expect(collectedPerformanceSpansAfterIndexNavigation).toEqual(
expect.arrayContaining([
expectedNavigationPerformanceSpan,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"type": 2,
"tagName": "a",
"attributes": {
"href": "/page-0.html"
"href": "http://sentry-test.io/page-0.html"
},
"childNodes": [
{
Expand Down Expand Up @@ -110,4 +110,4 @@
},
"timestamp": [timestamp]
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"type": 2,
"tagName": "a",
"attributes": {
"href": "/page-0.html"
"href": "http://sentry-test.io/page-0.html"
},
"childNodes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"type": 2,
"tagName": "a",
"attributes": {
"href": "/page-0.html"
"href": "http://sentry-test.io/page-0.html"
},
"childNodes": [
{
Expand Down Expand Up @@ -110,4 +110,4 @@
},
"timestamp": [timestamp]
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"type": 2,
"tagName": "a",
"attributes": {
"href": "/page-0.html"
"href": "http://sentry-test.io/page-0.html"
},
"childNodes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"type": 2,
"tagName": "a",
"attributes": {
"href": "/index.html"
"href": "http://sentry-test.io/index.html"
},
"childNodes": [
{
Expand Down Expand Up @@ -153,4 +153,4 @@
},
"timestamp": [timestamp]
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"type": 2,
"tagName": "a",
"attributes": {
"href": "/index.html"
"href": "http://sentry-test.io/index.html"
},
"childNodes": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"type": 2,
"tagName": "a",
"attributes": {
"href": "/page-0.html"
"href": "http://sentry-test.io/page-0.html"
},
"childNodes": [
{
Expand Down Expand Up @@ -110,4 +110,4 @@
},
"timestamp": [timestamp]
}
]
]
Loading
Loading