Home / File/ static-assets.test.js — astro Source File

static-assets.test.js — astro Source File

Architecture documentation for static-assets.test.js, a javascript file in the astro codebase. 4 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  56777acc_b5e0_629d_c0e3_2940a6a61608["static-assets.test.js"]
  81c783ff_7259_703c_7bdc_c78ff183642d["test-utils.js"]
  56777acc_b5e0_629d_c0e3_2940a6a61608 --> 81c783ff_7259_703c_7bdc_c78ff183642d
  f0817fb3_f192_bfcf_f1b0_c1a429dad07b["loadFixture"]
  56777acc_b5e0_629d_c0e3_2940a6a61608 --> f0817fb3_f192_bfcf_f1b0_c1a429dad07b
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  56777acc_b5e0_629d_c0e3_2940a6a61608 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  56777acc_b5e0_629d_c0e3_2940a6a61608 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style 56777acc_b5e0_629d_c0e3_2940a6a61608 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { loadFixture } from './test-utils.js';

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

	const VALID_CACHE_CONTROL = 'public, max-age=31536000, immutable';

	async function build({ adapter, assets, output }) {
		fixture = await loadFixture({
			root: './fixtures/static-assets/',
			output,
			adapter,
			build: {
				assets,
			},
		});
		await fixture.build();
	}

	async function getConfig() {
		const json = await fixture.readFile('../.vercel/output/config.json');
		const config = JSON.parse(json);

		return config;
	}

	async function getAssets() {
		return fixture.config.build.assets;
	}

	async function checkValidCacheControl(assets) {
		const config = await getConfig();
		const theAssets = assets ?? (await getAssets());

		const route = config.routes.find((r) => r.src === `^/${theAssets}/(.*)$`);
		assert.equal(route.headers['cache-control'], VALID_CACHE_CONTROL);
		assert.equal(route.continue, true);
	}

	describe('static adapter', () => {
		it('has cache control', async () => {
			const { default: vercel } = await import('@astrojs/vercel');
			await build({
				adapter: vercel(),
			});
			await checkValidCacheControl();
		});

		it('has cache control other assets', async () => {
			const { default: vercel } = await import('@astrojs/vercel');
			const assets = '_foo';
			await build({
				adapter: vercel(),
				assets,
			});
			await checkValidCacheControl(assets);
		});
	});

	describe('serverless adapter', () => {
		it('has cache control', async () => {
			const { default: vercel } = await import('@astrojs/vercel');
			await build({
				output: 'server',
				adapter: vercel(),
			});
			await checkValidCacheControl();
		});

		it('has cache control other assets', async () => {
			const { default: vercel } = await import('@astrojs/vercel');
			const assets = '_foo';
			await build({
				output: 'server',
				adapter: vercel(),
				assets,
			});
			await checkValidCacheControl(assets);
		});
	});
});

Domain

Dependencies

Frequently Asked Questions

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