summaryrefslogtreecommitdiff
path: root/packages/integrations/vercel/test/edge-middleware.test.js
blob: c713c546460debb5a9922035bb7e2054f435a6ef (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
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';
import chaiJestSnapshot from 'chai-jest-snapshot';

describe('Vercel edge middleware', () => {
	it('with edge handle file, should successfully build the middleware', async () => {
		const fixture = await loadFixture({
			root: './fixtures/middleware-with-edge-file/',
		});
		await fixture.build();
		const contents = await fixture.readFile(
			// this is abysmal...
			'../.vercel/output/functions/render.func/packages/integrations/vercel/test/fixtures/middleware-with-edge-file/dist/middleware.mjs'
		);
		expect(contents.includes('title:')).to.be.true;
		chaiJestSnapshot.setTestName('Middleware with handler file');
		expect(contents).to.matchSnapshot(true);
	});

	it('with edge handle file, should successfully build the middleware', async () => {
		const fixture = await loadFixture({
			root: './fixtures/middleware-without-edge-file/',
		});
		await fixture.build();
		const contents = await fixture.readFile(
			// this is abysmal...
			'../.vercel/output/functions/render.func/packages/integrations/vercel/test/fixtures/middleware-without-edge-file/dist/middleware.mjs'
		);
		expect(contents.includes('title:')).to.be.false;
		chaiJestSnapshot.setTestName('Middleware without handler file');
		expect(contents).to.matchSnapshot(true);
	});
});