-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(nuxt): Resolve pinia when added via layer or module
- Loading branch information
David Marr
committed
Oct 23, 2024
1 parent
6fb480e
commit db6e0c5
Showing
9 changed files
with
105 additions
and
14 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,37 @@ | ||
/** | ||
* @vitest-env node | ||
*/ | ||
import { fileURLToPath } from 'node:url' | ||
import path from 'node:path' | ||
import { describe, it, expect } from 'vitest' | ||
import { setup, $fetch } from '@nuxt/test-utils' | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
|
||
await setup({ | ||
server: true, | ||
rootDir: path.join(__dirname, '../layer/playground'), | ||
nuxtConfig: { | ||
hooks: { | ||
'vite:extendConfig'(config, { isClient }) { | ||
config.define!.__BROWSER__ = isClient | ||
}, | ||
}, | ||
vite: { | ||
define: { | ||
__DEV__: false, | ||
__TEST__: true, | ||
__FEATURE_PROD_DEVTOOLS__: false, | ||
__USE_DEVTOOLS__: false, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
describe('works with nuxt layers', async () => { | ||
it('loads stores when extending', async () => { | ||
const html = await $fetch('/') | ||
expect(html).toContain('Base store: 3') | ||
expect(html).toContain('App store: xyz') | ||
}) | ||
}) |
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,22 @@ | ||
import { dirname, join } from 'node:path' | ||
import { fileURLToPath } from 'node:url' | ||
import { defineNuxtConfig } from 'nuxt/config' | ||
import piniaModule from '../src/module' | ||
|
||
const currentDir = dirname(fileURLToPath(import.meta.url)) | ||
|
||
export default defineNuxtConfig({ | ||
modules: [piniaModule], | ||
|
||
pinia: { | ||
storesDirs: [join(currentDir, 'stores')], | ||
}, | ||
|
||
vite: { | ||
define: { | ||
__DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'), | ||
__USE_DEVTOOLS__: true, | ||
__TEST__: false, | ||
}, | ||
}, | ||
}) |
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,10 @@ | ||
<script lang="ts" setup> | ||
const baseStore = useExampleStore(); | ||
const appStore = useXYZStore(); | ||
</script> | ||
<template> | ||
<div> | ||
<p>Base store: {{ baseStore.example }}</p> | ||
<p>App store: {{ appStore.foo }}</p> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { defineNuxtConfig } from 'nuxt/config' | ||
|
||
export default defineNuxtConfig({ | ||
extends: ['..'], | ||
pinia: { | ||
storesDirs: ['xyz'], | ||
}, | ||
vite: { | ||
define: { | ||
__DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'), | ||
__USE_DEVTOOLS__: true, | ||
__TEST__: false, | ||
}, | ||
}, | ||
}) |
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,6 @@ | ||
export const useXYZStore = defineStore('xyz', () => { | ||
const foo = ref<string>('xyz') | ||
return { | ||
foo, | ||
} | ||
}) |
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,6 @@ | ||
export const useExampleStore = defineStore('example', () => { | ||
const example = ref<number>(3) | ||
return { | ||
example, | ||
} | ||
}) |
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