Skip to content

Commit b97d3c1

Browse files
authored
Merge branch 'develop' into nh/instrument-interceptors-after-route
2 parents e639af5 + a8c0a3b commit b97d3c1

File tree

107 files changed

+1504
-759
lines changed

Some content is hidden

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

107 files changed

+1504
-759
lines changed

.github/actions/install-playwright/action.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,23 @@ runs:
1313
run: echo "version=$(node -p "require('@playwright/test/package.json').version")" >> $GITHUB_OUTPUT
1414
shell: bash
1515

16-
- name: Cache playwright binaries
17-
uses: actions/cache@v4
16+
- name: Restore cached playwright binaries
17+
uses: actions/cache/restore@v4
1818
id: playwright-cache
1919
with:
2020
path: |
2121
~/.cache/ms-playwright
2222
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}
2323

24+
# Only store cache on develop branch
25+
- name: Store cached playwright binaries
26+
uses: actions/cache/save@v4
27+
if: github.event_name == 'push' && github.ref == 'refs/heads/develop'
28+
with:
29+
path: |
30+
~/.cache/ms-playwright
31+
key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }}
32+
2433
# We always install all browsers, if uncached
2534
- name: Install Playwright dependencies (uncached)
2635
run: npx playwright install chromium webkit firefox --with-deps

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ jobs:
847847
[
848848
'angular-17',
849849
'angular-18',
850+
'astro-4',
850851
'aws-lambda-layer-cjs',
851852
'aws-serverless-esm',
852853
'node-express',

dev-packages/browser-integration-tests/loader-suites/loader/noOnLoad/sdkLoadedInMeanwhile/test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import fs from 'fs';
2-
import path from 'path';
1+
import * as fs from 'fs';
2+
import * as path from 'path';
33
import { expect } from '@playwright/test';
44

55
import { TEST_HOST, sentryTest } from '../../../../utils/fixtures';
@@ -28,19 +28,22 @@ sentryTest('it does not download the SDK if the SDK was loaded in the meanwhile'
2828
});
2929
});
3030

31+
const tmpDir = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true });
32+
3133
await page.route(`${TEST_HOST}/*.*`, route => {
3234
const file = route.request().url().split('/').pop();
3335

3436
if (file === 'cdn.bundle.js') {
3537
cdnLoadedCount++;
3638
}
3739

38-
const filePath = path.resolve(__dirname, `./dist/${file}`);
40+
const filePath = path.resolve(tmpDir, `./${file}`);
3941

4042
return fs.existsSync(filePath) ? route.fulfill({ path: filePath }) : route.continue();
4143
});
4244

43-
const url = await getLocalTestUrl({ testDir: __dirname, skipRouteHandler: true });
45+
const url = `${TEST_HOST}/index.html`;
46+
4447
const req = await waitForErrorRequestOnUrl(page, url);
4548

4649
const eventData = envelopeRequestParser(req);

dev-packages/browser-integration-tests/playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const config: PlaywrightTestConfig = {
3131
],
3232

3333
globalSetup: require.resolve('./playwright.setup.ts'),
34+
globalTeardown: require.resolve('./playwright.teardown.ts'),
3435
};
3536

