Skip to content

Commit

Permalink
Print react-error-overlay CSP hash in test error
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Dec 7, 2023
1 parent f625099 commit e695fea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions internals/getSecurityHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const localnet = `
const hmrWebsocket = `
ws://localhost:2222
`
// If this changes csp-react-error-overlay.spec.ts will print a new sha in an error in csp-react-error-overlay.spec.ts.
const reactErrorOverlay = `'sha256-yt+SNVxRkIi6H6yb7ndFuZM1esMX9esg3UpRHaTsyVk='`
const hmrScripts = `
'unsafe-eval'
Expand Down
2 changes: 2 additions & 0 deletions playwright/tests/csp-react-error-overlay.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { test, expect } from '@playwright/test'
import { reactErrorOverlay } from '../../internals/getSecurityHeaders.js'
import { expectNoErrorsInConsole } from '../utils/expectNoErrorsInConsole'

test('Dev Content-Security-Policy should allow react-error-overlay', async ({ page, baseURL }) => {
if (baseURL !== 'http://localhost:3000') test.skip()
expect((await page.request.head('/')).headers()).toHaveProperty('content-security-policy')
expect((await page.request.head('/')).headers()['content-security-policy']).toContain(reactErrorOverlay)
await page.goto('/e2e')
await page.getByRole('button', { name: 'Trigger uncaught error' }).click()
await expectNoErrorsInConsole(page)
await expect(page.locator('iframe')).toBeVisible()
await expect(page.frameLocator('iframe').getByText('ReferenceError')).toBeVisible()
})

0 comments on commit e695fea

Please sign in to comment.