[ci] format
This commit is contained in:
parent
79fe09fa30
commit
cb3fcdde6a
6 changed files with 48 additions and 25 deletions
|
@ -1,4 +1,4 @@
|
|||
export { };
|
||||
export {};
|
||||
|
||||
declare global {
|
||||
interface NetworkInformation {
|
||||
|
@ -10,6 +10,6 @@ declare global {
|
|||
|
||||
var NetworkInformation: {
|
||||
prototype: NetworkInformation;
|
||||
new(): NetworkInformation;
|
||||
new (): NetworkInformation;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -72,7 +72,10 @@ export interface PrefetchOptions {
|
|||
throttle?: number;
|
||||
}
|
||||
|
||||
export default function prefetch({ selector = 'a[href][rel~="prefetch"]', throttle = 1 }: PrefetchOptions) {
|
||||
export default function prefetch({
|
||||
selector = 'a[href][rel~="prefetch"]',
|
||||
throttle = 1,
|
||||
}: PrefetchOptions) {
|
||||
const conn = navigator.connection;
|
||||
|
||||
if (typeof conn !== 'undefined') {
|
||||
|
|
|
@ -9,9 +9,11 @@ export default function (options: PrefetchOptions = {}): AstroIntegration {
|
|||
// Inject the necessary polyfills on every page (inlined for speed).
|
||||
injectScript(
|
||||
'page',
|
||||
`import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify(options)});`
|
||||
`import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify(
|
||||
options
|
||||
)});`
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
@ -25,8 +25,14 @@ test.describe('Basic prefetch', () => {
|
|||
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(requests.has(astro.resolveUrl('/about')), '/about was prefetched').toBeTruthy();
|
||||
await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy();
|
||||
await expect(
|
||||
requests.has(astro.resolveUrl('/about')),
|
||||
'/about was prefetched'
|
||||
).toBeTruthy();
|
||||
await expect(
|
||||
requests.has(astro.resolveUrl('/contact')),
|
||||
'/contact was prefetched'
|
||||
).toBeTruthy();
|
||||
await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
@ -55,8 +61,14 @@ test.describe('Basic prefetch', () => {
|
|||
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(requests.has(astro.resolveUrl('/about')), '/about was prefetched').toBeTruthy();
|
||||
await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy();
|
||||
await expect(
|
||||
requests.has(astro.resolveUrl('/about')),
|
||||
'/about was prefetched'
|
||||
).toBeTruthy();
|
||||
await expect(
|
||||
requests.has(astro.resolveUrl('/contact')),
|
||||
'/contact was prefetched'
|
||||
).toBeTruthy();
|
||||
await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -6,9 +6,9 @@ const test = testFactory({
|
|||
root: './fixtures/basic-prefetch/',
|
||||
integrations: [
|
||||
prefetch({
|
||||
selector: 'a[href="/contact"]'
|
||||
selector: 'a[href="/contact"]',
|
||||
}),
|
||||
]
|
||||
],
|
||||
});
|
||||
|
||||
test.describe('Custom prefetch selectors', () => {
|
||||
|
@ -34,7 +34,10 @@ test.describe('Custom prefetch selectors', () => {
|
|||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(requests.has(astro.resolveUrl('/about')), '/about was skipped').toBeFalsy();
|
||||
await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy();
|
||||
await expect(
|
||||
requests.has(astro.resolveUrl('/contact')),
|
||||
'/contact was prefetched'
|
||||
).toBeTruthy();
|
||||
await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
@ -64,7 +67,10 @@ test.describe('Custom prefetch selectors', () => {
|
|||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(requests.has(astro.resolveUrl('/about')), '/about was skipped').toBeFalsy();
|
||||
await expect(requests.has(astro.resolveUrl('/contact')), '/contact was prefetched').toBeTruthy();
|
||||
await expect(
|
||||
requests.has(astro.resolveUrl('/contact')),
|
||||
'/contact was prefetched'
|
||||
).toBeTruthy();
|
||||
await expect(requests.has(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
"allowJs": true,
|
||||
"module": "ES2020",
|
||||
"outDir": "./dist",
|
||||
"target": "ES2020",
|
||||
"target": "ES2020"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue