|
1 |
| -import { expect, type Locator } from '@playwright/test' |
| 1 | +import { expect, type Locator, type Response } from '@playwright/test' |
2 | 2 | import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
|
3 | 3 | import { test } from '../utils/playwright-helpers.js'
|
4 | 4 |
|
@@ -282,3 +282,59 @@ test('can require CJS module that is not bundled', async ({ simple }) => {
|
282 | 282 | expect(parsedBody.notBundledCJSModule.isBundled).toEqual(false)
|
283 | 283 | expect(parsedBody.bundledCJSModule.isBundled).toEqual(true)
|
284 | 284 | })
|
| 285 | + |
| 286 | +test.describe('RSC cache poisoning', () => { |
| 287 | + test('Next.config.js rewrite', async ({ page, simple }) => { |
| 288 | + const prefetchResponsePromise = new Promise<Response>((resolve) => { |
| 289 | + page.on('response', (response) => { |
| 290 | + if (response.url().includes('/config-rewrite/source')) { |
| 291 | + resolve(response) |
| 292 | + } |
| 293 | + }) |
| 294 | + }) |
| 295 | + await page.goto(`${simple.url}/config-rewrite`) |
| 296 | + |
| 297 | + // ensure prefetch |
| 298 | + await page.hover('text=NextConfig.rewrite') |
| 299 | + |
| 300 | + // wait for prefetch request to finish |
| 301 | + const prefetchResponse = await prefetchResponsePromise |
| 302 | + |
| 303 | + // ensure prefetch respond with RSC data |
| 304 | + expect(prefetchResponse.headers()['content-type']).toMatch(/text\/x-component/) |
| 305 | + expect(prefetchResponse.headers()['netlify-cdn-cache-control']).toMatch(/s-maxage=31536000/) |
| 306 | + |
| 307 | + const htmlResponse = await page.goto(`${simple.url}/config-rewrite/source`) |
| 308 | + |
| 309 | + // ensure we get HTML response |
| 310 | + expect(htmlResponse?.headers()['content-type']).toMatch(/text\/html/) |
| 311 | + expect(htmlResponse?.headers()['netlify-cdn-cache-control']).toMatch(/s-maxage=31536000/) |
| 312 | + }) |
| 313 | + |
| 314 | + test('Next.config.js redirect', async ({ page, simple }) => { |
| 315 | + const prefetchResponsePromise = new Promise<Response>((resolve) => { |
| 316 | + page.on('response', (response) => { |
| 317 | + if (response.url().includes('/config-redirect/dest')) { |
| 318 | + resolve(response) |
| 319 | + } |
| 320 | + }) |
| 321 | + }) |
| 322 | + await page.goto(`${simple.url}/config-redirect`) |
| 323 | + |
| 324 | + // ensure prefetch |
| 325 | + await page.hover('text=NextConfig.redirect') |
| 326 | + |
| 327 | + // wait for prefetch request to finish |
| 328 | + const prefetchResponse = await prefetchResponsePromise |
| 329 | + |
| 330 | + // ensure prefetch respond with RSC data |
| 331 | + expect(prefetchResponse.headers()['content-type']).toMatch(/text\/x-component/) |
| 332 | + expect(prefetchResponse.headers()['netlify-cdn-cache-control']).toMatch(/s-maxage=31536000/) |
| 333 | + |
| 334 | + const htmlResponse = await page.goto(`${simple.url}/config-rewrite/source`) |
| 335 | + |
| 336 | + // ensure we get HTML response |
| 337 | + expect(htmlResponse?.headers()['content-type']).toMatch(/text\/html/) |
| 338 | + expect(htmlResponse?.headers()['netlify-cdn-cache-control']).toMatch(/s-maxage=31536000/) |
| 339 | + }) |
| 340 | +}) |
0 commit comments