0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/integrations/netlify/test/functions/edge-middleware.test.js
Emanuele Stoppa 4c93bd8154
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>
2023-07-17 15:53:10 +01:00

43 lines
1.6 KiB
JavaScript

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;
});
});