Home / File/ error-page-host.test.js — astro Source File

error-page-host.test.js — astro Source File

Architecture documentation for error-page-host.test.js, a javascript file in the astro codebase. 6 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  c7c1034b_9f55_0f9a_eeb6_33dd8764f56f["error-page-host.test.js"]
  760b1776_8858_e3bd_06b8_5cc4c1a9cbdc["../dist/index.js"]
  c7c1034b_9f55_0f9a_eeb6_33dd8764f56f --> 760b1776_8858_e3bd_06b8_5cc4c1a9cbdc
  ff334e41_2760_839e_fc38_ab9318c18dfc["test-utils.js"]
  c7c1034b_9f55_0f9a_eeb6_33dd8764f56f --> ff334e41_2760_839e_fc38_ab9318c18dfc
  0b7a6b11_e910_da4b_c617_1880167f44ef["loadFixture"]
  c7c1034b_9f55_0f9a_eeb6_33dd8764f56f --> 0b7a6b11_e910_da4b_c617_1880167f44ef
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  c7c1034b_9f55_0f9a_eeb6_33dd8764f56f --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  c2f6615e_96e9_c4eb_5f71_cf120e271705["node:http"]
  c7c1034b_9f55_0f9a_eeb6_33dd8764f56f --> c2f6615e_96e9_c4eb_5f71_cf120e271705
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  c7c1034b_9f55_0f9a_eeb6_33dd8764f56f --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style c7c1034b_9f55_0f9a_eeb6_33dd8764f56f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import * as assert from 'node:assert/strict';
import { createServer } from 'node:http';
import { after, before, describe, it } from 'node:test';
import nodejs from '../dist/index.js';
import { loadFixture } from './test-utils.js';

describe('Prerendered error page host', () => {
	/** @type {import('./test-utils').Fixture} */
	let fixture;
	let devPreview;
	/** @type {import('node:http').Server} */
	let errorPageServer;
	let errorPageRequests = [];

	before(async () => {
		// Start local server to serve error pages
		// This isn't something that would happen in production, but allows us to
		// see if Astro is correctly requesting the prerendered error pages
		errorPageServer = createServer((req, res) => {
			errorPageRequests.push(req.url);

			if (req.url === '/404.html') {
				res.writeHead(200, { 'Content-Type': 'text/html' });
				res.end('<html><body><h1>Custom 404 Page</h1></body></html>');
			} else if (req.url === '/500.html') {
				res.writeHead(200, { 'Content-Type': 'text/html' });
				res.end('<html><body><h1>Custom 500 Page</h1></body></html>');
			} else {
				res.writeHead(404);
				res.end('Not found');
			}
		});

		await new Promise((resolve) => {
			errorPageServer.listen(3030, resolve);
		});

		fixture = await loadFixture({
			root: './fixtures/prerender-error-page/',
			adapter: nodejs({ mode: 'standalone', experimentalErrorPageHost: 'http://localhost:3030' }),
		});
		await fixture.build();
		devPreview = await fixture.preview();
	});

	after(async () => {
		await devPreview.stop();
		if (errorPageServer) {
			await new Promise((resolve) => {
				errorPageServer.close(resolve);
			});
		}
	});

	it('requests prerendered 404 page from the configured host', async () => {
		errorPageRequests = [];

		const response = await fixture.fetch('/nonexistent');
		assert.ok(
			errorPageRequests.includes('/404.html'),
			'Error page host should receive request for 404.html',
		);

		const text = await response.text();
		assert.ok(text.includes('Custom 404 Page'), 'Should serve error page content from host');
	});
	it('requests prerendered 500 page from the configured host', async () => {
		// Clear any previous requests
		errorPageRequests = [];

		const response = await fixture.fetch('/error?error=true');
		assert.ok(
			errorPageRequests.includes('/500.html'),
			'Error page host should receive request for 500.html',
		);

		const text = await response.text();
		assert.ok(text.includes('Custom 500 Page'), 'Should serve error page content from host');
	});

	it('throws if experimentalErrorPageHost is not a valid URL', async () => {
		await assert.rejects(
			async () =>
				loadFixture({
					root: './fixtures/prerender-error-page/',
					adapter: nodejs({ mode: 'standalone', experimentalErrorPageHost: 'invalid-url' }),
				}),
			{
				name: 'AstroUserError',
				message: /Invalid experimentalErrorPageHost/,
			},
		);

		await assert.rejects(
			async () =>
				loadFixture({
					root: './fixtures/prerender-error-page/',
					adapter: nodejs({ mode: 'standalone', experimentalErrorPageHost: 'file:///invalid-url' }),
				}),
			{
				name: 'AstroUserError',
				message: /Invalid experimentalErrorPageHost/,
			},
		);
	});
});

Domain

Dependencies

Frequently Asked Questions

What does error-page-host.test.js do?
error-page-host.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does error-page-host.test.js depend on?
error-page-host.test.js imports 6 module(s): ../dist/index.js, loadFixture, node:http, node:test, strict, test-utils.js.
Where is error-page-host.test.js in the architecture?
error-page-host.test.js is located at packages/integrations/node/test/error-page-host.test.js (domain: CoreAstro, directory: packages/integrations/node/test).

Analyze Your Own Codebase

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

Try Supermodel Free