loadFixture() — astro Function Reference
Architecture documentation for the loadFixture() function in test-utils.js from the astro codebase.
Entity Profile
Dependency Diagram
graph TD dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture()"] 0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"] dd4f09ce_3fd7_8295_f616_8876cda4555c -->|defined in| 0a624eac_945e_c9e8_c9de_3feb9de2dd15 019f0b9c_f317_8761_c903_c4c521c6970a["loadFixture()"] 019f0b9c_f317_8761_c903_c4c521c6970a -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c 6d277f3d_88f9_05d3_9a12_e441d72b9900["benchmark()"] 6d277f3d_88f9_05d3_9a12_e441d72b9900 -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c b986d062_9e9a_0abf_b359_867ad0f09623["createFixture()"] b986d062_9e9a_0abf_b359_867ad0f09623 -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c 34879056_2ed8_a6e4_7a87_126d3b31f769["createDevFixture()"] 34879056_2ed8_a6e4_7a87_126d3b31f769 -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c f29fe0ca_bda0_7579_8486_db11be5bbf05["createBuildFixture()"] f29fe0ca_bda0_7579_8486_db11be5bbf05 -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c b5ecd85d_1d95_4be1_d36c_a9e4938046ab["createSsrFixture()"] b5ecd85d_1d95_4be1_d36c_a9e4938046ab -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c 5b5870e5_6570_8950_c56d_3170427d28c7["loadFixture()"] 5b5870e5_6570_8950_c56d_3170427d28c7 -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c 33b9a01d_12ac_568f_9775_9e80b35139cb["loadFixture()"] 33b9a01d_12ac_568f_9775_9e80b35139cb -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c caadc522_c0b6_936a_6b1a_abe8c4d593c7["getFixture()"] caadc522_c0b6_936a_6b1a_abe8c4d593c7 -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c 32a88c02_5854_d88c_4f32_84c4b704b523["getFixture()"] 32a88c02_5854_d88c_4f32_84c4b704b523 -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c 50124cc7_e209_9bdd_019a_4ee769ff5902["getFixture()"] 50124cc7_e209_9bdd_019a_4ee769ff5902 -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c 3c8e19c6_a6bf_3fe9_fcc2_83c525538edb["buildFixture()"] 3c8e19c6_a6bf_3fe9_fcc2_83c525538edb -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c 0b7a6b11_e910_da4b_c617_1880167f44ef["loadFixture()"] 0b7a6b11_e910_da4b_c617_1880167f44ef -->|calls| dd4f09ce_3fd7_8295_f616_8876cda4555c style dd4f09ce_3fd7_8295_f616_8876cda4555c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/test/test-utils.js lines 90–308
export async function loadFixture(inlineConfig) {
if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }");
// Silent by default during tests to not pollute the console output
inlineConfig.logLevel ??= 'silent';
inlineConfig.vite ??= {};
inlineConfig.vite.logLevel = 'silent';
let root = inlineConfig.root;
// Handle URL, should already be absolute so just convert to path
if (typeof root !== 'string') {
root = fileURLToPath(root);
}
// Handle "file:///C:/Users/fred", convert to "C:/Users/fred"
else if (root.startsWith('file://')) {
root = fileURLToPath(new URL(root));
}
// Handle "./fixtures/...", convert to absolute path
else if (!path.isAbsolute(root)) {
root = fileURLToPath(new URL(root, import.meta.url));
}
inlineConfig = { ...inlineConfig, root };
// Load the config.
const { astroConfig: config } = await resolveConfig(inlineConfig, 'dev');
const protocol = config.vite?.server?.https ? 'https' : 'http';
const resolveUrl = (url) =>
`${protocol}://${config.server.host || 'localhost'}:${config.server.port}${url.replace(
/^\/?/,
'/',
)}`;
// A map of files that have been edited.
let fileEdits = new Map();
const resetAllFiles = () => {
for (const [, reset] of fileEdits) {
reset();
}
fileEdits.clear();
};
const onNextChange = () =>
devServer
? new Promise((resolve) => devServer.watcher.once('change', resolve))
: Promise.reject(new Error('No dev server running'));
// After each test, reset each of the edits to their original contents.
if (typeof afterEach === 'function') {
afterEach(resetAllFiles);
}
// Also do it on process exit, just in case.
process.on('exit', resetAllFiles);
let fixtureId = new Date().valueOf();
let devServer;
return {
build: async (extraInlineConfig = {}, options = {}) => {
globalContentLayer.dispose();
globalContentConfigObserver.set({ status: 'init' });
// Reset NODE_ENV so it can be re-set by `build()`
delete process.env.NODE_ENV;
return build(mergeConfig(inlineConfig, extraInlineConfig), {
teardownCompiler: false,
...options,
});
},
sync,
check: async (opts) => {
return await check(opts);
},
startDevServer: async (extraInlineConfig = {}) => {
globalContentLayer.dispose();
globalContentConfigObserver.set({ status: 'init' });
// Reset NODE_ENV so it can be re-set by `dev()`
delete process.env.NODE_ENV;
try {
devServer = await dev(mergeConfig(inlineConfig, extraInlineConfig));
} catch (e) {
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does loadFixture() do?
loadFixture() is a function in the astro codebase, defined in packages/astro/test/test-utils.js.
Where is loadFixture() defined?
loadFixture() is defined in packages/astro/test/test-utils.js at line 90.
What does loadFixture() call?
loadFixture() calls 1 function(s): parseAddressToHost.
What calls loadFixture()?
loadFixture() is called by 16 function(s): benchmark, buildFixture, createBuildFixture, createDevFixture, createFixture, createSsrFixture, getFixture, getFixture, and 8 more.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free