Home / Function/ createRequestAndResponse() — astro Function Reference

createRequestAndResponse() — astro Function Reference

Architecture documentation for the createRequestAndResponse() function in test-utils.js from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  37bee138_718e_22c5_b294_37b0235244a2["createRequestAndResponse()"]
  b0be4d0c_86b6_a283_f2af_003189bfd572["test-utils.js"]
  37bee138_718e_22c5_b294_37b0235244a2 -->|defined in| b0be4d0c_86b6_a283_f2af_003189bfd572
  faadc1fc_e8ff_8aac_bad0_4c2e6c17fbde["toPromise()"]
  37bee138_718e_22c5_b294_37b0235244a2 -->|calls| faadc1fc_e8ff_8aac_bad0_4c2e6c17fbde
  66c5f3dc_f6ed_cf07_994f_ece674a6d8a3["buffersToString()"]
  37bee138_718e_22c5_b294_37b0235244a2 -->|calls| 66c5f3dc_f6ed_cf07_994f_ece674a6d8a3
  style 37bee138_718e_22c5_b294_37b0235244a2 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/test/units/test-utils.js lines 39–64

export function createRequestAndResponse(reqOptions = {}) {
	const req = httpMocks.createRequest(reqOptions);
	req.headers.host ||= 'localhost';

	const res = httpMocks.createResponse({
		eventEmitter: EventEmitter,
		req,
	});

	// When the response is complete.
	const done = toPromise(res);

	// Get the response as text
	const text = async () => {
		let chunks = await done;
		return buffersToString(chunks);
	};

	// Get the response as json
	const json = async () => {
		const raw = await text();
		return JSON.parse(raw);
	};

	return { req, res, done, json, text };
}

Subdomains

Frequently Asked Questions

What does createRequestAndResponse() do?
createRequestAndResponse() is a function in the astro codebase, defined in packages/astro/test/units/test-utils.js.
Where is createRequestAndResponse() defined?
createRequestAndResponse() is defined in packages/astro/test/units/test-utils.js at line 39.
What does createRequestAndResponse() call?
createRequestAndResponse() calls 2 function(s): buffersToString, toPromise.

Analyze Your Own Codebase

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

Try Supermodel Free