image.test.js — astro Source File
Architecture documentation for image.test.js, a javascript file in the astro codebase. 5 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR ed6ad9ed_ae1d_09a1_659b_4e74efe7d6f2["image.test.js"] 81c783ff_7259_703c_7bdc_c78ff183642d["test-utils.js"] ed6ad9ed_ae1d_09a1_659b_4e74efe7d6f2 --> 81c783ff_7259_703c_7bdc_c78ff183642d f0817fb3_f192_bfcf_f1b0_c1a429dad07b["loadFixture"] ed6ad9ed_ae1d_09a1_659b_4e74efe7d6f2 --> f0817fb3_f192_bfcf_f1b0_c1a429dad07b e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"] ed6ad9ed_ae1d_09a1_659b_4e74efe7d6f2 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607 6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"] ed6ad9ed_ae1d_09a1_659b_4e74efe7d6f2 --> 6b0635f9_51ea_77aa_767b_7857878e98a6 deb87372_5629_35f8_9a54_e755a08f776a["cheerio"] ed6ad9ed_ae1d_09a1_659b_4e74efe7d6f2 --> deb87372_5629_35f8_9a54_e755a08f776a style ed6ad9ed_ae1d_09a1_659b_4e74efe7d6f2 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('Image', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;
before(async () => {
fixture = await loadFixture({
root: './fixtures/image/',
});
await fixture.build();
});
it('build successful', async () => {
assert.ok(await fixture.readFile('../.vercel/output/static/index.html'));
});
it('has link to vercel in build with proper attributes', async () => {
const html = await fixture.readFile('../.vercel/output/static/index.html');
const $ = cheerio.load(html);
const img = $('#basic-image img');
assert.equal(img.attr('src').startsWith('/_vercel/image?url=_astr'), true);
assert.equal(img.attr('loading'), 'lazy');
assert.equal(img.attr('width'), '225');
});
it('generates valid image sizes when requested width is larger than source image', async () => {
const html = await fixture.readFile('../.vercel/output/static/index.html');
const $ = cheerio.load(html);
const img = $('#small-source img');
const widths = img
.attr('srcset')
.split(', ')
.map((entry) => entry.split(' ')[1]);
assert.deepEqual(widths, ['640w'], 'uses valid widths in srcset');
const url = new URL(img.attr('src'), 'http://localhost');
assert.equal(url.searchParams.get('w'), '640', 'uses valid width in src');
assert.equal(img.attr('width'), '225', 'uses requested width in img attribute');
});
it('generates valid densities-based srcset using only configured sizes', async () => {
const html = await fixture.readFile('../.vercel/output/static/index.html');
const $ = cheerio.load(html);
const img = $('#densities-test img');
const srcset = img.attr('srcset');
// Extract widths from srcset (format: "url 1x", "url 1.5x", etc)
const descriptors = srcset.split(', ').map((entry) => entry.split(' ')[1]);
// Extract the widths from the URLs (they should be valid configured sizes)
const urls = srcset.split(', ').map((entry) => entry.split(' ')[0]);
const widthsFromUrls = urls.map((url) => {
const urlObj = new URL(url, 'http://localhost');
return parseInt(urlObj.searchParams.get('w'), 10);
// ... (87 more lines)
Domain
Dependencies
- cheerio
- loadFixture
- node:test
- strict
- test-utils.js
Source
Frequently Asked Questions
What does image.test.js do?
image.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does image.test.js depend on?
image.test.js imports 5 module(s): cheerio, loadFixture, node:test, strict, test-utils.js.
Where is image.test.js in the architecture?
image.test.js is located at packages/integrations/vercel/test/image.test.js (domain: CoreAstro, directory: packages/integrations/vercel/test).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free