Skip to content

Commit 6bf0b8f

Browse files
committed
add regression test
1 parent a3acd38 commit 6bf0b8f

File tree

5 files changed

+79
-7
lines changed

5 files changed

+79
-7
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
integrations: [
8+
Sentry.browserTracingIntegration({
9+
idleTimeout: 9000,
10+
enableLongAnimationFrame: false,
11+
instrumentPageLoad: false,
12+
instrumentNavigation: true,
13+
enableInp: false,
14+
enableLongTask: true,
15+
}),
16+
],
17+
tracesSampleRate: 1,
18+
debug: true,
19+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const longTaskButton = document.getElementById('myButton');
2+
3+
longTaskButton?.addEventListener('click', () => {
4+
const startTime = Date.now();
5+
6+
function getElapsed() {
7+
const time = Date.now();
8+
return time - startTime;
9+
}
10+
11+
while (getElapsed() < 500) {
12+
//
13+
}
14+
15+
// trigger a navigation in the same event loop tick
16+
window.history.pushState({}, '', '/#myHeading');
17+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
</head>
6+
<body>
7+
<div>Rendered Before Long Task</div>
8+
<script src="https://example.com/path/to/script.js"></script>
9+
10+
<button id="myButton">Start long task</button>
11+
<h1 id="myHeading">Heading</h1>
12+
</body>
13+
</html>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { Event } from '@sentry/types';
2+
import { expect } from '@playwright/test';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
6+
7+
sentryTest(
8+
"doesn't capture long task spans starting before a navigation in the navigation transaction",
9+
async ({ browserName, getLocalTestPath, page }) => {
10+
// Long tasks only work on chrome
11+
if (shouldSkipTracingTest() || browserName !== 'chromium') {
12+
sentryTest.skip();
13+
}
14+
const url = await getLocalTestPath({ testDir: __dirname });
15+
16+
await page.goto(url);
17+
18+
await page.locator('#myButton').click();
19+
20+
const navigationTransactionEvent = await getFirstSentryEnvelopeRequest<Event>(page, url);
21+
22+
expect(navigationTransactionEvent.contexts?.trace?.op).toBe('navigation');
23+
24+
const longTaskSpans = navigationTransactionEvent?.spans?.filter(span => span.op === 'ui.long-task');
25+
expect(longTaskSpans).toHaveLength(0);
26+
},
27+
);

packages/browser/package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"engines": {
1010
"node": ">=14.18"
1111
},
12-
"files": [
13-
"/build/npm"
14-
],
12+
"files": ["/build/npm"],
1513
"main": "build/npm/cjs/index.js",
1614
"module": "build/npm/esm/index.js",
1715
"types": "build/npm/types/index.d.ts",
@@ -30,9 +28,7 @@
3028
},
3129
"typesVersions": {
3230
"<4.9": {
33-
"build/npm/types/index.d.ts": [
34-
"build/npm/types-ts3.8/index.d.ts"
35-
]
31+
"build/npm/types/index.d.ts": ["build/npm/types-ts3.8/index.d.ts"]
3632
}
3733
},
3834
"publishConfig": {
@@ -53,7 +49,7 @@
5349
},
5450
"scripts": {
5551
"build": "run-p build:transpile build:bundle build:types",
56-
"build:dev": "yarn build",
52+
"build:dev": "run-p build:transpile build:types",
5753
"build:bundle": "rollup -c rollup.bundle.config.mjs",
5854
"build:transpile": "rollup -c rollup.npm.config.mjs",
5955
"build:types": "run-s build:types:core build:types:downlevel",

0 commit comments

Comments
 (0)