Home / File/ api-route.test.js — astro Source File

api-route.test.js — astro Source File

Architecture documentation for api-route.test.js, a javascript file in the astro codebase. 7 imports, 0 dependents.

Entity Profile

Dependency Diagram

graph LR
  16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6["api-route.test.js"]
  760b1776_8858_e3bd_06b8_5cc4c1a9cbdc["../dist/index.js"]
  16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6 --> 760b1776_8858_e3bd_06b8_5cc4c1a9cbdc
  ff334e41_2760_839e_fc38_ab9318c18dfc["test-utils.js"]
  16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6 --> ff334e41_2760_839e_fc38_ab9318c18dfc
  8aa05169_90cd_eb5f_1d5a_e36a77000a53["createRequestAndResponse"]
  16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6 --> 8aa05169_90cd_eb5f_1d5a_e36a77000a53
  0b7a6b11_e910_da4b_c617_1880167f44ef["loadFixture"]
  16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6 --> 0b7a6b11_e910_da4b_c617_1880167f44ef
  e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607["strict"]
  16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6 --> e1e2fac7_5a95_7a88_cb1e_0a3b91c4e607
  349a6247_7703_ff13_e2b6_d319130ff2f9["node:crypto"]
  16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6 --> 349a6247_7703_ff13_e2b6_d319130ff2f9
  6b0635f9_51ea_77aa_767b_7857878e98a6["node:test"]
  16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6 --> 6b0635f9_51ea_77aa_767b_7857878e98a6
  style 16e7fb07_ae19_7dcd_c4e1_9bbcfc63ada6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import * as assert from 'node:assert/strict';
import crypto from 'node:crypto';
import { after, before, describe, it } from 'node:test';
import nodejs from '../dist/index.js';
import { createRequestAndResponse, loadFixture } from './test-utils.js';

describe('API routes', () => {
	/** @type {import('./test-utils').Fixture} */
	let fixture;
	/** @type {import('../../../astro/src/types/public/preview.js').PreviewServer} */
	let previewServer;
	/** @type {URL} */
	let baseUri;

	before(async () => {
		fixture = await loadFixture({
			root: './fixtures/api-route/',
			output: 'server',
			adapter: nodejs({ mode: 'middleware' }),
		});
		await fixture.build();
		previewServer = await fixture.preview();
		baseUri = new URL(`http://${previewServer.host ?? 'localhost'}:${previewServer.port}/`);
	});

	after(() => previewServer.stop());

	it('Can get the request body', async () => {
		const { handler } = await import('./fixtures/api-route/dist/server/entry.mjs');
		const { req, res, done } = createRequestAndResponse({
			method: 'POST',
			url: '/recipes',
		});

		req.once('async_iterator', () => {
			req.send(JSON.stringify({ id: 2 }));
		});

		handler(req, res);

		const [buffer] = await done;

		const json = JSON.parse(buffer.toString('utf-8'));

		assert.equal(json.length, 1);

		assert.equal(json[0].name, 'Broccoli Soup');
	});

	it('Can get binary data', async () => {
		const { handler } = await import('./fixtures/api-route/dist/server/entry.mjs');

		const { req, res, done } = createRequestAndResponse({
			method: 'POST',
			url: '/binary',
		});

		req.once('async_iterator', () => {
			req.send(Buffer.from(new Uint8Array([1, 2, 3, 4, 5])));
		});
// ... (94 more lines)

Domain

Dependencies

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free