edge-middleware.test.js — astro Source File
Architecture documentation for edge-middleware.test.js, a javascript file in the astro codebase. 4 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR bed15954_f5ef_c6d7_bc87_51d34e6f48f6["edge-middleware.test.js"] 81c783ff_7259_703c_7bdc_c78ff183642d["test-utils.js"] bed15954_f5ef_c6d7_bc87_51d34e6f48f6 --> 81c783ff_7259_703c_7bdc_c78ff183642d f0817fb3_f192_bfcf_f1b0_c1a429dad07b["loadFixture"] bed15954_f5ef_c6d7_bc87_51d34e6f48f6 --> f0817fb3_f192_bfcf_f1b0_c1a429dad07b e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"] bed15954_f5ef_c6d7_bc87_51d34e6f48f6 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607 6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"] bed15954_f5ef_c6d7_bc87_51d34e6f48f6 --> 6b0635f9_51ea_77aa_767b_7857878e98a6 style bed15954_f5ef_c6d7_bc87_51d34e6f48f6 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';
describe('Vercel edge middleware', () => {
/** @type {import('./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',
);
const contentsJSON = JSON.parse(contents);
assert.equal(contentsJSON.runtime, 'edge');
assert.equal(contentsJSON.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);
assert.equal(
routes.some((route) => route.dest === '_middleware'),
true,
);
});
it('edge sets Set-Cookie headers', async () => {
const entry = new URL(
'../.vercel/output/functions/_middleware.func/middleware.mjs',
build.config.outDir,
);
const module = await import(entry);
const request = new Request('http://example.com/foo');
const response = await module.default(request, {});
assert.equal(response.headers.get('set-cookie'), 'foo=bar');
assert.ok((await response.text()).length, 'Body is included');
});
// 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/vercel/test/fixtures/middleware-with-edge-file/dist/middleware.mjs',
);
// assert.equal(contents.includes('title:')).to.be.true;
// chaiJestSnapshot.setTestName('Middleware with handler file');
// assert.equal(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/vercel/test/fixtures/middleware-without-edge-file/dist/middleware.mjs',
);
// assert.equal(contents.includes('title:')).to.be.false;
// chaiJestSnapshot.setTestName('Middleware without handler file');
// assert.equal(contents).to.matchSnapshot(true);
});
});
Domain
Dependencies
- loadFixture
- node:test
- strict
- test-utils.js
Source
Frequently Asked Questions
What does edge-middleware.test.js do?
edge-middleware.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does edge-middleware.test.js depend on?
edge-middleware.test.js imports 4 module(s): loadFixture, node:test, strict, test-utils.js.
Where is edge-middleware.test.js in the architecture?
edge-middleware.test.js is located at packages/integrations/vercel/test/edge-middleware.test.js (domain: CoreAstro, directory: packages/integrations/vercel/test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free