summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/test/functions/edge-middleware.test.js
blob: 219fd1ced80c49c6944d66820032b80228db1c57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;
	});
});