Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
fix: pass resolved runtimeConfig into nuxt environment (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankapaun committed Mar 21, 2023
1 parent 05f23da commit 6dce4dc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/nuxt-vitest/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export async function getVitestConfigFromNuxt(
test: {
...options.viteConfig.test,
dir: options.nuxt.options.rootDir,
environmentOptions: {
...options.viteConfig.test?.environmentOptions,
nuxtRuntimeConfig: options.nuxt.options.runtimeConfig,
},
environmentMatchGlobs: [
['**/*.nuxt.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', 'nuxt'],
['{test,tests}/nuxt/**.*', 'nuxt'],
Expand Down
3 changes: 2 additions & 1 deletion packages/vitest-environment-nuxt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {

export default <Environment>{
name: 'nuxt',
async setup() {
async setup(_, environmentOptions) {
const win = new (GlobalWindow || Window)() as any as Window & {
__app: App
__registry: Set<string>
Expand All @@ -26,6 +26,7 @@ export default <Environment>{
config: {
public: {},
app: { baseURL: '/' },
...environmentOptions?.nuxtRuntimeConfig
},
data: {},
state: {},
Expand Down
5 changes: 5 additions & 0 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ export default defineNuxtConfig({
},
},
},
runtimeConfig: {
public: {
hello: 'world',
},
}
})
9 changes: 9 additions & 0 deletions playground/tests/nuxt/config.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { it, expect } from 'vitest'

it('should return the runtimeConfig from nuxt.config', () => {
const config = useRuntimeConfig();
expect(config).toBeTypeOf('object');
expect(config?.public).toEqual({
hello: 'world'
})
})

0 comments on commit 6dce4dc

Please sign in to comment.