Home / File/ image-assets.test.js — astro Source File

image-assets.test.js — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  6af7f9d3_023a_599d_7704_d2576c45fbca["image-assets.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  6af7f9d3_023a_599d_7704_d2576c45fbca --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  6af7f9d3_023a_599d_7704_d2576c45fbca --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  6af7f9d3_023a_599d_7704_d2576c45fbca --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  6af7f9d3_023a_599d_7704_d2576c45fbca --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  cb315bcc_59d8_fa19_79aa_5da7cd3730c5["linkedom"]
  6af7f9d3_023a_599d_7704_d2576c45fbca --> cb315bcc_59d8_fa19_79aa_5da7cd3730c5
  style 6af7f9d3_023a_599d_7704_d2576c45fbca 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 { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';

const imageAssetsFixture = new URL('./fixtures/image-assets/', import.meta.url);
const imageAssetsCustomFixture = new URL('./fixtures/image-assets-custom/', import.meta.url);

describe('Markdoc - Image assets', () => {
	const configurations = [
		[imageAssetsFixture, 'Standard default image node rendering'],
		[imageAssetsCustomFixture, 'Custom default image node component'],
	];

	for (const [root, description] of configurations) {
		describe(description, () => {
			let baseFixture;

			before(async () => {
				baseFixture = await loadFixture({
					root,
				});
			});

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

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

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

				it('uses public/ image paths unchanged', async () => {
					const res = await baseFixture.fetch('/');
					const html = await res.text();
					const { document } = parseHTML(html);
					assert.equal(document.querySelector('#public > img')?.src, '/favicon.svg');
				});

				it('transforms relative image paths to optimized path', async () => {
					const res = await baseFixture.fetch('/');
					const html = await res.text();
					const { document } = parseHTML(html);
					assert.match(
						document.querySelector('#relative > img')?.src,
						/\/_image\?href=.*%2Fsrc%2Fassets%2Frelative%2Foar.jpg%3ForigWidth%3D420%26origHeight%3D630%26origFormat%3Djpg&w=420&h=630&f=webp/,
					);
				});

				it('transforms aliased image paths to optimized path', async () => {
					const res = await baseFixture.fetch('/');
					const html = await res.text();
					const { document } = parseHTML(html);
					assert.match(
						document.querySelector('#alias > img')?.src,
						/\/_image\?href=.*%2Fsrc%2Fassets%2Falias%2Fcityscape.jpg%3ForigWidth%3D420%26origHeight%3D280%26origFormat%3Djpg&w=420&h=280&f=webp/,
					);
				});

				it('passes images inside image tags to configured image component', async () => {
					const res = await baseFixture.fetch('/');
					const html = await res.text();
					const { document } = parseHTML(html);
					assert.equal(document.querySelector('#component > img')?.className, 'custom-styles');
				});
			});

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

				it('uses public/ image paths unchanged', async () => {
					const html = await baseFixture.readFile('/index.html');
					const { document } = parseHTML(html);
					assert.equal(document.querySelector('#public > img')?.src, '/favicon.svg');
				});

				it('transforms relative image paths to optimized path', async () => {
					const html = await baseFixture.readFile('/index.html');
					const { document } = parseHTML(html);
					assert.match(document.querySelector('#relative > img')?.src, /^\/_astro\/oar.*\.webp$/);
				});

				it('transforms aliased image paths to optimized path', async () => {
					const html = await baseFixture.readFile('/index.html');
					const { document } = parseHTML(html);
					assert.match(
						document.querySelector('#alias > img')?.src,
						/^\/_astro\/cityscape.*\.webp$/,
					);
				});

				it('passes images inside image tags to configured image component', async () => {
					const html = await baseFixture.readFile('/index.html');
					const { document } = parseHTML(html);
					assert.equal(document.querySelector('#component > img')?.className, 'custom-styles');
					assert.match(document.querySelector('#component > img')?.src, /^\/_astro\/oar.*\.webp$/);
				});
			});
		});
	}
});

Domain

Dependencies

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free