File tree Expand file tree Collapse file tree 5 files changed +30
-6
lines changed Expand file tree Collapse file tree 5 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 11{
22  "private" : true ,
3+   "name" : " module" 
34  "description" : " My new Nuxt module" 
45  "repository" : " your-org/my-module" 
56  "license" : " MIT" 
Original file line number Diff line number Diff line change 11import  {  fileURLToPath  }  from  'node:url' 
22import  {  describe ,  expect ,  it  }  from  'vitest' 
3- import  {  $fetch ,  setup  }  from  '@nuxt/test-utils/e2e' 
3+ import  {  $fetch ,  setup ,   startServer  }  from  '@nuxt/test-utils/e2e' 
44
55describe ( 'ssr' ,  async  ( )  =>  { 
66  await  setup ( { 
@@ -10,6 +10,17 @@ describe('ssr', async () => {
1010  it ( 'renders the index page' ,  async  ( )  =>  { 
1111    // Get response to a server-rendered page with `$fetch`. 
1212    const  html  =  await  $fetch ( '/' ) 
13-     expect ( html ) . toContain ( '<div>basic</div>' ) 
13+     expect ( html ) . toContain ( '<div>basic <span>original value</span></div>' ) 
14+   } ) 
15+ 
16+   it ( 'changes runtime config and restarts' ,  async  ( )  =>  { 
17+     await  startServer ( {  env : {  NUXT_PUBLIC_MY_VALUE : 'overwritten by test!'  }  } ) 
18+ 
19+     const  html  =  await  $fetch ( '/' ) 
20+     expect ( html ) . toContain ( '<div>basic <span>overwritten by test!</span></div>' ) 
21+ 
22+     await  startServer ( ) 
23+     const  htmlRestored  =  await  $fetch ( '/' ) 
24+     expect ( htmlRestored ) . toContain ( '<div>basic <span>original value</span></div>' ) 
1425  } ) 
1526} ) 
Original file line number Diff line number Diff line change 11<template >
2-   <div >basic</div >
2+   <div >basic < span >{{ config.public.myValue }}</ span > </div >
33</template >
44
55<script  setup>
6+ const  config  =  useRuntimeConfig ();
67script >
Original file line number Diff line number Diff line change 11import  MyModule  from  '../../../src/module' 
22
33export  default  defineNuxtConfig ( { 
4+   runtimeConfig : { 
5+     public : { 
6+       myValue : 'original value' , 
7+     } , 
8+   } , 
49  modules : [ 
510    MyModule 
611  ] 
Original file line number Diff line number Diff line change @@ -10,7 +10,11 @@ import { useTestContext } from './context'
1010// eslint-disable-next-line 
1111const  kit : typeof  _kit  =  _kit . default  ||  _kit 
1212
13- export  async  function  startServer  ( )  { 
13+ export  interface  StartServerOptions  { 
14+   env ?: Record < string ,  unknown > 
15+ } 
16+ 
17+ export  async  function  startServer  ( options : StartServerOptions  =  { } )  { 
1418  const  ctx  =  useTestContext ( ) 
1519  await  stopServer ( ) 
1620  const  host  =  '127.0.0.1' 
@@ -26,7 +30,8 @@ export async function startServer () {
2630        _PORT : String ( port ) ,  // Used by internal _dev command 
2731        PORT : String ( port ) , 
2832        HOST : host , 
29-         NODE_ENV : 'development' 
33+         NODE_ENV : 'development' , 
34+         ...options . env 
3035      } 
3136    } ) 
3237    await  waitForPort ( port ,  {  retries : 32 ,  host } ) . catch ( ( )  =>  { } ) 
@@ -53,7 +58,8 @@ export async function startServer () {
5358        ...process . env , 
5459        PORT : String ( port ) , 
5560        HOST : host , 
56-         NODE_ENV : 'test' 
61+         NODE_ENV : 'test' , 
62+         ...options . env 
5763      } 
5864    } ) 
5965    await  waitForPort ( port ,  {  retries : 20 ,  host } ) 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments