Home / File/ route-guard.test.js — astro Source File

route-guard.test.js — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  68745d88_8786_f7b2_6d18_c01663d2d25e["route-guard.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  68745d88_8786_f7b2_6d18_c01663d2d25e --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  68745d88_8786_f7b2_6d18_c01663d2d25e --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  68745d88_8786_f7b2_6d18_c01663d2d25e --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  68745d88_8786_f7b2_6d18_c01663d2d25e --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style 68745d88_8786_f7b2_6d18_c01663d2d25e 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('Route Guard - Dev Server', () => {
	/** @type {import('./test-utils').Fixture} */
	let fixture;
	/** @type {import('./test-utils').DevServer} */
	let devServer;

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

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

	describe('Files at project root should return 404 for browser requests', () => {
		// Browser navigation sends Accept: text/html - these should be blocked
		const browserHeaders = { headers: { Accept: 'text/html' } };

		it('404 when loading /README.md (file exists at project root)', async () => {
			const response = await fixture.fetch('/README.md', browserHeaders);
			assert.equal(response.status, 404);
		});

		it('404 when loading /LICENSE (file exists at project root)', async () => {
			const response = await fixture.fetch('/LICENSE', browserHeaders);
			assert.equal(response.status, 404);
		});

		it('404 when loading /config.json (file exists at project root)', async () => {
			const response = await fixture.fetch('/config.json', browserHeaders);
			assert.equal(response.status, 404);
		});

		it('404 when loading /package.json (file exists at project root)', async () => {
			const response = await fixture.fetch('/package.json', browserHeaders);
			assert.equal(response.status, 404);
		});
	});

	describe('Valid routes should work', () => {
		it('200 when loading / (index page)', async () => {
			const response = await fixture.fetch('/');
			assert.equal(response.status, 200);
		});

		it('200 when loading /about (markdown page in src/pages)', async () => {
			const response = await fixture.fetch('/about');
			assert.equal(response.status, 200);
		});
	});

	describe('Public directory files should be served', () => {
		it('200 when loading /robots.txt (file in public directory)', async () => {
			const response = await fixture.fetch('/robots.txt');
			assert.equal(response.status, 200);
			const text = await response.text();
			assert.match(text, /User-agent/);
		});
	});

	describe('Non-existent files should 404 normally', () => {
		it('404 when loading /nonexistent.md (file does not exist)', async () => {
			const response = await fixture.fetch('/nonexistent.md');
			assert.equal(response.status, 404);
		});

		it('404 when loading /does-not-exist (no file, no route)', async () => {
			const response = await fixture.fetch('/does-not-exist');
			assert.equal(response.status, 404);
		});
	});

	describe('Vite internal paths should still work', () => {
		it('allows /@vite/ prefixed requests', async () => {
			// This tests that we don't block Vite internals
			// The actual response may vary, but it shouldn't be our custom 404
			const response = await fixture.fetch('/@vite/client');
			// Vite client should return 200 or handle it appropriately
			assert.notEqual(response.status, 404);
		});
	});
});

Dependencies

Frequently Asked Questions

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