Home / File/ minification-html.test.js — astro Source File

minification-html.test.js — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  02ba1230_16ee_390f_df0f_6e34c6d74e3f["minification-html.test.js"]
  be670a78_841c_46e5_0af5_c5c328869ecb["test-adapter.js"]
  02ba1230_16ee_390f_df0f_6e34c6d74e3f --> be670a78_841c_46e5_0af5_c5c328869ecb
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  02ba1230_16ee_390f_df0f_6e34c6d74e3f --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  02ba1230_16ee_390f_df0f_6e34c6d74e3f --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  02ba1230_16ee_390f_df0f_6e34c6d74e3f --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  02ba1230_16ee_390f_df0f_6e34c6d74e3f --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style 02ba1230_16ee_390f_df0f_6e34c6d74e3f 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 testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';

const NEW_LINES = /[\r\n]+/g;

/**
 * The doctype declaration is on a line between the rest of the HTML in SSG.
 * This function removes the doctype so that we can check if the rest of the HTML is without
 * whitespace.
 */
function removeDoctypeLine(html) {
	return html.slice(20);
}

/**
 * In the dev environment, two more script tags will be injected than in the production environment
 * so that we can check if the rest of the HTML is without whitespace
 */
function removeDoctypeLineInDev(html) {
	return html.slice(-100);
}

describe('HTML minification', () => {
	describe('in DEV environment', () => {
		let fixture;
		let devServer;
		before(async () => {
			fixture = await loadFixture({
				root: './fixtures/minification-html/',
			});
			devServer = await fixture.startDevServer();
		});

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

		it('should emit compressed HTML in the emitted file', async () => {
			let res = await fixture.fetch('/');
			assert.equal(res.status, 200);
			const html = await res.text();
			assert.equal(NEW_LINES.test(removeDoctypeLineInDev(html)), false);
		});
	});

	describe('Build SSG', () => {
		let fixture;
		before(async () => {
			fixture = await loadFixture({
				root: './fixtures/minification-html/',
				// test suite was authored when inlineStylesheets defaulted to never
				build: { inlineStylesheets: 'never' },
			});
			await fixture.build();
		});

		it('should emit compressed HTML in the emitted file', async () => {
			const html = await fixture.readFile('/index.html');
			assert.equal(NEW_LINES.test(html), false);
		});
	});

	describe('Build SSR', () => {
		let fixture;
		before(async () => {
			fixture = await loadFixture({
				root: './fixtures/minification-html/',
				output: 'server',
				adapter: testAdapter(),
				// test suite was authored when inlineStylesheets defaulted to never
				build: { inlineStylesheets: 'never' },
			});
			await fixture.build();
		});

		it('should emit compressed HTML in the emitted file', async () => {
			const app = await fixture.loadTestAdapterApp();
			const request = new Request('http://example.com/');
			const response = await app.render(request);
			const html = await response.text();
			assert.equal(NEW_LINES.test(removeDoctypeLine(html)), false);
		});
	});
});

Subdomains

Dependencies

Frequently Asked Questions

What does minification-html.test.js do?
minification-html.test.js is a source file in the astro codebase, written in javascript. It belongs to the IntegrationAdapters domain, SsrAdapters subdomain.
What functions are defined in minification-html.test.js?
minification-html.test.js defines 2 function(s): removeDoctypeLine, removeDoctypeLineInDev.
What does minification-html.test.js depend on?
minification-html.test.js imports 5 module(s): loadFixture, node:test, strict, test-adapter.js, test-utils.js.
Where is minification-html.test.js in the architecture?
minification-html.test.js is located at packages/astro/test/minification-html.test.js (domain: IntegrationAdapters, subdomain: SsrAdapters, directory: packages/astro/test).

Analyze Your Own Codebase

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

Try Supermodel Free