Home / File/ astro-component-bundling.test.js — astro Source File

astro-component-bundling.test.js — astro Source File

Architecture documentation for astro-component-bundling.test.js, a javascript file in the astro codebase. 4 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  1766ead5_662c_1e4a_da0e_ec55d2fc8c5e["astro-component-bundling.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  1766ead5_662c_1e4a_da0e_ec55d2fc8c5e --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  1766ead5_662c_1e4a_da0e_ec55d2fc8c5e --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  1766ead5_662c_1e4a_da0e_ec55d2fc8c5e --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  1766ead5_662c_1e4a_da0e_ec55d2fc8c5e --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style 1766ead5_662c_1e4a_da0e_ec55d2fc8c5e 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 { loadFixture } from './test-utils.js';

describe('Component bundling', () => {
	/** @type {import('./test-utils.js').Fixture} */
	let fixture;

	before(async () => {
		fixture = await loadFixture({ root: './fixtures/astro-component-bundling/' });
	});

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

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

		after(async () => {
			await devServer.stop();
		});

		it('should not include Astro components in client bundles', async () => {
			const importedComponent = await fixture.fetch('/src/components/AstroComponent.astro');
			const moduleContent = await importedComponent.text();
			assert(
				moduleContent.includes('Astro components cannot be used in the browser.'),
				'Astro component imported from client should include error text in dev.',
			);
			assert(
				moduleContent.length < 3500,
				'Module content should be small and not include full server-side code.',
			);
			assert(
				!moduleContent.includes('import '),
				'Astro component imported from client should not include import statements.',
			);
		});
	});

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

		it(
			'should treeshake FooComponent',
			{ skip: 'Not sure how this can possibly work, we bundle the module as an entrypoint.' },
			async () => {
				const astroChunkDir = await fixture.readdir('/_astro');
				const manyComponentsChunkName = astroChunkDir.find((chunk) =>
					chunk.startsWith('ManyComponents'),
				);
				const manyComponentsChunkContent = await fixture.readFile(
					`/_astro/${manyComponentsChunkName}`,
				);
				assert.equal(manyComponentsChunkContent.includes('FooComponent'), false);
			},
		);

		it('should not include Astro components in client bundles', async () => {
			const html = await fixture.readFile('/astro-in-client/index.html');
			const match = /<script.+<\/script>/.exec(html);
			assert(match, 'Expected a <script> tag to be present');
			assert.match(
				match[0],
				/^<script type="module">const \w=\{\};console.log\(\w\);<\/script>$/,
				'Astro component on the client should be an empty object in prod',
			);
		});
	});
});

Dependencies

Frequently Asked Questions

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