Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as assert from 'uvu/assert';
export default function (test) {
// TODO unskip this
test.skip('resets focus', '/accessibility/a', async ({ page }) => {
await page.click('[href="/accessibility/b"]');
await Promise.all([page.waitForNavigation(), page.click('[href="/accessibility/b"]')]);
await page.waitForTimeout(50);
assert.equal(await page.innerHTML('h1'), 'b');
await page.waitForTimeout(50);
Expand All @@ -14,7 +14,7 @@ export default function (test) {
assert.equal(await page.evaluate(() => document.activeElement.nodeName), 'A');
assert.equal(await page.evaluate(() => document.activeElement.textContent), 'a');

await page.click('[href="/accessibility/a"]');
await Promise.all([page.waitForNavigation(), page.click('[href="/accessibility/a"]')]);
await page.waitForTimeout(50);
assert.equal(await page.innerHTML('h1'), 'a');
assert.equal(await page.evaluate(() => document.activeElement.nodeName), 'BODY');
Expand All @@ -33,7 +33,7 @@ export default function (test) {
// live region should exist, but be empty
assert.equal(await page.innerHTML('[aria-live]'), '');

await page.click('[href="/accessibility/b"]');
await Promise.all([page.waitForNavigation(), page.click('[href="/accessibility/b"]')]);
await page.waitForTimeout(50);
assert.equal(await page.innerHTML('[aria-live]'), 'Navigated to b'); // TODO i18n
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'uvu/assert';
/** @type {import('../../../../../types').TestMaker} */
export default function test(test) {
test('errors on preload', '/preload', async ({ page }) => {
await page.click('[href="/preload/uses-preload"]');
await Promise.all([page.waitForNavigation(), page.click('[href="/preload/uses-preload"]')]);

assert.equal(await page.textContent('h1'), '500');
assert.equal(await page.textContent('footer'), 'Custom layout');
Expand Down
12 changes: 9 additions & 3 deletions packages/kit/test/apps/basics/src/routes/redirect/__tests__.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'uvu/assert';
/** @type {import('../../../../../types').TestMaker} */
export default function (test, is_dev) {
test('redirect', '/redirect', async ({ base, page, js }) => {
await page.click('[href="/redirect/a"]');
await Promise.all([page.waitForNavigation(), page.click('[href="/redirect/a"]')]);

if (js) await page.waitForTimeout(50);

Expand All @@ -30,7 +30,10 @@ export default function (test, is_dev) {
});

test('errors on missing status', '/redirect', async ({ base, page, js }) => {
await page.click('[href="/redirect/missing-status/a"]');
await Promise.all([
page.waitForNavigation(),
page.click('[href="/redirect/missing-status/a"]')
]);

if (js) await page.waitForTimeout(50);

Expand All @@ -43,7 +46,10 @@ export default function (test, is_dev) {
});

test('errors on invalid status', '/redirect', async ({ base, page, js }) => {
await page.click('[href="/redirect/missing-status/b"]');
await Promise.all([
page.waitForNavigation(),
page.click('[href="/redirect/missing-status/b"]')
]);

if (js) await page.waitForTimeout(50);

Expand Down
25 changes: 14 additions & 11 deletions packages/kit/test/apps/basics/src/routes/routing/__tests__.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function (test) {
'redirects from /routing/ to /routing',
'/routing/slashes',
async ({ base, page, app, js }) => {
await page.click('a[href="/routing/"]');
await Promise.all([page.waitForNavigation(), page.click('a[href="/routing/"]')]);
assert.equal(await page.url(), `${base}/routing`);
assert.equal(await page.textContent('h1'), 'Great success!');

Expand All @@ -24,7 +24,7 @@ export default function (test) {
'redirects from /routing/? to /routing',
'/routing/slashes',
async ({ base, page, app, js }) => {
await page.click('a[href="/routing/?"]');
await Promise.all([page.waitForNavigation(), page.click('a[href="/routing/?"]')]);
assert.equal(await page.url(), `${base}/routing`);
assert.equal(await page.textContent('h1'), 'Great success!');

Expand All @@ -42,7 +42,7 @@ export default function (test) {
'redirects from /routing/?foo=bar to /routing?foo=bar',
'/routing/slashes',
async ({ base, page, app, js }) => {
await page.click('a[href="/routing/?foo=bar"]');
await Promise.all([page.waitForNavigation(), page.click('a[href="/routing/?foo=bar"]')]);
assert.equal(await page.url(), `${base}/routing?foo=bar`);
assert.equal(await page.textContent('h1'), 'Great success!');

Expand Down Expand Up @@ -97,7 +97,7 @@ export default function (test) {
await page.waitForTimeout(500);

const requests = await capture_requests(async () => {
await page.click('a[href="/routing/a"]');
await Promise.all([page.waitForNavigation(), page.click('a[href="/routing/a"]')]);

await page.waitForFunction(() => document.location.pathname == '/routing/a');

Expand Down Expand Up @@ -126,7 +126,10 @@ export default function (test) {
});

test('does not attempt client-side navigation to server routes', '/routing', async ({ page }) => {
await page.click('[href="/routing/ambiguous/ok.json"]');
await Promise.all([
page.waitForNavigation(),
page.click('[href="/routing/ambiguous/ok.json"]')
]);
await page.waitForFunction(() => document.location.pathname == '/routing/ambiguous/ok.json');

assert.equal(await page.textContent('body'), 'ok');
Expand All @@ -137,13 +140,13 @@ export default function (test) {
});

test('resets the active element after navigation', '/routing', async ({ page }) => {
await page.click('[href="/routing/a"]');
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/a"]')]);
await page.waitForFunction(() => document.activeElement.nodeName == 'BODY');
});

test('navigates between routes with empty parts', '/routing/dirs/foo', async ({ page }) => {
assert.equal(await page.textContent('h1'), 'foo');
await page.click('[href="bar"]');
await Promise.all([page.waitForNavigation(), page.click('[href="bar"]')]);
await page.waitForSelector('.bar');

assert.equal(await page.textContent('h1'), 'bar');
Expand Down Expand Up @@ -182,25 +185,25 @@ export default function (test) {
async ({ page }) => {
assert.equal(await page.textContent('h1'), 'A page');

await page.click('[href="/routing/dirs/foo/xyz"]');
await Promise.all([page.waitForNavigation(), page.click('[href="/routing/dirs/foo/xyz"]')]);
assert.equal(await page.textContent('h1'), 'B page');
}
);

test('find regexp routes', '/routing/qwe', async ({ page }) => {
assert.equal(await page.textContent('h1'), 'qwe');

await page.click('[href="234"]');
await Promise.all([page.waitForNavigation(), page.click('[href="234"]')]);
assert.equal(await page.textContent('h1'), 'Regexp page 234');

await page.click('[href="regexp/234"]');
await Promise.all([page.waitForNavigation(), page.click('[href="regexp/234"]')]);
assert.equal(await page.textContent('h1'), 'Nested regexp page 234');
});

test('invalidates page when a segment is skipped', '/routing/skipped/x/1', async ({ page }) => {
assert.equal(await page.textContent('h1'), 'x/1');

await page.click('#goto-y1');
await Promise.all([page.waitForNavigation(), page.click('#goto-y1')]);
assert.equal(await page.textContent('h1'), 'y/1');
});
}
3 changes: 2 additions & 1 deletion packages/kit/test/apps/basics/src/routes/store/__tests__.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as assert from 'uvu/assert';
/** @type {import('../../../../../types').TestMaker} */
export default function (test) {
test('page store functions as expected', '/store', async ({ page, js }) => {
await page.waitForLoadState();
assert.equal(await page.textContent('h1'), 'Test');
assert.equal(await page.textContent('h2'), 'Calls: 1');

Expand All @@ -18,7 +19,7 @@ export default function (test) {
assert.equal(await page.textContent('#navigating'), 'not currently navigating');

if (js) {
await page.click('a[href="/store/navigating/b"]');
await Promise.all([page.waitForNavigation(), page.click('a[href="/store/navigating/b"]')]);

assert.equal(
await page.textContent('#navigating'),
Expand Down