3637
export default config;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as childProcess from 'child_process';
2+
3+
export default function globalTeardown(): void {
4+
childProcess.execSync('yarn clean', { stdio: 'inherit', cwd: process.cwd() });
5+
}
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+
// Import this separately so that generatePlugin can handle it for CDN scenarios
3+
import { feedbackIntegration } from '@sentry/browser';
4+
5+
window.Sentry = Sentry;
6+
7+
Sentry.init({
8+
dsn: 'https://public@dsn.ingest.sentry.io/1337',
9+
integrations: [
10+
feedbackIntegration({ tags: { from: 'integration init' }, styleNonce: 'foo1234', scriptNonce: 'foo1234' }),
11+
],
12+
});
13+
14+
document.addEventListener('securitypolicyviolation', () => {
15+
const container = document.querySelector('#csp-violation');
16+
if (container) {
17+
container.innerText = 'CSP Violation';
18+
}
19+
});
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+
<meta
6+
http-equiv="Content-Security-Policy"
7+
content="style-src 'nonce-foo1234'; script-src sentry-test.io 'nonce-foo1234';"
8+
/>
9+
</head>
10+
<body>
11+
<div id="csp-violation" />
12+
</body>
13+
</html>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { TEST_HOST, sentryTest } from '../../../utils/fixtures';
4+
import { envelopeRequestParser, getEnvelopeType, shouldSkipFeedbackTest } from '../../../utils/helpers';
5+
6+
sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
7+
if (shouldSkipFeedbackTest()) {
8+
sentryTest.skip();
9+
}
10+
11+
const feedbackRequestPromise = page.waitForResponse(res => {
12+
const req = res.request();
13+
14+
const postData = req.postData();
15+
if (!postData) {
16+
return false;
17+
}
18+
19+
try {
20+
return getEnvelopeType(req) === 'feedback';
21+
} catch (err) {
22+
return false;
23+
}
24+
});
25+
26+
await page.route('https://dsn.ingest.sentry.io/**/*', route => {
27+
return route.fulfill({
28+
status: 200,
29+
contentType: 'application/json',
30+
body: JSON.stringify({ id: 'test-id' }),
31+
});
32+
});
33+
34+
const url = await getLocalTestUrl({ testDir: __dirname });
35+
36+
await page.goto(url);
37+
await page.getByText('Report a Bug').click();
38+
expect(await page.locator(':visible:text-is("Report a Bug")').count()).toEqual(1);
39+
await page.locator('[name="name"]').fill('Jane Doe');
40+
await page.locator('[name="email"]').fill('janedoe@example.org');
41+
await page.locator('[name="message"]').fill('my example feedback');
42+
await page.locator('[data-sentry-feedback] .btn--primary').click();
43+
44+
const feedbackEvent = envelopeRequestParser((await feedbackRequestPromise).request());
45+
expect(feedbackEvent).toEqual({
46+
type: 'feedback',
47+
breadcrumbs: expect.any(Array),
48+
contexts: {
49+
feedback: {
50+
contact_email: 'janedoe@example.org',
51+
message: 'my example feedback',
52+
name: 'Jane Doe',
53+
source: 'widget',
54+
url: `${TEST_HOST}/index.html`,
55+
},
56+
trace: {
57+
trace_id: expect.stringMatching(/\w{32}/),
58+
span_id: expect.stringMatching(/\w{16}/),
59+
},
60+
},
61+
level: 'info',
62+
tags: {
63+
from: 'integration init',
64+
},
65+
timestamp: expect.any(Number),
66+
event_id: expect.stringMatching(/\w{32}/),
67+
environment: 'production',
68+
sdk: {
69+
integrations: expect.arrayContaining(['Feedback']),
70+
version: expect.any(String),
71+
name: 'sentry.javascript.browser',
72+
packages: expect.anything(),
73+
},
74+
request: {
75+
url: `${TEST_HOST}/index.html`,
76+
headers: {
77+
'User-Agent': expect.stringContaining(''),
78+
},
79+
},
80+
platform: 'javascript',
81+
});
82+
const cspContainer = await page.locator('#csp-violation');
83+
expect(cspContainer).not.toContainText('CSP Violation');
84+
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
fetch('http://localhost:7654/foo').then(() => {
1+
fetch('http://sentry-test.io/foo').then(() => {
22
Sentry.captureException('test error');
33
});

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/get/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sentryTest('captures Breadcrumb for basic GET request', async ({ getLocalTestUrl
3131
data: {
3232
method: 'GET',
3333
status_code: 200,
34-
url: 'http://localhost:7654/foo',
34+
url: 'http://sentry-test.io/foo',
3535
},
3636
});
3737
});

0 commit comments

Comments
 (0)