summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/test/functions/edge-middleware.test.js
diff options
context:
space:
mode:
authorGravatar Emanuele Stoppa <my.burning@gmail.com> 2023-07-17 15:53:10 +0100
committerGravatar GitHub <noreply@github.com> 2023-07-17 15:53:10 +0100
commit4c93bd8154c210ebce6ad2889bd8bfdf4c349a78 (patch)
treee0b9fb9474845411b35f177260408f444d0631ff /packages/integrations/netlify/test/functions/edge-middleware.test.js
parentcc8e9de88179d2ed4b70980c60b41448db393429 (diff)
downloadastro-4c93bd8154c210ebce6ad2889bd8bfdf4c349a78.tar.gz
astro-4c93bd8154c210ebce6ad2889bd8bfdf4c349a78.tar.zst
astro-4c93bd8154c210ebce6ad2889bd8bfdf4c349a78.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.js43
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;
+ });
+});