Skip to content

Commit 8f07f87

Browse files
committed
add more tests for LoAF, long task, reportPageLoaded, fetch, xhr, setSpanActiveInBrowser
1 parent 05f531a commit 8f07f87

File tree

52 files changed

+1351
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1351
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
integrations: [
8+
Sentry.browserTracingIntegration({
9+
idleTimeout: 2000,
10+
enableLongTask: false,
11+
enableLongAnimationFrame: true,
12+
instrumentPageLoad: false,
13+
enableInp: false,
14+
}),
15+
Sentry.spanStreamingIntegration(),
16+
],
17+
tracesSampleRate: 1,
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function getElapsed(startTime) {
2+
const time = Date.now();
3+
return time - startTime;
4+
}
5+
6+
function handleClick() {
7+
const startTime = Date.now();
8+
while (getElapsed(startTime) < 105) {
9+
//
10+
}
11+
window.history.pushState({}, '', `#myHeading`);
12+
}
13+
14+
const button = document.getElementById('clickme');
15+
16+
console.log('button', button);
17+
18+
button.addEventListener('click', handleClick);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<button id="clickme">click me to start the long animation!</button>
8+
9+
<h1 id="myHeading">My Heading</h1>
10+
</body>
11+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect } from '@playwright/test';
2+
import { sentryTest } from '../../../../utils/fixtures';
3+
import { shouldSkipTracingTest } from '../../../../utils/helpers';
4+
import { getSpanOp, waitForStreamedSpans } from '../../../../utils/spanUtils';
5+
6+
sentryTest(
7+
"doesn't capture long animation frame that starts before a navigation.",
8+
async ({ browserName, getLocalTestUrl, page }) => {
9+
// Long animation frames only work on chrome
10+
if (shouldSkipTracingTest() || browserName !== 'chromium') {
11+
sentryTest.skip();
12+
}
13+
14+
const url = await getLocalTestUrl({ testDir: __dirname });
15+
16+
const navigationSpansPromise = waitForStreamedSpans(page, spans => spans.some(s => getSpanOp(s) === 'navigation'));
17+
18+
await page.goto(url);
19+
20+
await page.locator('#clickme').click();
21+
22+
const spans = await navigationSpansPromise;
23+
24+
const loafSpans = spans.filter(s => getSpanOp(s)?.startsWith('ui.long-animation-frame'));
25+
expect(loafSpans).toHaveLength(0);
26+
},
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(() => {
2+
const startTime = Date.now();
3+
4+
function getElapsed() {
5+
const time = Date.now();
6+
return time - startTime;
7+
}
8+
9+
while (getElapsed() < 101) {
10+
//
11+
}
12+
})();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
integrations: [
8+
Sentry.browserTracingIntegration({ enableLongTask: false, enableLongAnimationFrame: false, idleTimeout: 2000 }),
9+
Sentry.spanStreamingIntegration(),
10+
],
11+
tracesSampleRate: 1,
12+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<div>Rendered Before Long Animation Frame</div>
8+
<script src="https://sentry-test-site.example/path/to/script.js"></script>
9+
</body>
10+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Route } from '@playwright/test';
2+
import { expect } from '@playwright/test';
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { shouldSkipTracingTest } from '../../../../utils/helpers';
5+
import { getSpanOp, waitForStreamedSpans } from '../../../../utils/spanUtils';
6+
7+
sentryTest(
8+
'should not capture long animation frame when flag is disabled.',
9+
async ({ browserName, getLocalTestUrl, page }) => {
10+
// Long animation frames only work on chrome
11+
if (shouldSkipTracingTest() || browserName !== 'chromium') {
12+
sentryTest.skip();
13+
}
14+
15+
await page.route('**/path/to/script.js', (route: Route) =>
16+
route.fulfill({ path: `${__dirname}/assets/script.js` }),
17+
);
18+
19+
const url = await getLocalTestUrl({ testDir: __dirname });
20+
21+
const spansPromise = waitForStreamedSpans(page, spans => spans.some(s => getSpanOp(s) === 'pageload'));
22+
23+
await page.goto(url);
24+
25+
const spans = await spansPromise;
26+
const uiSpans = spans.filter(s => getSpanOp(s)?.startsWith('ui'));
27+
28+
expect(uiSpans.length).toBe(0);
29+
},
30+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function getElapsed(startTime) {
2+
const time = Date.now();
3+
return time - startTime;
4+
}
5+
6+
function handleClick() {
7+
const startTime = Date.now();
8+
while (getElapsed(startTime) < 105) {
9+
//
10+
}
11+
}
12+
13+
function start() {
14+
const startTime = Date.now();
15+
while (getElapsed(startTime) < 105) {
16+
//
17+
}
18+
}
19+
20+
// trigger 2 long-animation-frame events
21+
// one from the top-level and the other from an event-listener
22+
start();
23+
24+
const button = document.getElementById('clickme');
25+
button.addEventListener('click', handleClick);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
7+
integrations: [
8+
Sentry.browserTracingIntegration({
9+
idleTimeout: 2000,
10+
enableLongTask: false,
11+
enableLongAnimationFrame: true,
12+
}),
13+
Sentry.spanStreamingIntegration(),
14+
],
15+
tracesSampleRate: 1,
16+
});

0 commit comments

Comments
 (0)