Skip to content

Commit

Permalink
test: Fix flaky csp test (#13376)
Browse files Browse the repository at this point in the history
  • Loading branch information
chargome authored Aug 27, 2024
1 parent 80a116b commit 6cb6999
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,3 @@ Sentry.init({
feedbackIntegration({ tags: { from: 'integration init' }, styleNonce: 'foo1234', scriptNonce: 'foo1234' }),
],
});

document.addEventListener('securitypolicyviolation', () => {
const container = document.querySelector('#csp-violation');
if (container) {
container.innerText = 'CSP Violation';
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
window.__CSPVIOLATION__ = false;
document.addEventListener('securitypolicyviolation', () => {
window.__CSPVIOLATION__ = true;
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
content="style-src 'nonce-foo1234'; script-src sentry-test.io 'nonce-foo1234';"
/>
</head>
<body>
<div id="csp-violation" />
</body>
<body></body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ sentryTest('should capture feedback', async ({ getLocalTestUrl, page }) => {
},
platform: 'javascript',
});
const cspContainer = await page.locator('#csp-violation');
expect(cspContainer).not.toContainText('CSP Violation');
const cspViolation = await page.evaluate<boolean>('window.__CSPVIOLATION__');
expect(cspViolation).toBe(false);
});

0 comments on commit 6cb6999

Please sign in to comment.