Home / File/ astro-public.test.js — astro Source File

astro-public.test.js — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  1663adb1_bab0_970f_683b_4fd82df3d196["astro-public.test.js"]
  f5b154b4_7bf2_7c8f_2105_5c84d2420bd1["../../dist/core/logger/core.js"]
  1663adb1_bab0_970f_683b_4fd82df3d196 --> f5b154b4_7bf2_7c8f_2105_5c84d2420bd1
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  1663adb1_bab0_970f_683b_4fd82df3d196 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  1663adb1_bab0_970f_683b_4fd82df3d196 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  1663adb1_bab0_970f_683b_4fd82df3d196 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  8f34f3e8_2f0f_1f0d_91dc_c25ece8c8169["node:stream"]
  1663adb1_bab0_970f_683b_4fd82df3d196 --> 8f34f3e8_2f0f_1f0d_91dc_c25ece8c8169
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  1663adb1_bab0_970f_683b_4fd82df3d196 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style 1663adb1_bab0_970f_683b_4fd82df3d196 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { Writable } from 'node:stream';
import { after, before, describe, it } from 'node:test';
import { Logger } from '../dist/core/logger/core.js';
import { loadFixture } from './test-utils.js';

describe('Public', () => {
	let fixture;
	let buildLogs = [];

	before(async () => {
		fixture = await loadFixture({ root: './fixtures/astro-public/' });
		await fixture.build({
			vite: {
				logLevel: 'info',
			},
			logger: new Logger({
				level: 'info',
				dest: new Writable({
					objectMode: true,
					write(event, _, callback) {
						buildLogs.push(event);
						callback();
					},
				}),
			}),
		});
	});

	it('css and js files do not get bundled', async () => {
		let indexHtml = await fixture.readFile('/index.html');
		assert.equal(indexHtml.includes('<script src="/example.js"></script>'), true);
		assert.equal(indexHtml.includes('<link href="/example.css" rel="stylesheet">'), true);
		assert.equal(indexHtml.includes('<img src="/images/twitter.png">'), true);
	});

	it('should not produce empty chunk warning when building with no client JS', () => {
		// Check for empty chunk warnings in the build logs
		const emptyChunkWarning = buildLogs.find(
			(log) =>
				log.message &&
				(log.message.includes('empty chunk') ||
					(log.message.includes('empty') && log.message.includes('chunk'))),
		);

		if (emptyChunkWarning) {
			assert.fail(`Should not have empty chunk warning, but got: ${emptyChunkWarning.message}`);
		}
	});

	it('public file takes priority over API route in build', async () => {
		// When both public/robots.txt and src/pages/robots.txt.ts exist,
		// the public file should take priority
		const robotsTxt = await fixture.readFile('/robots.txt');
		assert.match(robotsTxt, /Disallow: \/admin\//, 'Should contain public file content');
		assert.doesNotMatch(robotsTxt, /Disallow: \/\n/, 'Should not contain API route content');
	});
});

describe('Public (dev)', () => {
	let fixture;
	let devServer;

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

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

	it('public file takes priority over API route in dev', async () => {
		// When both public/robots.txt and src/pages/robots.txt.ts exist,
		// the public file should take priority
		const response = await fixture.fetch('/robots.txt');
		assert.equal(response.status, 200);
		const text = await response.text();
		assert.match(text, /Disallow: \/admin\//, 'Should contain public file content');
		assert.doesNotMatch(text, /Disallow: \/\n/, 'Should not contain API route content');
	});
});

Dependencies

Frequently Asked Questions

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