-
-
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-pinia (#195)
- Loading branch information
Showing
16 changed files
with
109 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { test, expect, run, fetchHtml, page, getServerUrl, autoRetry } from '@brillout/test-e2e' | ||
|
||
runTest() | ||
|
||
const counter1 = 'button#counter-1' | ||
const counter2 = 'button#counter-2' | ||
const counter3 = 'button#counter-3' | ||
|
||
function runTest() { | ||
run('pnpm run dev') | ||
|
||
test('initial state', async () => { | ||
const url = '/' | ||
const html = await fetchHtml(url) | ||
expect(html).toContain('<button type="button" id="counter-1">Counter 1</button>') | ||
expect(html).toContain('<button type="button" id="counter-2">Counter 1</button>') | ||
await page.goto(getServerUrl() + url) | ||
expect(await page.textContent(counter1)).toBe('Counter 1') | ||
expect(await page.textContent(counter2)).toBe('Counter 1') | ||
}) | ||
|
||
test('synced state', async () => { | ||
// autoRetry() for awaiting client-side code loading & executing | ||
await autoRetry( | ||
async () => { | ||
expect(await page.textContent(counter1)).toBe('Counter 1') | ||
await page.click(counter1) | ||
expect(await page.textContent(counter1)).toContain('Counter 2') | ||
}, | ||
{ timeout: 5 * 1000 }, | ||
) | ||
expect(await page.textContent(counter1)).toBe('Counter 2') | ||
expect(await page.textContent(counter2)).toBe('Counter 2') | ||
}) | ||
|
||
test('preserved state upon client-side navigation', async () => { | ||
await page.click('a[href="/about"]') | ||
expect(await page.textContent(counter3)).toBe('Counter 2') | ||
await page.click(counter3) | ||
expect(await page.textContent(counter3)).toContain('Counter 3') | ||
await page.click('a[href="/"]') | ||
expect(await page.textContent(counter1)).toBe('Counter 3') | ||
expect(await page.textContent(counter2)).toBe('Counter 3') | ||
}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +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 vikeVuePinia from 'vike-vue-pinia/config' | ||
|
||
// Default configs (can be overridden by pages) | ||
export default { | ||
Layout, | ||
Head, | ||
// <title> | ||
title: 'My Vike + Vue + Pinia App', | ||
extends: [vikeVue, vikeVuePinia], | ||
} satisfies Config |
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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
<template> | ||
<h1>About</h1> | ||
<p>Example of using Vike.</p> | ||
<p>Example of using Pinia.</p> | ||
<Counter id="counter-3" /> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import Counter from '../../components/Counter.vue' | ||
</script> |
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,14 +1,9 @@ | ||
export { config as default } | ||
|
||
import vue from '@vitejs/plugin-vue' | ||
import vike from 'vike/plugin' | ||
import { UserConfig } from 'vite' | ||
|
||
const config: UserConfig = { | ||
plugins: [ | ||
vike({ prerender: true }), | ||
vue({ | ||
include: [/\.vue$/, /\.md$/], | ||
}), | ||
], | ||
plugins: [vike(), vue()], | ||
} | ||
|
||
export default 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 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 type { OnAfterRenderHtmlSync } from 'vike-vue/types' | ||
|
||
const onAfterRenderHtml: OnAfterRenderHtmlSync = (pageContext): ReturnType<OnAfterRenderHtmlSync> => { | ||
return dehydratePinia(pageContext) | ||
} | ||
|
||
type PageContext = Parameters<typeof onAfterRenderHtml>[0] | ||
function dehydratePinia(pageContext: PageContext) { | ||
const { pinia } = pageContext | ||
return { piniaInitialState: pinia!.state.value } | ||
} |
15 changes: 9 additions & 6 deletions
15
...ike-vue-pinia/integration/hydratePinia.ts → ...pinia/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
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,15 @@ | ||
export { onCreateApp } | ||
|
||
import { createPinia } from 'pinia' | ||
import type { OnCreateAppSync } from 'vike-vue/types' | ||
|
||
const onCreateApp: OnCreateAppSync = (pageContext): ReturnType<OnCreateAppSync> => { | ||
installPinia(pageContext) | ||
} | ||
|
||
type PageContext = Parameters<typeof onCreateApp>[0] | ||
function installPinia(pageContext: PageContext) { | ||
const pinia = createPinia() | ||
pageContext.app.use(pinia) | ||
Object.assign(pageContext, { pinia }) | ||
} |
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