Home / File/ core-image-svg-in-island.test.js — astro Source File

core-image-svg-in-island.test.js — astro Source File

Architecture documentation for core-image-svg-in-island.test.js, a javascript file in the astro codebase. 5 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  ba0d5eb1_c5ce_f9b2_b502_8ff787618d54["core-image-svg-in-island.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  ba0d5eb1_c5ce_f9b2_b502_8ff787618d54 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  ba0d5eb1_c5ce_f9b2_b502_8ff787618d54 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  ba0d5eb1_c5ce_f9b2_b502_8ff787618d54 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  ba0d5eb1_c5ce_f9b2_b502_8ff787618d54 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  ba0d5eb1_c5ce_f9b2_b502_8ff787618d54 --> deb87372_5629_35f8_9a54_e755a08f776a
  style ba0d5eb1_c5ce_f9b2_b502_8ff787618d54 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 { loadFixture } from './test-utils.js';

describe('astro:assets - SVG Components in Astro Islands', async () => {
	/** @type {import('./test-utils.js').Fixture} */
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/core-image-svg-in-island/',
		});
	});

	describe('dev', () => {
		/** @type {import('./test-utils.js').DevServer} */
		let devServer;

		before(async () => {
			devServer = await fixture.startDevServer();
		});

		after(() => devServer.stop());

		it('SVG metadata imported in React island is small', async () => {
			const html = await fixture.fetch('/').then((res) => res.text());
			const $ = cheerio.load(html, { xml: true });
			const island = $('astro-island');
			const componentUrl = island.attr('component-url');
			assert.ok(componentUrl, 'Expected component-url attribute to be present on astro-island.');
			const componentModule = await fixture.fetch(componentUrl).then((res) => res.text());
			const imports = componentModule
				.split('\n')
				.map((line) => line.trim())
				.filter((line) => line.startsWith('import '));
			const svgImportStatement = imports.find((imp) => imp.includes('src/components/astro.svg'));
			assert.ok(svgImportStatement, 'Expected SVG to be imported in the component.');
			const importPath = svgImportStatement.split('from')[1].trim().replace(/['";]/g, '');
			const mod = await fixture.fetch(importPath).then((res) => res.text());
			assert.ok(
				mod.length < 1_500,
				`Expected SVG module to be smaller than 1500 bytes, got ${mod.length} bytes. If this test fails, it is likely that server code has been imported while importing an SVG.`,
			);
			assert.ok(
				!mod.includes('import'),
				'Expected client-side SVG not to include import statements.',
			);
		});
	});

	describe('build', () => {
		before(() => fixture.build({}));

		after(() => fixture.clean());

		it('React bundle size is small when importing an SVG', async () => {
			const files = await fixture.readdir('_astro');
			const bundledReactComponentFilename = files.find(
				(f) => f.startsWith('ReactTest.') && f.endsWith('.js'),
			);
			assert.ok(bundledReactComponentFilename, 'Expected to find React component in build output.');
			const bundledReactComponent = await fixture.readFile(
				`_astro/${bundledReactComponentFilename}`,
			);
			assert.ok(bundledReactComponent, 'Expected React component bundle not to be empty');
			assert.ok(
				bundledReactComponent.length < 1_000,
				`Expected React component bundle to be smaller than 1000 bytes, got ${bundledReactComponent.length} bytes. If this test fails, it is likely that server code has been imported while importing an SVG.`,
			);
		});
	});
});

Dependencies

Frequently Asked Questions

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