Home / File/ csp-server-islands.test.js — astro Source File

csp-server-islands.test.js — astro Source File

Architecture documentation for csp-server-islands.test.js, a javascript file in the astro codebase. 7 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  f70a7047_7ccc_b7ad_81e5_76bae835b053["csp-server-islands.test.js"]
  82dbf6c0_3ed5_6a79_7a8f_0df388c37f87["../dist/core/encryption.js"]
  f70a7047_7ccc_b7ad_81e5_76bae835b053 --> 82dbf6c0_3ed5_6a79_7a8f_0df388c37f87
  be670a78_841c_46e5_0af5_c5c328869ecb["test-adapter.js"]
  f70a7047_7ccc_b7ad_81e5_76bae835b053 --> be670a78_841c_46e5_0af5_c5c328869ecb
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  f70a7047_7ccc_b7ad_81e5_76bae835b053 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  f70a7047_7ccc_b7ad_81e5_76bae835b053 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  f70a7047_7ccc_b7ad_81e5_76bae835b053 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  f70a7047_7ccc_b7ad_81e5_76bae835b053 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  f70a7047_7ccc_b7ad_81e5_76bae835b053 --> deb87372_5629_35f8_9a54_e755a08f776a
  style f70a7047_7ccc_b7ad_81e5_76bae835b053 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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

// Helper to create encryption key from test key string
async function createKeyFromString(keyString) {
	const binaryString = atob(keyString);
	const bytes = new Uint8Array(binaryString.length);
	for (let i = 0; i < binaryString.length; i++) {
		bytes[i] = binaryString.charCodeAt(i);
	}
	return await crypto.subtle.importKey('raw', bytes, { name: 'AES-GCM' }, false, [
		'encrypt',
		'decrypt',
	]);
}

// Helper to get encrypted componentExport for 'default'
async function getEncryptedComponentExport(
	keyString = 'eKBaVEuI7YjfanEXHuJe/pwZKKt3LkAHeMxvTU7aR0M=',
) {
	const key = await createKeyFromString(keyString);
	return encryptString(key, 'default');
}

describe('Server islands', () => {
	describe('SSR', () => {
		/** @type {import('./test-utils').Fixture} */
		let fixture;
		before(async () => {
			fixture = await loadFixture({
				root: './fixtures/server-islands/ssr',
				adapter: testAdapter(),
				security: {
					csp: true,
				},
			});
			process.env.ASTRO_KEY = 'eKBaVEuI7YjfanEXHuJe/pwZKKt3LkAHeMxvTU7aR0M=';
			await fixture.build();
		});

		after(async () => {
			delete process.env.ASTRO_KEY;
		});

		it('omits the islands HTML', async () => {
			const app = await fixture.loadTestAdapterApp();
			const request = new Request('http://example.com/');
			const response = await app.render(request);
			const html = await response.text();

			const $ = cheerio.load(html);
			const serverIslandEl = $('h2#island');
			assert.equal(serverIslandEl.length, 0);

			const serverIslandScript = $('script[data-island-id]');
			assert.equal(serverIslandScript.length, 1, 'has the island script');
// ... (152 more lines)

Subdomains

Dependencies

Frequently Asked Questions

What does csp-server-islands.test.js do?
csp-server-islands.test.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 csp-server-islands.test.js?
csp-server-islands.test.js defines 2 function(s): createKeyFromString, getEncryptedComponentExport.
What does csp-server-islands.test.js depend on?
csp-server-islands.test.js imports 7 module(s): ../dist/core/encryption.js, cheerio, loadFixture, node:test, strict, test-adapter.js, test-utils.js.
Where is csp-server-islands.test.js in the architecture?
csp-server-islands.test.js is located at packages/astro/test/csp-server-islands.test.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