Home / File/ passthrough-image-service.test.js — astro Source File

passthrough-image-service.test.js — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  88f97726_1237_9649_9afd_b86cfb03ad9a["passthrough-image-service.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  88f97726_1237_9649_9afd_b86cfb03ad9a --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  88f97726_1237_9649_9afd_b86cfb03ad9a --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  88f97726_1237_9649_9afd_b86cfb03ad9a --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  88f97726_1237_9649_9afd_b86cfb03ad9a --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  88f97726_1237_9649_9afd_b86cfb03ad9a --> deb87372_5629_35f8_9a54_e755a08f776a
  style 88f97726_1237_9649_9afd_b86cfb03ad9a 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 * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';

describe('passthroughImageService', () => {
	/** @type {import('./test-utils.js').Fixture} */
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/passthrough-image-service/',
		});
	});

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

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

			const html = await fixture.fetch('/').then((res) => res.text());
			$ = cheerio.load(html);
		});

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

		it('includes img element in dev', () => {
			const $img = $('#image img');
			assert.equal($img.length, 1);
		});

		it('serves SVG logo with correct content type', async () => {
			const $img = $('#logo img');
			const src = $img.attr('src');

			const response = await fixture.fetch(src);
			const contentType = response.headers.get('content-type');

			assert.ok(
				contentType.includes('image/svg+xml'),
				`Expected SVG content type, got: ${contentType}`,
			);
		});
	});

	describe('build', () => {
		let $;

		before(async () => {
			await fixture.build();

			const html = await fixture.readFile('/index.html');
			$ = cheerio.load(html);
		});

		describe('Assets', () => {
			it('does not generate webp images', async () => {
				const webpImages = await fixture.glob('_astro/**/*.webp');
				assert.equal(webpImages.length, 0);
			});

			it('preserves original image format', async () => {
				const jpgImages = await fixture.glob('_astro/**/*.jpg');
				assert.ok(jpgImages.length > 0);
			});
		});

		describe('Image component', () => {
			it('includes img element', () => {
				const $img = $('#image img');
				assert.equal($img.length, 1);
			});

			it('preserves original format', () => {
				const $img = $('#image img');
				const src = $img.attr('src');
				assert.ok(src.endsWith('.jpg'), `Should preserve jpg format, got: ${src}`);
			});
		});

		describe('Picture component', () => {
			it('includes <picture> element', () => {
				const $picture = $('#picture picture');
				assert.equal($picture.length, 1);
			});

			it('includes <img> inside picture', () => {
				const $img = $('#picture img');
				assert.equal($img.length, 1);
			});

			it('preserves original format', () => {
				const $img = $('#picture img');
				const src = $img.attr('src');
				assert.ok(src.endsWith('.jpg'), `Should preserve jpg format, got: ${src}`);
			});
		});

		describe('SVG Logo component', () => {
			it('includes img element', () => {
				const $img = $('#logo img');
				assert.equal($img.length, 1);
			});

			it('preserves SVG format', () => {
				const $img = $('#logo img');
				const src = $img.attr('src');
				assert.ok(src.endsWith('.svg'), `Should preserve svg format, got: ${src}`);
			});
		});
	});
});

Dependencies

Frequently Asked Questions

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