prefetch.test.js — astro Source File
Architecture documentation for prefetch.test.js, a javascript file in the astro codebase. 3 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 1c683310_85be_7904_6ff5_67c2a35b7c0b["prefetch.test.js"] 2ca394f6_a63d_3921_1f12_c5a979ea0039["test-utils.js"] 1c683310_85be_7904_6ff5_67c2a35b7c0b --> 2ca394f6_a63d_3921_1f12_c5a979ea0039 e27f6887_ea47_dd44_7933_5faa0f6bcf4d["testFactory"] 1c683310_85be_7904_6ff5_67c2a35b7c0b --> e27f6887_ea47_dd44_7933_5faa0f6bcf4d f8fbe851_c5d6_c4ee_c044_67a751668c18["test"] 1c683310_85be_7904_6ff5_67c2a35b7c0b --> f8fbe851_c5d6_c4ee_c044_67a751668c18 style 1c683310_85be_7904_6ff5_67c2a35b7c0b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import { expect } from '@playwright/test';
import { testFactory } from './test-utils.js';
const test = testFactory(import.meta.url, {
root: './fixtures/prefetch/',
});
// Used to track fetch request urls
/** @type {string[]} */
const reqUrls = [];
test.beforeEach(async ({ page }) => {
page.on('request', (req) => {
const urlObj = new URL(req.url());
reqUrls.push(urlObj.pathname + urlObj.search);
});
});
test.afterEach(() => {
reqUrls.length = 0;
});
/**
* Check if url is prefetched via `link[rel="prefetch"]` or `fetch()` (from `reqUrls`)
* @param {string} url
* @param {import('@playwright/test').Page} page
* @param {number} [count] Also expect that it's prefetched this amount of times
*/
async function expectUrlPrefetched(url, page, count) {
try {
await expect(page.locator(`link[rel="prefetch"][href$="${url}"]`)).toBeAttached();
} catch {
// If link is not found, check if it was fetched via `fetch()`
expect(reqUrls, `${url} is not prefetched via link or fetch`).toContainEqual(url);
}
if (count != null) {
const linkCount = await page.locator(`link[rel="prefetch"][href$="${url}"]`).count();
try {
expect(linkCount).toBe(count);
} catch {
const fetchCount = reqUrls.filter((u) => u.includes(url)).length;
expect(
fetchCount,
`${url} should be prefetched ${count} time(s), but is prefetch with link ${linkCount} time(s) and with fetch ${fetchCount} time(s)`,
).toEqual(count);
}
}
}
/**
* Check if url is not prefetched via `link[rel="prefetch"]` and `fetch()` (from `reqUrls`)
* @param {string} url
* @param {import('@playwright/test').Page} page
*/
async function expectUrlNotPrefetched(url, page) {
await expect(page.locator(`link[rel="prefetch"][href$="${url}"]`)).not.toBeAttached();
expect(reqUrls).not.toContainEqual(url);
}
/**
* @param {import('@playwright/test').Page} page
// ... (426 more lines)
Domain
Subdomains
Dependencies
Source
Frequently Asked Questions
What does prefetch.test.js do?
prefetch.test.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 prefetch.test.js?
prefetch.test.js defines 4 function(s): expectUrlNotPrefetched, expectUrlPrefetched, mouseDown, waitForPageLoad.
What does prefetch.test.js depend on?
prefetch.test.js imports 3 module(s): test, test-utils.js, testFactory.
Where is prefetch.test.js in the architecture?
prefetch.test.js is located at packages/astro/e2e/prefetch.test.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