@@ -156,56 +156,33 @@ describe('loadConfig', () => {
156156 } ) ;
157157
158158 test ( 'fails when specified config does not exist' , async ( ) => {
159- try {
160- await loadConfig ( '{}' ) ;
161- expect . fail ( 'Config is loaded successfully' ) ;
162- } catch ( error ) {
163- expect ( error . message ) . toMatch ( / C a n n o t f i n d m o d u l e / ) ;
164- }
159+ await expect ( loadConfig ( '{}' ) ) . rejects . toThrow ( / C a n n o t f i n d m o d u l e / ) ;
165160 } ) ;
166161
167162 test ( 'fails when exported config not an object' , async ( ) => {
168- try {
169- await loadConfig ( path . join ( fixtures , 'invalid-null.js' ) ) ;
170- expect . fail ( 'Config is loaded successfully' ) ;
171- } catch ( error ) {
172- expect ( error . message ) . toMatch ( / I n v a l i d c o n f i g f i l e / ) ;
173- }
174- try {
175- await loadConfig ( path . join ( fixtures , 'invalid-array.js' ) ) ;
176- expect . fail ( 'Config is loaded successfully' ) ;
177- } catch ( error ) {
178- expect ( error . message ) . toMatch ( / I n v a l i d c o n f i g f i l e / ) ;
179- }
180- try {
181- await loadConfig ( path . join ( fixtures , 'invalid-string.js' ) ) ;
182- expect . fail ( 'Config is loaded successfully' ) ;
183- } catch ( error ) {
184- expect ( error . message ) . toMatch ( / I n v a l i d c o n f i g f i l e / ) ;
185- }
163+ await expect (
164+ loadConfig ( path . join ( fixtures , 'invalid-null.js' ) ) ,
165+ ) . rejects . toThrow ( / I n v a l i d c o n f i g f i l e / ) ;
166+ await expect (
167+ loadConfig ( path . join ( fixtures , 'invalid-array.js' ) ) ,
168+ ) . rejects . toThrow ( / I n v a l i d c o n f i g f i l e / ) ;
169+ await expect (
170+ loadConfig ( path . join ( fixtures , 'invalid-string.js' ) ) ,
171+ ) . rejects . toThrow ( / I n v a l i d c o n f i g f i l e / ) ;
186172 } ) ;
187173
188174 test ( 'handles runtime errors properly' , async ( ) => {
189- try {
190- await loadConfig ( path . join ( fixtures , 'invalid-runtime.js' ) ) ;
191- expect . fail ( 'Config is loaded successfully' ) ;
192- } catch ( error ) {
193- expect ( error . message ) . toMatch ( / p l u g i n s i s n o t d e f i n e d / ) ;
194- }
195- try {
196- await loadConfig ( path . join ( fixtures , 'invalid-runtime.mjs' ) ) ;
197- expect . fail ( 'Config is loaded successfully' ) ;
198- } catch ( error ) {
199- expect ( error . message ) . toMatch ( / p l u g i n s i s n o t d e f i n e d / ) ;
200- }
175+ await expect (
176+ loadConfig ( path . join ( fixtures , 'invalid-runtime.js' ) ) ,
177+ ) . rejects . toThrow ( / p l u g i n s i s n o t d e f i n e d / ) ;
178+ await expect (
179+ loadConfig ( path . join ( fixtures , 'invalid-runtime.mjs' ) ) ,
180+ ) . rejects . toThrow ( / p l u g i n s i s n o t d e f i n e d / ) ;
201181 } ) ;
202182
203183 test ( 'handles MODULE_NOT_FOUND properly' , async ( ) => {
204- try {
205- await loadConfig ( path . join ( fixtures , 'module-not-found.js' ) ) ;
206- expect . fail ( 'Config is loaded successfully' ) ;
207- } catch ( error ) {
208- expect ( error . message ) . toMatch ( / C a n n o t f i n d m o d u l e ' u n k n o w n - m o d u l e ' / ) ;
209- }
184+ await expect (
185+ loadConfig ( path . join ( fixtures , 'module-not-found.js' ) ) ,
186+ ) . rejects . toThrow ( / C a n n o t f i n d m o d u l e ' u n k n o w n - m o d u l e ' / ) ;
210187 } ) ;
211188} ) ;
0 commit comments