Home / File/ ssr-dynamic.test.js — astro Source File

ssr-dynamic.test.js — astro Source File

Architecture documentation for ssr-dynamic.test.js, a javascript file in the astro codebase. 9 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  203d2ae6_cf56_8a1c_ce77_3926f3d01949["ssr-dynamic.test.js"]
  be670a78_841c_46e5_0af5_c5c328869ecb["test-adapter.js"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> be670a78_841c_46e5_0af5_c5c328869ecb
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  e16a223b_37f3_6b25_1ee1_2b7bcb9d9415["node:fs"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> e16a223b_37f3_6b25_1ee1_2b7bcb9d9415
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> d9a92db9_c95e_9165_13ac_24b3d859d946
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  203d2ae6_cf56_8a1c_ce77_3926f3d01949 --> deb87372_5629_35f8_9a54_e755a08f776a
  style 203d2ae6_cf56_8a1c_ce77_3926f3d01949 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { mkdirSync, writeFileSync } from 'node:fs';
import { dirname } from 'node:path';
import { before, describe, it } from 'node:test';
import { fileURLToPath } from 'node:url';
import { load as cheerioLoad } from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';

describe('Dynamic pages in SSR', () => {
	/** @type {import('./test-utils').Fixture} */
	let fixture;

	before(async () => {
		const root = './fixtures/ssr-dynamic/';
		fixture = await loadFixture({
			root,
			output: 'server',
			integrations: [
				{
					name: 'inject-routes',
					hooks: {
						'astro:config:setup': ({ injectRoute }) => {
							injectRoute({
								pattern: '/path-alias/[id]',
								entrypoint: './src/pages/api/products/[id].js',
							});

							const entrypoint = fileURLToPath(
								new URL(`${root}.astro/test.astro`, import.meta.url),
							);
							mkdirSync(dirname(entrypoint), { recursive: true });
							writeFileSync(entrypoint, '<h1>Index</h1>');

							injectRoute({
								pattern: '/test',
								entrypoint,
							});
						},
					},
				},
			],
			adapter: testAdapter(),
			// test suite was authored when inlineStylesheets defaulted to never
			build: { inlineStylesheets: 'never' },
		});
		await fixture.build();
	});

	async function matchRoute(path) {
		const app = await fixture.loadTestAdapterApp();
		const request = new Request('https://example.com' + path);
		return app.match(request);
	}

	async function fetchHTML(path) {
		const app = await fixture.loadTestAdapterApp();
		const request = new Request('http://example.com' + path);
		const response = await app.render(request);
		const html = await response.text();
		return html;
	}

	async function fetchJSON(path) {
		const app = await fixture.loadTestAdapterApp();
		const request = new Request('http://example.com' + path);
		const response = await app.render(request);
		const json = await response.json();
		return json;
	}

	it('Do not have to implement getStaticPaths', async () => {
		const html = await fetchHTML('/123');
		const $ = cheerioLoad(html);
		assert.equal($('h1').text(), 'Item 123');
	});

	it('Includes page styles', async () => {
		const html = await fetchHTML('/123');
		const $ = cheerioLoad(html);
		assert.equal($('link').length, 1);
	});

	it('Dynamic API routes work', async () => {
		const json = await fetchJSON('/api/products/33');
		assert.equal(json.id, '33');
	});

	it('Injected route work', async () => {
		const json = await fetchJSON('/path-alias/33');
		assert.equal(json.id, '33');
	});

	it('Public assets take priority', async () => {
		const favicon = await matchRoute('/favicon.ico');
		assert.equal(favicon, undefined);
	});

	it('injectRoute entrypoint should not fail build if containing the extension several times in the path', async () => {
		const html = await fetchHTML('/test');
		const $ = cheerioLoad(html);
		assert.equal($('h1').text(), 'Index');
	});
});

Dependencies

Frequently Asked Questions

What does ssr-dynamic.test.js do?
ssr-dynamic.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does ssr-dynamic.test.js depend on?
ssr-dynamic.test.js imports 9 module(s): cheerio, loadFixture, node:fs, node:path, node:test, node:url, strict, test-adapter.js, and 1 more.
Where is ssr-dynamic.test.js in the architecture?
ssr-dynamic.test.js is located at packages/astro/test/ssr-dynamic.test.js (domain: IntegrationAdapters, directory: packages/astro/test).

Analyze Your Own Codebase

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

Try Supermodel Free