summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/test/directory.test.js
blob: a252b03e9254de41e0b24ae74e5f663e8e65d2e0 (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
import { loadFixture } from './test-utils.js';
import { expect } from 'chai';
import cloudflare from '../dist/index.js';

/** @type {import('./test-utils').Fixture} */
describe('mode: "directory"', () => {
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/basics/',
			output: 'server',
			adapter: cloudflare({ mode: 'directory' }),
			redirects: {
				'/old': '/',
			},
		});
		await fixture.build();
	});

	it('generates functions folder inside the project root', async () => {
		expect(await fixture.pathExists('../functions')).to.be.true;
		expect(await fixture.pathExists('../functions/[[path]].js')).to.be.true;
	});

	it('generates a redirects file', async () => {
		try {
			let _redirects = await fixture.readFile('/_redirects');
			let parts = _redirects.split(/\s+/);
			expect(parts).to.deep.equal(['/old', '/', '301']);
		} catch {
			expect(false).to.equal(true);
		}
	});
});