Home / File/ mdx-images.test.js — astro Source File

mdx-images.test.js — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  b6ae5692_8a8d_9259_968a_82da1959e559["mdx-images.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  b6ae5692_8a8d_9259_968a_82da1959e559 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  b6ae5692_8a8d_9259_968a_82da1959e559 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  b6ae5692_8a8d_9259_968a_82da1959e559 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  b6ae5692_8a8d_9259_968a_82da1959e559 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  cb315bcc_59d8_fa19_79aa_5da7cd3730c5["linkedom"]
  b6ae5692_8a8d_9259_968a_82da1959e559 --> cb315bcc_59d8_fa19_79aa_5da7cd3730c5
  style b6ae5692_8a8d_9259_968a_82da1959e559 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import * as 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 imageTestRoutes = ['with-components', 'esm-import', 'content-collection'];

describe('MDX Page', () => {
	let devServer;
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: new URL('./fixtures/mdx-images/', import.meta.url),
		});
		devServer = await fixture.startDevServer();
	});

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

	describe('Optimized images in MDX', () => {
		it('works', async () => {
			const res = await fixture.fetch('/');
			assert.equal(res.status, 200);

			const html = await res.text();
			const { document } = parseHTML(html);

			const imgs = document.getElementsByTagName('img');
			assert.equal(imgs.length, 6);
			// Image using a relative path
			assert.equal(imgs.item(0).src.startsWith('/_image'), true);
			// Image using an aliased path
			assert.equal(imgs.item(1).src.startsWith('/_image'), true);
			// Image with title
			assert.equal(imgs.item(2).title, 'Houston title');
			// Image with spaces in the path
			assert.equal(imgs.item(3).src.startsWith('/_image'), true);
			// Image using a relative path with no slashes
			assert.equal(imgs.item(4).src.startsWith('/_image'), true);
			// Image using a relative path with nested directory
			assert.equal(imgs.item(5).src.startsWith('/_image'), true);
		});

		for (const route of imageTestRoutes) {
			it(`supports img component - ${route}`, async () => {
				const res = await fixture.fetch(`/${route}`);
				assert.equal(res.status, 200);

				const html = await res.text();
				const { document } = parseHTML(html);

				const imgs = document.getElementsByTagName('img');
				assert.equal(imgs.length, 2);

				const assetsImg = imgs.item(0);
				assert.equal(assetsImg.src.startsWith('/_image'), true);
				assert.equal(assetsImg.hasAttribute('data-my-image'), true);

				const publicImg = imgs.item(1);
				assert.equal(publicImg.src, '/favicon.svg');
				assert.equal(publicImg.hasAttribute('data-my-image'), true);
			});
		}
	});

	describe('build', () => {
		before(async () => {
			await fixture.build();
		});
		it('includes responsive styles', async () => {
			const code = await fixture.readFile('/index.html');
			assert.ok(code.includes('[data-astro-image]'));
		});
		it("doesn't include styles on pages without images", async () => {
			const code = await fixture.readFile('/no-image/index.html');
			assert.ok(!code.includes('[data-astro-image]'));
		});
	});
});

Domain

Dependencies

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free