summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test/routes-json.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/cloudflare/test/routes-json.test.js')
-rw-r--r--packages/integrations/cloudflare/test/routes-json.test.js54
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: [],
+ });
+ });
+ });
});