Files
vercel__next.js/test/e2e/edge-runtime-timer-this/edge-runtime-timer-this.test.ts
Janka Uryga 660026d50b fix: this in edge sandbox setTimeout/setInterval (#94754)
Our attempts at setting the correct `this` in our
`setTimeout`/`setInterval` polyfills were slightly incorrect, because
they used the wrong global object.

(Thanks to [cyberjoker](https://hackerone.com/cyberjoker) for
discovering this)
2026-06-12 21:28:39 +00:00

37 lines
1.2 KiB
TypeScript

import { nextTestSetup } from 'e2e-utils'
const enableCacheComponents = process.env.__NEXT_CACHE_COMPONENTS === 'true'
describe('edge-runtime-timer-this', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
// This is testing the edge runtime sandbox, which is only used in `next start`.
skipDeployment: true,
})
if (skipped) {
return
}
if (enableCacheComponents) {
it.skip('skipped because `runtime = "edge"` is not allowed in cacheComponents', () => {})
return
}
it('should not expose the outer globalThis to edge runtime callbacks', async () => {
const res = await next.fetch('/')
const text = await res.text()
// If the sandbox is escaped, the route resolves with exactly "escape successful"
// after writing a file via the outer process. It should instead fail to
// reach the outer globalThis and resolve with "escape failed:" plus the error.
expect(await next.hasFile('hello.txt')).toBe(false)
expect(text).not.toBe('escape successful')
expect(text).toMatchInlineSnapshot(`
"escape failed:
TypeError: Cannot read properties of undefined (reading 'require')"
`)
})
})