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

ssr-locals.test.js — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  b7a83e2e_bfcc_a098_696f_f0cb034f0fdf["ssr-locals.test.js"]
  be670a78_841c_46e5_0af5_c5c328869ecb["test-adapter.js"]
  b7a83e2e_bfcc_a098_696f_f0cb034f0fdf --> be670a78_841c_46e5_0af5_c5c328869ecb
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  b7a83e2e_bfcc_a098_696f_f0cb034f0fdf --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  b7a83e2e_bfcc_a098_696f_f0cb034f0fdf --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  b7a83e2e_bfcc_a098_696f_f0cb034f0fdf --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  b7a83e2e_bfcc_a098_696f_f0cb034f0fdf --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  b7a83e2e_bfcc_a098_696f_f0cb034f0fdf --> deb87372_5629_35f8_9a54_e755a08f776a
  style b7a83e2e_bfcc_a098_696f_f0cb034f0fdf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import * as cheerio from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';

describe('SSR Astro.locals from server', () => {
	/** @type {import('./test-utils').Fixture} */
	let fixture;
	/** @type {import('./test-utils.js').App} */
	let app;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/ssr-locals/',
			output: 'server',
			adapter: testAdapter(),
		});
		await fixture.build();
		app = await fixture.loadTestAdapterApp();
	});

	it('Can access Astro.locals in page', async () => {
		const request = new Request('http://example.com/foo');
		const locals = { foo: 'bar' };
		const response = await app.render(request, { locals });
		const html = await response.text();

		const $ = cheerio.load(html);
		assert.equal($('#foo').text(), 'bar');
	});

	it('Can access Astro.locals in api context', async () => {
		const request = new Request('http://example.com/api');
		const locals = { foo: 'bar' };
		const response = await app.render(request, { routeData: undefined, locals });
		assert.equal(response.status, 200);
		const body = await response.json();

		assert.equal(body.foo, 'bar');
	});

	it('404.astro can access locals provided to app.render()', async () => {
		const request = new Request('http://example.com/slkfnasf');
		const locals = { foo: 'par' };
		const response = await app.render(request, { locals });
		assert.equal(response.status, 404);

		const html = await response.text();
		const $ = cheerio.load(html);
		assert.equal($('#foo').text(), 'par');
	});

	it('500.astro can access locals provided to app.render()', async () => {
		const request = new Request('http://example.com/go-to-error-page');
		const locals = { foo: 'par' };
		const response = await app.render(request, { locals });
		assert.equal(response.status, 500);

		const html = await response.text();
		const $ = cheerio.load(html);
		assert.equal($('#foo').text(), 'par');
	});
});

Dependencies

Frequently Asked Questions

What does ssr-locals.test.js do?
ssr-locals.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain.
What does ssr-locals.test.js depend on?
ssr-locals.test.js imports 6 module(s): cheerio, loadFixture, node:test, strict, test-adapter.js, test-utils.js.
Where is ssr-locals.test.js in the architecture?
ssr-locals.test.js is located at packages/astro/test/ssr-locals.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