88a033fa1f
### What? Exposing `globalThis.crypto`, based on [Node.js' WebCrypto API](https://nodejs.org/api/globals.html#crypto_1) ### Why? Similar to `fetch`, `crypto` is a popular API that is currently not available on `globalThis` in all active Node.js versions yet. This can help library authors to create runtime-agnostic packages. ### How? Node.js already has the WebCrypto API that can be imported, we just expose it on `globalThis` in Node.js versions where this is not available. Closes NEXT-1063 [Slack thread](https://vercel.slack.com/archives/C03KAR5DCKC/p1681821510191059)
22 lines
675 B
TypeScript
22 lines
675 B
TypeScript
import { createNextDescribe } from 'e2e-utils'
|
|
|
|
createNextDescribe(
|
|
'Web Crypto API is available globally',
|
|
{
|
|
files: __dirname,
|
|
},
|
|
({ next }) => {
|
|
// Recommended for tests that need a full browser
|
|
it('should be available in Server Components', async () => {
|
|
const browser = await next.browser('/')
|
|
expect(await browser.elementByCss('p').text()).toBe('crypto is available')
|
|
})
|
|
|
|
// In case you need to test the response object
|
|
it('should be available in Route Handlers', async () => {
|
|
const res = await next.fetch('/handler')
|
|
const html = await res.text()
|
|
expect(html).toContain('crypto is available')
|
|
})
|
|
}
|
|
)
|