Home / File/ test-prerenderer.js — astro Source File

test-prerenderer.js — astro Source File

Architecture documentation for test-prerenderer.js, a javascript file in the astro codebase. 0 imports, 1 dependents.

File javascript IntegrationAdapters SsrAdapters 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  68407ce2_f297_0f69_e923_be3697615739["test-prerenderer.js"]
  f0972392_bca0_3141_69a5_4dfb80812919["astro-basic.test.js"]
  f0972392_bca0_3141_69a5_4dfb80812919 --> 68407ce2_f297_0f69_e923_be3697615739
  style 68407ce2_f297_0f69_e923_be3697615739 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * @typedef {import('../src/types/public/integrations.js').AstroIntegration} AstroIntegration
 * @typedef {import('../src/types/public/integrations.js').AstroPrerenderer} AstroPrerenderer
 * @typedef {import('../src/types/public/integrations.js').PathWithRoute} PathWithRoute
 * @typedef {import('../src/types/public/internal.js').RouteData} RouteData
 */

/**
 * Creates a test integration that sets a custom prerenderer.
 * The prerenderer tracks calls made to it for testing purposes.
 *
 * @param {{
 *   onSetup?: () => void;
 *   onGetStaticPaths?: () => void;
 *   onRender?: (request: Request, routeData: RouteData) => void;
 *   onTeardown?: () => void;
 * }} [callbacks]
 * @returns {{
 *   integration: AstroIntegration;
 *   calls: { setup: number; getStaticPaths: number; render: number; teardown: number };
 *   renderedPaths: string[];
 * }}
 */
export default function createTestPrerenderer(callbacks = {}) {
	const calls = {
		setup: 0,
		getStaticPaths: 0,
		render: 0,
		teardown: 0,
	};

	const renderedPaths = [];

	const integration = {
		name: 'test-prerenderer-integration',
		hooks: {
			'astro:build:start': ({ setPrerenderer }) => {
				// Use factory function to receive the default prerenderer
				setPrerenderer((defaultPrerenderer) => ({
					name: 'test-prerenderer',

					async setup() {
						calls.setup++;
						callbacks.onSetup?.();
						// Delegate to the default prerenderer's setup
						if (defaultPrerenderer?.setup) {
							await defaultPrerenderer.setup();
						}
					},

					async getStaticPaths() {
						calls.getStaticPaths++;
						callbacks.onGetStaticPaths?.();
						// Delegate to the default prerenderer
						return defaultPrerenderer.getStaticPaths();
					},

					async render(request, { routeData }) {
						calls.render++;
						const url = new URL(request.url);
						renderedPaths.push(url.pathname);
						callbacks.onRender?.(request, routeData);
						// Delegate to the default prerenderer
						return defaultPrerenderer.render(request, { routeData });
					},

					async teardown() {
						calls.teardown++;
						callbacks.onTeardown?.();
						// Delegate to the default prerenderer's teardown
						if (defaultPrerenderer?.teardown) {
							await defaultPrerenderer.teardown();
						}
					},
				}));
			},
		},
	};

	return {
		integration,
		calls,
		renderedPaths,
	};
}

Subdomains

Frequently Asked Questions

What does test-prerenderer.js do?
test-prerenderer.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain, SsrAdapters subdomain.
What functions are defined in test-prerenderer.js?
test-prerenderer.js defines 1 function(s): createTestPrerenderer.
What files import test-prerenderer.js?
test-prerenderer.js is imported by 1 file(s): astro-basic.test.js.
Where is test-prerenderer.js in the architecture?
test-prerenderer.js is located at packages/astro/test/test-prerenderer.js (domain: IntegrationAdapters, subdomain: SsrAdapters, directory: packages/astro/test).

Analyze Your Own Codebase

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

Try Supermodel Free