Home / File/ redirects.test.js — astro Source File

redirects.test.js — astro Source File

Architecture documentation for redirects.test.js, a javascript file in the astro codebase. 5 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  e49f2b51_a3c0_aa5a_e1d5_88ed3cf43e7d["redirects.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  e49f2b51_a3c0_aa5a_e1d5_88ed3cf43e7d --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  e49f2b51_a3c0_aa5a_e1d5_88ed3cf43e7d --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  e49f2b51_a3c0_aa5a_e1d5_88ed3cf43e7d --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  c2f6615e_96e9_c4eb_5f71_cf120e271705["node:http"]
  e49f2b51_a3c0_aa5a_e1d5_88ed3cf43e7d --> c2f6615e_96e9_c4eb_5f71_cf120e271705
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  e49f2b51_a3c0_aa5a_e1d5_88ed3cf43e7d --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style e49f2b51_a3c0_aa5a_e1d5_88ed3cf43e7d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import * as assert from 'node:assert/strict';
import { createServer } from 'node:http';
import { before, describe, it } from 'node:test';
import { loadFixture } from '../../../../astro/test/test-utils.js';

describe(
	'SSR - Redirects',
	() => {
		let fixture;

		before(async () => {
			fixture = await loadFixture({ root: new URL('./fixtures/redirects/', import.meta.url) });
			await fixture.build();
		});

		it('Creates a redirects file', async () => {
			const redirects = await fixture.readFile('./_redirects');
			const parts = redirects.split(/\s+/);
			assert.deepEqual(parts, ['', '/other', '/', '301', '']);
			// Snapshots are not supported in Node.js test yet (https://github.com/nodejs/node/issues/48260)
			assert.equal(redirects, '\n/other    /       301\n');
		});

		it('Does not create .html files', async () => {
			let hasErrored = false;
			try {
				await fixture.readFile('/other/index.html');
			} catch {
				hasErrored = true;
			}
			assert.equal(hasErrored, true, 'this file should not exist');
		});

		it('renders static 404 page', async () => {
			const entryURL = new URL(
				'./fixtures/redirects/.netlify/v1/functions/ssr/ssr.mjs',
				import.meta.url,
			);
			const { default: handler } = await import(entryURL);
			const resp = await handler(new Request('http://example.com/nonexistant-page'), {});
			assert.equal(resp.status, 404);
			assert.equal(resp.headers.get('content-type'), 'text/html; charset=utf-8');
			const text = await resp.text();
			assert.equal(text.includes('This is my static 404 page'), true);
		});

		it('does not pass through 404 request', async () => {
			let testServerCalls = 0;
			const testServer = createServer((_req, res) => {
				testServerCalls++;
				res.writeHead(200);
				res.end();
			});
			testServer.listen(5678);
			const entryURL = new URL(
				'./fixtures/redirects/.netlify/v1/functions/ssr/ssr.mjs',
				import.meta.url,
			);
			const { default: handler } = await import(entryURL);
			const resp = await handler(new Request('http://localhost:5678/nonexistant-page'), {});
			assert.equal(resp.status, 404);
			assert.equal(testServerCalls, 0);
			testServer.close();
		});
	},
	{
		timeout: 120000,
	},
);

Domain

Dependencies

Frequently Asked Questions

What does redirects.test.js do?
redirects.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does redirects.test.js depend on?
redirects.test.js imports 5 module(s): loadFixture, node:http, node:test, strict, test-utils.js.
Where is redirects.test.js in the architecture?
redirects.test.js is located at packages/integrations/netlify/test/functions/redirects.test.js (domain: CoreAstro, directory: packages/integrations/netlify/test/functions).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free