Skip to content

Commit

Permalink
failing tests for #790
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Aug 30, 2022
1 parent aa76bdc commit c899e16
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div style="height: 2000px; background: palegoldenrod" />

<a id="one" href="/data-sveltekit/noscroll/target" data-sveltekit-noscroll>one</a>

<div data-sveltekit-noscroll>
<a id="two" href="/data-sveltekit/noscroll/target">two</a>
<a id="three" href="/data-sveltekit/noscroll/target" data-sveltekit-noscroll="off">three</a>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div style="height: 2000px; background: palegoldenrod" />

<h1>target</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<a id="one" href="/data-sveltekit/prefetch/target" data-sveltekit-prefetch>one</a>

<div data-sveltekit-prefetch>
<a id="two" href="/data-sveltekit/prefetch/target">two</a>
<a id="three" href="/data-sveltekit/prefetch/target" data-sveltekit-prefetch="off">three</a>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>target</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<a id="one" href="/data-sveltekit/reload/target" data-sveltekit-reload>one</a>

<div data-sveltekit-reload>
<a id="two" href="/data-sveltekit/reload/target">two</a>
<a id="three" href="/data-sveltekit/reload/target" data-sveltekit-reload="off">three</a>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>target</h1>
73 changes: 73 additions & 0 deletions packages/kit/test/apps/basics/test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,3 +690,76 @@ test.describe.serial('Invalidation', () => {
expect(await page.textContent('h1')).toBe('a: 4, b: 5');
});
});

test.describe('data-sveltekit attributes', () => {
test('data-sveltekit-prefetch', async ({ baseURL, page }) => {
const requests = [];
page.on('request', (r) => requests.push(r.url()));

await page.goto('/data-sveltekit/prefetch');
await page.locator('#one').dispatchEvent('mousemove');
await Promise.all([
page.waitForTimeout(100), // wait for prefetching to start
page.waitForLoadState('networkidle') // wait for prefetching to finish
]);
expect(requests).toContain(`${baseURL}/src/routes/data-sveltekit/prefetch/target/+page.svelte`);

requests.length = 0;
await page.goto('/data-sveltekit/prefetch');
await page.locator('#two').dispatchEvent('mousemove');
await Promise.all([
page.waitForTimeout(100), // wait for prefetching to start
page.waitForLoadState('networkidle') // wait for prefetching to finish
]);
expect(requests).toContain(`${baseURL}/src/routes/data-sveltekit/prefetch/target/+page.svelte`);

requests.length = 0;
await page.goto('/data-sveltekit/prefetch');
await page.locator('#three').dispatchEvent('mousemove');
await Promise.all([
page.waitForTimeout(100), // wait for prefetching to start
page.waitForLoadState('networkidle') // wait for prefetching to finish
]);
expect(requests).not.toContain(
`${baseURL}/src/routes/data-sveltekit/prefetch/target/+page.svelte`
);
});

test('data-sveltekit-reload', async ({ baseURL, page, clicknav }) => {
const requests = [];
page.on('request', (r) => requests.push(r.url()));

await page.goto('/data-sveltekit/reload');
await page.click('#one');
await page.waitForLoadState('networkidle');
expect(requests).toContain(`${baseURL}/src/routes/data-sveltekit/reload/target`);

requests.length = 0;
await page.goto('/data-sveltekit/reload');
await page.click('#two');
await page.waitForLoadState('networkidle');
expect(requests).toContain(`${baseURL}/src/routes/data-sveltekit/reload/target`);

requests.length = 0;
await page.goto('/data-sveltekit/reload');
await clicknav('#three');
expect(requests).not.toContain(`${baseURL}/src/routes/data-sveltekit/reload/target`);
});

test('data-sveltekit-noscroll', async ({ baseURL, page, clicknav }) => {
await page.goto('/data-sveltekit/noscroll');
// await page.evaluate(() => window.scrollTo(0, 1000));
await clicknav('#one');
expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(1000);

// await page.goto('/data-sveltekit/noscroll');
// // await page.evaluate(() => window.scrollTo(0, 1000));
// await clicknav('#two');
// expect(await page.evaluate(() => window.scrollY)).toBeGreaterThan(1000);

await page.goto('/data-sveltekit/noscroll');
// await page.evaluate(() => window.scrollTo(0, 1000));
await clicknav('#three');
expect(await page.evaluate(() => window.scrollY)).toBe(0);
});
});

0 comments on commit c899e16

Please sign in to comment.