File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -103,23 +103,26 @@ export const define: Define = {
103103
104104export const loadRstackConfig = async ( ) : Promise < Configs > => {
105105 const state = getConfigState ( ) ;
106+ state . configs = { } ;
106107
107- await loadConfig ( {
108- loader : 'native' ,
109- exportName : false ,
110- ...( state . configPath !== undefined
111- ? { path : state . configPath }
112- : {
113- configFileNames : [
114- 'rstack.config.ts' ,
115- 'rstack.config.js' ,
116- 'rstack.config.mts' ,
117- 'rstack.config.mjs' ,
118- ] ,
119- } ) ,
120- } ) ;
108+ try {
109+ await loadConfig ( {
110+ loader : 'native' ,
111+ exportName : false ,
112+ ...( state . configPath !== undefined
113+ ? { path : state . configPath }
114+ : {
115+ configFileNames : [
116+ 'rstack.config.ts' ,
117+ 'rstack.config.js' ,
118+ 'rstack.config.mts' ,
119+ 'rstack.config.mjs' ,
120+ ] ,
121+ } ) ,
122+ } ) ;
121123
122- const result = state . configs ;
123- state . configs = { } ;
124- return result ;
124+ return state . configs ;
125+ } finally {
126+ state . configs = { } ;
127+ }
125128} ;
Original file line number Diff line number Diff line change 1+ import path from 'node:path' ;
2+ import { expect , test } from 'rstack/test' ;
3+ import { getConfigState , loadRstackConfig } from '../../../src/config.ts' ;
4+
5+ test ( 'should reset config state before and after loading' , async ( ) => {
6+ const state = getConfigState ( ) ;
7+ state . configs = { app : { } } ;
8+ state . configPath = path . join ( import . meta. dirname , 'rstack.config.ts' ) ;
9+
10+ try {
11+ await expect ( loadRstackConfig ( ) ) . rejects . toThrow ( 'test config error' ) ;
12+ expect ( state . configs ) . toEqual ( { } ) ;
13+ } finally {
14+ state . configs = { } ;
15+ delete state . configPath ;
16+ }
17+ } ) ;
Original file line number Diff line number Diff line change 1+ import { define } from 'rstack' ;
2+
3+ define . app ( { } ) ;
4+ throw new Error ( 'test config error' ) ;
You can’t perform that action at this time.
0 commit comments