diff options
author | 2023-07-17 15:53:10 +0100 | |
---|---|---|
committer | 2023-07-17 15:53:10 +0100 | |
commit | 23804cda3892abe376c2657d0438ae2d80006cc9 (patch) | |
tree | 2e5ebcd04ca9d5900b22e654649eff6ef2c97c86 /packages/integrations/netlify/test/functions/edge-middleware.test.js | |
parent | d66a7e0306a3e6b0367030802f552f5049318f60 (diff) | |
download | astro-23804cda3892abe376c2657d0438ae2d80006cc9.tar.gz astro-23804cda3892abe376c2657d0438ae2d80006cc9.tar.zst astro-23804cda3892abe376c2657d0438ae2d80006cc9.zip |
feat(@astrojs/netlify): edge middleware support (#7632)
Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
Diffstat (limited to 'packages/integrations/netlify/test/functions/edge-middleware.test.js')
-rw-r--r-- | packages/integrations/netlify/test/functions/edge-middleware.test.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/packages/integrations/netlify/test/functions/edge-middleware.test.js b/packages/integrations/netlify/test/functions/edge-middleware.test.js new file mode 100644 index 000000000..219fd1ced --- /dev/null +++ b/packages/integrations/netlify/test/functions/edge-middleware.test.js @@ -0,0 +1,43 @@ +import netlifyAdapter from '../../dist/index.js'; +import { testIntegration, loadFixture } from './test-utils.js'; +import { expect } from 'chai'; + +describe('Middleware', () => { + it('with edge handle file, should successfully build the middleware', async () => { + /** @type {import('./test-utils').Fixture} */ + const fixture = await loadFixture({ + root: new URL('./fixtures/middleware-with-handler-file/', import.meta.url).toString(), + output: 'server', + adapter: netlifyAdapter({ + dist: new URL('./fixtures/middleware-with-handler-file/dist/', import.meta.url), + }), + site: `http://example.com`, + integrations: [testIntegration()], + build: { + excludeMiddleware: true, + }, + }); + await fixture.build(); + const contents = await fixture.readFile('../.netlify/edge-functions/edgeMiddleware.js'); + expect(contents.includes('"Hello world"')).to.be.true; + }); + + it('without edge handle file, should successfully build the middleware', async () => { + /** @type {import('./test-utils').Fixture} */ + const fixture = await loadFixture({ + root: new URL('./fixtures/middleware-without-handler-file/', import.meta.url).toString(), + output: 'server', + adapter: netlifyAdapter({ + dist: new URL('./fixtures/middleware-without-handler-file/dist/', import.meta.url), + }), + site: `http://example.com`, + integrations: [testIntegration()], + build: { + excludeMiddleware: true, + }, + }); + await fixture.build(); + const contents = await fixture.readFile('../.netlify/edge-functions/edgeMiddleware.js'); + expect(contents.includes('"Hello world"')).to.be.false; + }); +}); |