Home / File/ primitives.test.js — astro Source File

primitives.test.js — astro Source File

Architecture documentation for primitives.test.js, a javascript file in the astro codebase. 6 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  c5d9f554_f943_b3f2_f078_630616ded80d["primitives.test.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  c5d9f554_f943_b3f2_f078_630616ded80d --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  c5d9f554_f943_b3f2_f078_630616ded80d --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  95925957_51e9_5d2f_fd27_c3f9697e6a81["../../dist/index.js"]
  c5d9f554_f943_b3f2_f078_630616ded80d --> 95925957_51e9_5d2f_fd27_c3f9697e6a81
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  c5d9f554_f943_b3f2_f078_630616ded80d --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  c5d9f554_f943_b3f2_f078_630616ded80d --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  deb87372_5629_35f8_9a54_e755a08f776a["cheerio"]
  c5d9f554_f943_b3f2_f078_630616ded80d --> deb87372_5629_35f8_9a54_e755a08f776a
  style c5d9f554_f943_b3f2_f078_630616ded80d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import assert from 'node:assert/strict';
import { after, afterEach, before, describe, it } from 'node:test';

import * as cheerio from 'cheerio';
import { loadFixture } from '../../../../astro/test/test-utils.js';
import netlifyAdapter from '../../dist/index.js';

describe('Netlify primitives', () => {
	describe('Development', () => {
		/** @type {import('../../../../astro/test/test-utils').Fixture} */
		let fixture;
		let devServer;
		before(async () => {
			fixture = await loadFixture({
				root: new URL('./fixtures/primitives/', import.meta.url),
				output: 'server',
				adapter: netlifyAdapter(),
			});
			devServer = await fixture.startDevServer();
		});

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

		afterEach(async () => {
			fixture.resetAllFiles();
		});

		it('loads Astro routes', async () => {
			const rootResponse = await fixture.fetch('/');
			const $root = cheerio.load(await rootResponse.text());

			assert.equal($root('h1').text(), 'Middleware');

			const imgResponse = await fixture.fetch('/astronaut');
			const $img = cheerio.load(await imgResponse.text());

			assert.equal($img('h1').text(), 'Hello, Astronaut');

			// assert($img('img').attr('src').startsWith('/_image?href='));
		});

		it('loads function routes', async () => {
			const firstResponse = await fixture.fetch('/function');

			assert.equal(await firstResponse.text(), 'Hello from function');

			await fixture.editFile('netlify/functions/func.mjs', (content) =>
				content.replace('Hello', 'Hello again'),
			);

			const secondResponse = await fixture.fetch('/function');

			assert.equal(await secondResponse.text(), 'Hello again from function');
		});

		it('loads edge function routes', async () => {
			const efResponse = await fixture.fetch('/processed/hello');
			const $root = cheerio.load(await efResponse.text());

			assert.equal($root('h1').text(), 'HELLO THERE, ASTRONAUT.');
		});

		it('loads images in development', async () => {
			const imgResponse = await fixture.fetch('/astronaut');
			const $img = cheerio.load(await imgResponse.text());
			const images = $img('img').map((_i, el) => {
				return $img(el).attr('src');
			});

			for (const imgSrc of images) {
				assert(imgSrc.startsWith('/.netlify/images'));
				const imageResponse = await fixture.fetch(imgSrc);
				assert.equal(imageResponse.status, 200);
				// Images are JPEG by default in development
				assert.equal(imageResponse.headers.get('content-type'), 'image/jpeg');
			}
		});
	});
});

Domain

Dependencies

Frequently Asked Questions

What does primitives.test.js do?
primitives.test.js is a source file in the astro codebase, written in javascript. It belongs to the CoreAstro domain.
What does primitives.test.js depend on?
primitives.test.js imports 6 module(s): ../../dist/index.js, cheerio, loadFixture, node:test, strict, test-utils.js.
Where is primitives.test.js in the architecture?
primitives.test.js is located at packages/integrations/netlify/test/development/primitives.test.js (domain: CoreAstro, directory: packages/integrations/netlify/test/development).

Analyze Your Own Codebase

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

Try Supermodel Free