diff options
author | 2024-10-21 10:08:17 +0200 | |
---|---|---|
committer | 2024-10-21 10:08:17 +0200 | |
commit | 6ebcb9b2f5a2027e8b34d990e67acab7bd1e08e6 (patch) | |
tree | b9869bb9b8dd52be1153722c1d03e9abceb14699 /packages/integrations/cloudflare/test/routes-json.test.js | |
parent | 50a79c6503f408d4286cc51e5476418a0db65d15 (diff) | |
download | astro-6ebcb9b2f5a2027e8b34d990e67acab7bd1e08e6.tar.gz astro-6ebcb9b2f5a2027e8b34d990e67acab7bd1e08e6.tar.zst astro-6ebcb9b2f5a2027e8b34d990e67acab7bd1e08e6.zip |
feat: improve _routes.json generation (#423)
Diffstat (limited to 'packages/integrations/cloudflare/test/routes-json.test.js')
-rw-r--r-- | packages/integrations/cloudflare/test/routes-json.test.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/test/routes-json.test.js b/packages/integrations/cloudflare/test/routes-json.test.js index 028549bad..b7494b1c5 100644 --- a/packages/integrations/cloudflare/test/routes-json.test.js +++ b/packages/integrations/cloudflare/test/routes-json.test.js @@ -185,4 +185,58 @@ describe('_routes.json generation', () => { }); }); }); + + describe('with many static files', () => { + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: new URL('./fixtures/routes-json/', import.meta.url).toString(), + srcDir: './src/manyStatic', + adapter: cloudflare({}), + }); + await fixture.build(); + }); + + it('creates a wildcard `include` and `exclude` for as many static assets and redirects as possible, truncating after 100 rules', async () => { + const _routesJson = await fixture.readFile('/_routes.json'); + const routes = JSON.parse(_routesJson); + + assert.deepEqual(routes, { + version: 1, + include: ['/*'], + exclude: [ + '/_astro/*', + '/redirectme', + '/public.txt', + '/a/*', + ...Array.from({ length: 95 }, (_, i) => `/${i}`), + ], + }); + }); + }); + + describe('with many static files when a static 404 is present', () => { + let fixture; + + before(async () => { + fixture = await loadFixture({ + root: new URL('./fixtures/routes-json/', import.meta.url).toString(), + srcDir: './src/manyStaticWith404', + adapter: cloudflare({}), + }); + await fixture.build(); + }); + + it('creates `include` for on-demand and `exclude` that are supposed to match nothin', async () => { + const _routesJson = await fixture.readFile('/_routes.json'); + const routes = JSON.parse(_routesJson); + + assert.deepEqual(routes, { + version: 1, + include: ['/_image', '/dynamic'], + exclude: [], + }); + }); + }); }); |