|
1 | 1 | import * as assert from 'node:assert/strict'; |
| 2 | +import { rmSync } from 'node:fs'; |
2 | 3 | import { after, before, describe, it } from 'node:test'; |
3 | | -import { type Fixture, loadFixture, type PreviewServer } from './test-utils.ts'; |
| 4 | +import { fileURLToPath } from 'node:url'; |
| 5 | +import { type DevServer, type Fixture, loadFixture, type PreviewServer } from './test-utils.ts'; |
4 | 6 |
|
5 | 7 | // Regression test for https://github.com/withastro/astro/issues/17591: |
6 | 8 | // a custom worker entryfile that builds its own request state with |
@@ -38,3 +40,30 @@ describe('Custom entry file using astro/fetch', () => { |
38 | 40 | ); |
39 | 41 | }); |
40 | 42 | }); |
| 43 | + |
| 44 | +describe('Custom entry file using astro/fetch in dev', () => { |
| 45 | + let fixture: Fixture; |
| 46 | + let devServer: DevServer; |
| 47 | + |
| 48 | + before(async () => { |
| 49 | + fixture = await loadFixture({ |
| 50 | + root: './fixtures/custom-entryfile-fetch-state/', |
| 51 | + }); |
| 52 | + // Optimizer plugins are not included in Vite's cache key. |
| 53 | + const viteCacheDir = new URL('./node_modules/.vite/', fixture.config.root); |
| 54 | + rmSync(fileURLToPath(viteCacheDir), { recursive: true, force: true }); |
| 55 | + devServer = await fixture.startDevServer(); |
| 56 | + }); |
| 57 | + |
| 58 | + after(async () => { |
| 59 | + await devServer.stop(); |
| 60 | + }); |
| 61 | + |
| 62 | + it('renders an SSR page from a state built with new FetchState(request)', async () => { |
| 63 | + const response = await fixture.fetch('/'); |
| 64 | + const html = await response.text(); |
| 65 | + assert.equal(response.status, 200, html); |
| 66 | + assert.equal(response.headers.get('X-Fetch-State-Entrypoint'), 'true'); |
| 67 | + assert.match(html, /astro-cloudflare-custom-entryfile-fetch-state/); |
| 68 | + }); |
| 69 | +}); |
0 commit comments