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

image-cdn.test.js — astro Source File

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

Entity Profile

Dependency Diagram

graph LR
  c0f9fc4e_29e7_a10a_70c3_5b8ac1ca9dae["image-cdn.test.js"]
  00a2554b_127e_f517_31a9_3bcd1edd111d["test-utils.js"]
  c0f9fc4e_29e7_a10a_70c3_5b8ac1ca9dae --> 00a2554b_127e_f517_31a9_3bcd1edd111d
  a2e8916f_09d6_61ff_ee5e_719f62dea5c4["loadFixture"]
  c0f9fc4e_29e7_a10a_70c3_5b8ac1ca9dae --> a2e8916f_09d6_61ff_ee5e_719f62dea5c4
  0e588d0c_5409_f008_bf3b_3762dd6c1c5a["strict"]
  c0f9fc4e_29e7_a10a_70c3_5b8ac1ca9dae --> 0e588d0c_5409_f008_bf3b_3762dd6c1c5a
  fa887d9d_247c_d770_d661_490745669024["node:test"]
  c0f9fc4e_29e7_a10a_70c3_5b8ac1ca9dae --> fa887d9d_247c_d770_d661_490745669024
  7cb75991_c51f_4a44_8d30_fc6099530bc5["netlify"]
  c0f9fc4e_29e7_a10a_70c3_5b8ac1ca9dae --> 7cb75991_c51f_4a44_8d30_fc6099530bc5
  style c0f9fc4e_29e7_a10a_70c3_5b8ac1ca9dae 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 { remotePatternToRegex } from '@astrojs/netlify';
import { loadFixture } from '../../../../astro/test/test-utils.js';

describe(
	'Image CDN',
	() => {
		const root = new URL('./fixtures/middleware/', import.meta.url);

		describe('configuration', () => {
			after(() => {
				process.env.DISABLE_IMAGE_CDN = undefined;
			});

			it('enables Netlify Image CDN', async () => {
				const fixture = await loadFixture({ root });
				await fixture.build();

				const astronautPage = await fixture.readFile('astronaut/index.html');
				assert.equal(astronautPage.includes(`src="/.netlify/image`), true);
			});

			it('respects image CDN opt-out', async () => {
				process.env.DISABLE_IMAGE_CDN = 'true';
				const fixture = await loadFixture({ root });
				await fixture.build();

				const astronautPage = await fixture.readFile('astronaut/index.html');
				assert.equal(astronautPage.includes(`src="/_astro/astronaut.`), true);
			});
		});

		describe('remote image config', () => {
			let regexes;

			before(async () => {
				const fixture = await loadFixture({ root });
				await fixture.build();

				const config = await fixture.readFile('../.netlify/v1/config.json');
				if (config) {
					regexes = JSON.parse(config).images.remote_images.map((pattern) => new RegExp(pattern));
				}
			});

			it('generates remote image config patterns', async () => {
				assert.equal(regexes?.length, 3);
			});

			it('generates correct config for domains', async () => {
				const domain = regexes[0];
				assert.equal(domain.test('https://example.net/image.jpg'), true);
				assert.equal(
					domain.test('https://www.example.net/image.jpg'),
					false,
					'subdomain should not match',
				);
				assert.equal(domain.test('http://example.net/image.jpg'), true, 'http should match');
				assert.equal(
// ... (67 more lines)

Dependencies

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free