diff options
author | 2023-08-10 11:49:52 +0100 | |
---|---|---|
committer | 2023-08-10 11:49:52 +0100 | |
commit | 14b0626f3eca8ec92df29b0d43b87cd2f59efa25 (patch) | |
tree | ffbb2499b12734de79309fb098c964a9ef22428b /packages/integrations/cloudflare/test/routesJson.js | |
parent | 08c3afb8606f7e0cde30db66c07782c6c058f182 (diff) | |
parent | 1e3c9f515b78dded044a2b1582cf629a15943f69 (diff) | |
download | astro-14b0626f3eca8ec92df29b0d43b87cd2f59efa25.tar.gz astro-14b0626f3eca8ec92df29b0d43b87cd2f59efa25.tar.zst astro-14b0626f3eca8ec92df29b0d43b87cd2f59efa25.zip |
Merge remote-tracking branch 'origin/main' into next
Diffstat (limited to 'packages/integrations/cloudflare/test/routesJson.js')
-rw-r--r-- | packages/integrations/cloudflare/test/routesJson.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/packages/integrations/cloudflare/test/routesJson.js b/packages/integrations/cloudflare/test/routesJson.js new file mode 100644 index 000000000..927e4c38e --- /dev/null +++ b/packages/integrations/cloudflare/test/routesJson.js @@ -0,0 +1,78 @@ +import { expect } from 'chai'; +import { loadFixture } from './test-utils.js'; + +/** @type {import('./test-utils.js').Fixture} */ +describe('_routes.json generation', () => { + after(() => { + delete process.env.SRC; + }); + + describe('of both functions and static files', () => { + let fixture; + + before(async () => { + process.env.SRC = './src/mixed'; + fixture = await loadFixture({ + root: './fixtures/routesJson/', + }); + await fixture.build(); + }); + + it('creates `include` for functions and `exclude` for static files where needed', async () => { + const _routesJson = await fixture.readFile('/_routes.json'); + const routes = JSON.parse(_routesJson); + + expect(routes).to.deep.equal({ + version: 1, + include: ['/a/*'], + exclude: ['/a/', '/a/redirect', '/a/index.html'], + }); + }); + }); + + describe('of only functions', () => { + let fixture; + + before(async () => { + process.env.SRC = './src/dynamicOnly'; + fixture = await loadFixture({ + root: './fixtures/routesJson/', + }); + await fixture.build(); + }); + + it('creates a wildcard `include` and `exclude` only for the redirect', async () => { + const _routesJson = await fixture.readFile('/_routes.json'); + const routes = JSON.parse(_routesJson); + + expect(routes).to.deep.equal({ + version: 1, + include: ['/*'], + exclude: ['/a/redirect'], + }); + }); + }); + + describe('of only static files', () => { + let fixture; + + before(async () => { + process.env.SRC = './src/staticOnly'; + fixture = await loadFixture({ + root: './fixtures/routesJson/', + }); + await fixture.build(); + }); + + it('create only one `include` and `exclude` that are supposed to match nothing', async () => { + const _routesJson = await fixture.readFile('/_routes.json'); + const routes = JSON.parse(_routesJson); + + expect(routes).to.deep.equal({ + version: 1, + include: ['/'], + exclude: ['/'], + }); + }); + }); +}); |