Home / File/ astro-assets-prefix-multi-cdn.test.js — astro Source File

astro-assets-prefix-multi-cdn.test.js — astro Source File

Architecture documentation for astro-assets-prefix-multi-cdn.test.js, a javascript file in the astro codebase. 6 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  ee56b650_a538_6287_413f_0137a9a4f896["astro-assets-prefix-multi-cdn.test.js"]
  be670a78_841c_46e5_0af5_c5c328869ecb["test-adapter.js"]
  ee56b650_a538_6287_413f_0137a9a4f896 --> be670a78_841c_46e5_0af5_c5c328869ecb
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  ee56b650_a538_6287_413f_0137a9a4f896 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  ee56b650_a538_6287_413f_0137a9a4f896 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  ee56b650_a538_6287_413f_0137a9a4f896 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  ee56b650_a538_6287_413f_0137a9a4f896 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  ee56b650_a538_6287_413f_0137a9a4f896 --> deb87372_5629_35f8_9a54_e755a08f776a
  style ee56b650_a538_6287_413f_0137a9a4f896 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 testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';

const defaultAssetsPrefixRegex = /^https:\/\/example.com\/_astro\/.*/;
const jsAssetsPrefixRegex = /^https:\/\/js\.example\.com\/_astro\/.*/;
const cssAssetsPrefixRegex = /^https:\/\/css\.example\.com\/_astro\/.*/;
const assetsPrefix = {
	js: 'https://js.example.com',
	css: 'https://css.example.com',
	fallback: 'https://example.com',
};

// Asset prefix for CDN support
describe('Assets Prefix Multiple CDN - Static', () => {
	let fixture;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/astro-assets-prefix',
			build: {
				assetsPrefix,
			},
		});
		await fixture.build();
	});

	after(async () => {
		await fixture.clean();
	});

	it('all stylesheets should start with  cssAssetPrefix', async () => {
		const html = await fixture.readFile('/index.html');
		const $ = cheerio.load(html);
		const stylesheets = $('link[rel="stylesheet"]');
		stylesheets.each((_i, el) => {
			assert.match(el.attribs.href, cssAssetsPrefixRegex);
		});
	});

	it('image src start with fallback', async () => {
		const html = await fixture.readFile('/index.html');
		const $ = cheerio.load(html);
		const imgAsset = $('#image-asset');
		assert.match(imgAsset.attr('src'), defaultAssetsPrefixRegex);
	});

	it('react component astro-island should import from jsAssetsPrefix', async () => {
		const html = await fixture.readFile('/index.html');
		const $ = cheerio.load(html);
		const island = $('astro-island');
		assert.match(island.attr('component-url'), jsAssetsPrefixRegex);
		assert.match(island.attr('renderer-url'), jsAssetsPrefixRegex);
	});

	it('import.meta.env.ASSETS_PREFIX works', async () => {
		const html = await fixture.readFile('/index.html');
		const $ = cheerio.load(html);
// ... (81 more lines)

Dependencies

Frequently Asked Questions

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