Home / File/ test-utils.js — astro Source File

test-utils.js — astro Source File

Architecture documentation for test-utils.js, a javascript file in the astro codebase. 6 imports, 42 dependents.

File javascript E2ETesting TestFixtures 6 imports 42 dependents 6 functions

Entity Profile

Dependency Diagram

graph LR
  2ca394f6_a63d_3921_1f12_c5a979ea0039["test-utils.js"]
  0a624eac_945e_c9e8_c9de_3feb9de2dd15["test-utils.js"]
  2ca394f6_a63d_3921_1f12_c5a979ea0039 --> 0a624eac_945e_c9e8_c9de_3feb9de2dd15
  dd4f09ce_3fd7_8295_f616_8876cda4555c["loadFixture"]
  2ca394f6_a63d_3921_1f12_c5a979ea0039 --> dd4f09ce_3fd7_8295_f616_8876cda4555c
  5d6d1861_a18d_b246_cd94_08889ab7e74c["promises"]
  2ca394f6_a63d_3921_1f12_c5a979ea0039 --> 5d6d1861_a18d_b246_cd94_08889ab7e74c
  c52a5f83_66e3_37d7_9ebb_767f7129bc62["node:path"]
  2ca394f6_a63d_3921_1f12_c5a979ea0039 --> c52a5f83_66e3_37d7_9ebb_767f7129bc62
  d9a92db9_c95e_9165_13ac_24b3d859d946["node:url"]
  2ca394f6_a63d_3921_1f12_c5a979ea0039 --> d9a92db9_c95e_9165_13ac_24b3d859d946
  f8fbe851_c5d6_c4ee_c044_67a751668c18["test"]
  2ca394f6_a63d_3921_1f12_c5a979ea0039 --> f8fbe851_c5d6_c4ee_c044_67a751668c18
  752f9c5a_1c86_7360_d126_bcb34204a9d1["actions-blog.test.js"]
  752f9c5a_1c86_7360_d126_bcb34204a9d1 --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  3507241b_b7f9_3c03_54c1_613a90b1cf41["actions-react-19.test.js"]
  3507241b_b7f9_3c03_54c1_613a90b1cf41 --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  4c13623b_a0f3_45ab_5015_41440cb4d070["astro-component.test.js"]
  4c13623b_a0f3_45ab_5015_41440cb4d070 --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  95a22f6c_8303_af59_867a_90cb094c092c["astro-envs.test.js"]
  95a22f6c_8303_af59_867a_90cb094c092c --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  bcf02f02_eebf_fbac_db0a_40a11df13a18["client-idle-timeout.test.js"]
  bcf02f02_eebf_fbac_db0a_40a11df13a18 --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  f06d80d1_91d7_16f5_7a0f_d9c085476fd0["client-only.test.js"]
  f06d80d1_91d7_16f5_7a0f_d9c085476fd0 --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  f09edeb5_2bf0_094d_f488_7fc8b4becf8f["cloudflare.test.js"]
  f09edeb5_2bf0_094d_f488_7fc8b4becf8f --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  60cd063a_3580_a0f2_9ba6_ab93df1980cf["content-collections.test.js"]
  60cd063a_3580_a0f2_9ba6_ab93df1980cf --> 2ca394f6_a63d_3921_1f12_c5a979ea0039
  style 2ca394f6_a63d_3921_1f12_c5a979ea0039 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import fs from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { expect, test as testBase } from '@playwright/test';
import { loadFixture as baseLoadFixture } from '../test/test-utils.js';

// Get all test files in directory, assign unique port for each of them so they don't conflict
const testFiles = await fs.readdir(new URL('.', import.meta.url));
const testFileToPort = new Map();
for (let i = 0; i < testFiles.length; i++) {
	const file = testFiles[i];
	if (file.endsWith('.test.js')) {
		// Port 4045 is an unsafe port in Chrome, so skip it.
		if (4000 + i === 4045) {
			i++;
		}
		testFileToPort.set(file, 4000 + i);
	}
}

export function loadFixture(testFile, inlineConfig) {
	if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }");

	const port = testFileToPort.get(path.basename(testFile));

	// resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath
	// without this, the main `loadFixture` helper will resolve relative to `packages/astro/test`
	return baseLoadFixture({
		...inlineConfig,
		root: fileURLToPath(new URL(inlineConfig.root, import.meta.url)),
		server: {
			...inlineConfig?.server,
			port,
		},
		vite: {
			...inlineConfig?.vite,
			server: {
				...inlineConfig?.vite?.server,
				strictPort: true,
			},
		},
	});
}

export function testFactory(testFile, inlineConfig) {
	let fixture;

	const test = testBase.extend({
		astro: async ({}, use) => {
			fixture = fixture || (await loadFixture(testFile, inlineConfig));
			await use(fixture);
		},
	});

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

	return test;
}
// ... (97 more lines)

Domain

Subdomains

Dependencies

Imported By

Frequently Asked Questions

What does test-utils.js do?
test-utils.js is a source file in the astro codebase, written in javascript. It belongs to the E2ETesting domain, TestFixtures subdomain.
What functions are defined in test-utils.js?
test-utils.js defines 6 function(s): createLoggerSpy, getErrorOverlayContent, loadFixture, scrollToElement, testFactory, waitForHydrate.
What does test-utils.js depend on?
test-utils.js imports 6 module(s): loadFixture, node:path, node:url, promises, test, test-utils.js.
What files import test-utils.js?
test-utils.js is imported by 42 file(s): actions-blog.test.js, actions-react-19.test.js, astro-component.test.js, astro-envs.test.js, client-idle-timeout.test.js, client-only.test.js, cloudflare.test.js, content-collections.test.js, and 34 more.
Where is test-utils.js in the architecture?
test-utils.js is located at packages/astro/e2e/test-utils.js (domain: E2ETesting, subdomain: TestFixtures, directory: packages/astro/e2e).

Analyze Your Own Codebase

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

Try Supermodel Free