prepareTestFactory() — astro Function Reference
Architecture documentation for the prepareTestFactory() function in shared-component-tests.js from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 4471adac_6b72_7031_4587_e50c8db5a233["prepareTestFactory()"] f50170e1_d539_f9d5_a768_c073a3afcfd4["shared-component-tests.js"] 4471adac_6b72_7031_4587_e50c8db5a233 -->|defined in| f50170e1_d539_f9d5_a768_c073a3afcfd4 e27f6887_ea47_dd44_7933_5faa0f6bcf4d["testFactory()"] 4471adac_6b72_7031_4587_e50c8db5a233 -->|calls| e27f6887_ea47_dd44_7933_5faa0f6bcf4d c373140e_7fdf_7fff_8884_991b85bc22b5["waitForHydrate()"] 4471adac_6b72_7031_4587_e50c8db5a233 -->|calls| c373140e_7fdf_7fff_8884_991b85bc22b5 f16c187c_deda_00e3_0b31_6ec7d6f81052["scrollToElement()"] 4471adac_6b72_7031_4587_e50c8db5a233 -->|calls| f16c187c_deda_00e3_0b31_6ec7d6f81052 style 4471adac_6b72_7031_4587_e50c8db5a233 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/e2e/shared-component-tests.js lines 4–165
export function prepareTestFactory(testFile, opts) {
const test = testFactory(testFile, opts);
let devServer;
test.beforeAll(async ({ astro }) => {
devServer = await astro.startDevServer();
});
test.afterAll(async () => {
await devServer.stop();
});
const createTests = ({ pageUrl, pageSourceFilePath, componentFilePath, counterCssFilePath }) => {
test('server only', async ({ page, astro }) => {
await page.goto(astro.resolveUrl(pageUrl));
const counter = page.locator('#server-only');
await expect(counter, 'component is visible').toBeVisible();
const count = counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');
const inc = counter.locator('.increment');
await inc.click();
await expect(count, 'component not hydrated').toHaveText('0');
});
test('client:idle', async ({ page, astro }) => {
await page.goto(astro.resolveUrl(pageUrl));
const counter = page.locator('#client-idle');
await expect(counter, 'component is visible').toBeVisible();
const count = counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');
await waitForHydrate(page, counter);
const inc = counter.locator('.increment');
await inc.click();
await expect(count, 'count incremented by 1').toHaveText('1');
});
test('client:load', async ({ page, astro }) => {
await page.goto(astro.resolveUrl(pageUrl));
const counter = page.locator('#client-load');
await expect(counter, 'component is visible').toBeVisible();
const count = counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');
await waitForHydrate(page, counter);
const inc = counter.locator('.increment');
await inc.click();
await expect(count, 'count incremented by 1').toHaveText('1');
});
test('client:visible', async ({ page, astro }) => {
await page.goto(astro.resolveUrl(pageUrl));
// Make sure the component is on screen to trigger hydration
const counter = page.locator('#client-visible');
// NOTE: Use custom implementation instead of `counter.scrollIntoViewIfNeeded`
// as Playwright's function doesn't take into account of `counter` being hydrated
// and losing the original DOM reference.
await scrollToElement(counter);
await expect(counter, 'component is visible').toBeVisible();
const count = counter.locator('pre');
await expect(count, 'initial count is 0').toHaveText('0');
await waitForHydrate(page, counter);
const inc = counter.locator('.increment');
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does prepareTestFactory() do?
prepareTestFactory() is a function in the astro codebase, defined in packages/astro/e2e/shared-component-tests.js.
Where is prepareTestFactory() defined?
prepareTestFactory() is defined in packages/astro/e2e/shared-component-tests.js at line 4.
What does prepareTestFactory() call?
prepareTestFactory() calls 3 function(s): scrollToElement, testFactory, waitForHydrate.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free