Skip to content

Commit 6cb6999

Browse files
authored
test: Fix flaky csp test (#13376)
1 parent 80a116b commit 6cb6999

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/init.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,3 @@ Sentry.init({
1010
feedbackIntegration({ tags: { from: 'integration init' }, styleNonce: 'foo1234', scriptNonce: 'foo1234' }),
1111
],
1212
});
13-
14-
document.addEventListener('securitypolicyviolation', () => {
15-
const container = document.querySelector('#csp-violation');
16-
if (container) {
17-
container.innerText = 'CSP Violation';
18-
}
19-
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
window.__CSPVIOLATION__ = false;
2+
document.addEventListener('securitypolicyviolation', () => {
3+
window.__CSPVIOLATION__ = true;
4+
});

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/template.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@
77
content="style-src 'nonce-foo1234'; script-src sentry-test.io 'nonce-foo1234';"
88
/>
99
</head>
10-
<body>
11-
<div id="csp-violation" />
12-
</body>
10+
<body></body>
1311
</html>

dev-packages/browser-integration-tests/suites/feedback/captureFeedbackCsp/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
7979
},
8080
platform: 'javascript',
8181
});
82-
const cspContainer = await page.locator('#csp-violation');
83-
expect(cspContainer).not.toContainText('CSP Violation');
82+
const cspViolation = await page.evaluate<boolean>('window.__CSPVIOLATION__');
83+
expect(cspViolation).toBe(false);
8484
});

0 commit comments

Comments
 (0)