mirror of
https://github.com/withastro/astro.git
synced 2025-01-06 22:10:10 -05:00
05adaaa2d2
* create vercel edge middleware remove getVercelOutput * handle node built-in modules * edge function to node fetch * adjust tests * add test * add changeset * function paths as constants * ensure node built-in modules are namespaced with `node:` * x-astro-path as constant * appease linter * add comments for ASTRO_PATH_HEADER and ASTRO_LOCALS_HEADER --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
63 lines
2.2 KiB
JavaScript
63 lines
2.2 KiB
JavaScript
import { expect } from 'chai';
|
|
import chaiJestSnapshot from 'chai-jest-snapshot';
|
|
import { loadFixture } from './test-utils.js';
|
|
|
|
describe('Vercel edge middleware', () => {
|
|
/** @type {import('../../../astro/test/test-utils.js').Fixture} */
|
|
let build;
|
|
before(async () => {
|
|
build = await loadFixture({
|
|
root: './fixtures/middleware-with-edge-file/',
|
|
});
|
|
await build.build();
|
|
});
|
|
|
|
it('an edge function is created', async () => {
|
|
const contents = await build.readFile(
|
|
'../.vercel/output/functions/_middleware.func/.vc-config.json'
|
|
);
|
|
expect(JSON.parse(contents)).to.deep.include({
|
|
"runtime": "edge",
|
|
"entrypoint": "middleware.mjs"
|
|
});
|
|
});
|
|
|
|
|
|
it('deployment config points to the middleware edge function', async () => {
|
|
const contents = await build.readFile(
|
|
'../.vercel/output/config.json'
|
|
);
|
|
const { routes } = JSON.parse(contents);
|
|
expect(routes.some(route => route.dest === '_middleware')).to.be.true;
|
|
});
|
|
|
|
// TODO: The path here seems to be inconsistent?
|
|
it.skip('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/www/withastro/astro/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);
|
|
});
|
|
|
|
// TODO: The path here seems to be inconsistent?
|
|
it.skip('without 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/www/withastro/astro/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);
|
|
});
|
|
});
|