-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor refactor vike-vue-query (#196)
- Loading branch information
Showing
21 changed files
with
92 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
import { test, expect, run, fetchHtml, page, getServerUrl } from '@brillout/test-e2e' | ||
import { test, expect, run, fetchHtml, page, getServerUrl, autoRetry } from '@brillout/test-e2e' | ||
|
||
runTest() | ||
|
||
const fetchedText = 'A New Hope' | ||
const url = '/' | ||
|
||
function runTest() { | ||
run('pnpm run dev') | ||
|
||
const textLandingPage = 'A New Hope' | ||
const title = 'Star Wars Movies' | ||
testUrl({ | ||
url: '/', | ||
title, | ||
text: textLandingPage, | ||
}) | ||
} | ||
|
||
function testUrl({ url, title, text }: { url: string; title: string; text: string }) { | ||
test(url + ' (HTML)', async () => { | ||
test('HTML', async () => { | ||
const html = await fetchHtml(url) | ||
expect(html).toContain(text) | ||
expect(getTitle(html)).toBe(title) | ||
expect(html).toContain(fetchedText) | ||
}) | ||
test(url + ' (Hydration)', async () => { | ||
|
||
test('Hydration', async () => { | ||
await page.goto(getServerUrl() + url) | ||
const body = await page.textContent('body') | ||
expect(body).toContain(text) | ||
await testDOM() | ||
}) | ||
|
||
test('Navigation', async () => { | ||
await page.click('a[href="/about"]') | ||
await page.click('a[href="/"]') | ||
await testDOM() | ||
}) | ||
} | ||
|
||
async function testDOM() { | ||
await testCounter() | ||
const body = await page.textContent('body') | ||
expect(body).toContain(fetchedText) | ||
} | ||
|
||
function getTitle(html: string) { | ||
const title = html.match(/<title>(.*?)<\/title>/i)?.[1] | ||
return title | ||
async function testCounter() { | ||
// autoRetry() for awaiting client-side code loading & executing | ||
await autoRetry( | ||
async () => { | ||
expect(await page.textContent('button')).toBe('Counter 0') | ||
await page.click('button') | ||
expect(await page.textContent('button')).toContain('Counter 1') | ||
}, | ||
{ timeout: 5 * 1000 }, | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
import type { Config } from 'vike/types' | ||
import Layout from '../layouts/LayoutDefault.vue' | ||
import Head from '../layouts/HeadDefault.vue' | ||
import vikeVue from 'vike-vue/config' | ||
import vikeVueQuery from 'vike-vue-query/config' | ||
|
||
// Default configs (can be overridden by pages) | ||
export default { | ||
Layout, | ||
Head, | ||
// <title> | ||
title: 'My Vike + Vue + TanStack Query App', | ||
|
||
extends: [vikeVue, vikeVueQuery], | ||
} satisfies Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<template> | ||
<h1>About</h1> | ||
<p>Example of using TanStack Query.</p> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,7 +51,7 @@ | |
"vue-tsc": "^2.0.13" | ||
}, | ||
"files": [ | ||
"dist" | ||
"dist/" | ||
], | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export { onAfterRenderHtml } | ||
|
||
import { dehydrate } from '@tanstack/vue-query' | ||
import type { OnAfterRenderHtmlSync } from 'vike-vue/types' | ||
|
||
const onAfterRenderHtml: OnAfterRenderHtmlSync = (pageContext): ReturnType<OnAfterRenderHtmlSync> => { | ||
dehydrateVueQuery(pageContext) | ||
} | ||
|
||
type PageContext = Parameters<typeof onAfterRenderHtml>[0] | ||
function dehydrateVueQuery(pageContext: PageContext) { | ||
pageContext._vueQueryInitialState = dehydrate(pageContext.queryClient!) | ||
} |
9 changes: 7 additions & 2 deletions
9
...-vue-query/integration/hydrateVueQuery.ts → ...query/integration/onBeforeRenderClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
...-vue-query/integration/installVueQuery.ts → ...vike-vue-query/integration/onCreateApp.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.