Home / File/ endpoints.test.js — astro Source File

endpoints.test.js — astro Source File

Architecture documentation for endpoints.test.js, a javascript file in the astro codebase. 8 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  ce6f853c_d307_6254_377b_72038fa759cd["endpoints.test.js"]
  d941fcda_7a73_7111_5c8f_ff626cd2fcad["../../../dist/core/dev/container.js"]
  ce6f853c_d307_6254_377b_72038fa759cd --> d941fcda_7a73_7111_5c8f_ff626cd2fcad
  be670a78_841c_46e5_0af5_c5c328869ecb["test-adapter.js"]
  ce6f853c_d307_6254_377b_72038fa759cd --> be670a78_841c_46e5_0af5_c5c328869ecb
  b0be4d0c_86b6_a283_f2af_003189bfd572["test-utils.js"]
  ce6f853c_d307_6254_377b_72038fa759cd --> b0be4d0c_86b6_a283_f2af_003189bfd572
  16e9d20a_70fc_8349_984c_4af9e0b840d5["createBasicSettings"]
  ce6f853c_d307_6254_377b_72038fa759cd --> 16e9d20a_70fc_8349_984c_4af9e0b840d5
  f0937d94_cf30_e0fa_fbd5_135f8c876f70["createFixture"]
  ce6f853c_d307_6254_377b_72038fa759cd --> f0937d94_cf30_e0fa_fbd5_135f8c876f70
  37bee138_718e_22c5_b294_37b0235244a2["createRequestAndResponse"]
  ce6f853c_d307_6254_377b_72038fa759cd --> 37bee138_718e_22c5_b294_37b0235244a2
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  ce6f853c_d307_6254_377b_72038fa759cd --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  ce6f853c_d307_6254_377b_72038fa759cd --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style ce6f853c_d307_6254_377b_72038fa759cd fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import * as assert from 'node:assert/strict';
import { after, before, describe, it } from 'node:test';
import { createContainer } from '../../../dist/core/dev/container.js';
import testAdapter from '../../test-adapter.js';
import {
	createBasicSettings,
	createFixture,
	createRequestAndResponse,
	defaultLogger,
} from '../test-utils.js';

const fileSystem = {
	'/src/pages/response-redirect.ts': `export const GET = ({ url }) => Response.redirect("https://example.com/destination", 307)`,
	'/src/pages/response.ts': `export const GET = ({ url }) => new Response(null, { headers: { Location: "https://example.com/destination" }, status: 307 })`,
	'/src/pages/not-found.ts': `export const GET = ({ url }) => new Response('empty', { headers: { "Content-Type": "text/plain" }, status: 404 })`,
	'/src/pages/internal-error.ts': `export const GET = ({ url }) => new Response('something went wrong', { headers: { "Content-Type": "text/plain" }, status: 500 })`,
};

describe('endpoints', () => {
	let container;
	let settings;

	before(async () => {
		const fixture = await createFixture(fileSystem);
		settings = await createBasicSettings({
			root: fixture.path,
			output: 'server',
			adapter: testAdapter(),
		});
		container = await createContainer({
			fs,
			settings,
			logger: defaultLogger,
		});
	});

	after(async () => {
		await container.close();
	});

	it('should return a redirect response with location header', async () => {
		const { req, res, done } = createRequestAndResponse({
			method: 'GET',
			url: '/response-redirect',
		});
		container.handle(req, res);
		await done;
		const headers = res.getHeaders();
		assert.equal(headers['location'], 'https://example.com/destination');
		assert.equal(headers['x-astro-reroute'], undefined);
		assert.equal(res.statusCode, 307);
	});

	it('should return a response with location header', async () => {
		const { req, res, done } = createRequestAndResponse({
			method: 'GET',
			url: '/response',
		});
		container.handle(req, res);
		await done;
		const headers = res.getHeaders();
		assert.equal(headers['location'], 'https://example.com/destination');
		assert.equal(res.statusCode, 307);
	});

	it('should remove internally-used for HTTP status 404', async () => {
		const { req, res, done } = createRequestAndResponse({
			method: 'GET',
			url: '/not-found',
		});
		container.handle(req, res);
		await done;
		const headers = res.getHeaders();
		assert.equal(headers['x-astro-reroute'], undefined);
		assert.equal(res.statusCode, 404);
	});

	it('should remove internally-used header for HTTP status 500', async () => {
		const { req, res, done } = createRequestAndResponse({
			method: 'GET',
			url: '/internal-error',
		});
		container.handle(req, res);
		await done;
		const headers = res.getHeaders();
		assert.equal(headers['x-astro-reroute'], undefined);
		assert.equal(res.statusCode, 500);
	});
});

Dependencies

Frequently Asked Questions

What does endpoints.test.js do?
endpoints.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does endpoints.test.js depend on?
endpoints.test.js imports 8 module(s): ../../../dist/core/dev/container.js, createBasicSettings, createFixture, createRequestAndResponse, node:test, strict, test-adapter.js, test-utils.js.
Where is endpoints.test.js in the architecture?
endpoints.test.js is located at packages/astro/test/units/routing/endpoints.test.js (domain: IntegrationAdapters, directory: packages/astro/test/units/routing).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free