File tree 3 files changed +34
-4
lines changed
3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,17 @@ describe('config', () => {
189
189
JunoPluginError
190
190
) ;
191
191
} ) ;
192
+
193
+ it ( 'throws if config is undefined in satelliteId' , async ( ) => {
194
+ vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( true ) ;
195
+ vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValue (
196
+ undefined as unknown as JunoConfig
197
+ ) ;
198
+
199
+ await expect ( ( ) => satelliteId ( { params : { } , mode : 'production' } ) ) . rejects . toThrow (
200
+ / N o c o n f i g u r a t i o n e x p o r t e d /
201
+ ) ;
202
+ } ) ;
192
203
} ) ;
193
204
} ) ;
194
205
Original file line number Diff line number Diff line change @@ -34,6 +34,12 @@ export const satelliteId = async (args: ConfigArgs): Promise<string> => {
34
34
const junoConfigSatelliteId = async ( { mode} : ConfigArgs ) : Promise < string > => {
35
35
await assertJunoConfig ( ) ;
36
36
37
+ const config = await readJunoConfig ( { mode} ) ;
38
+
39
+ if ( config === undefined || ! ( 'satellite' in config ) ) {
40
+ throw new JunoPluginError ( `No configuration exported for ${ mode } .` ) ;
41
+ }
42
+
37
43
const {
38
44
satellite : { ids, satelliteId : deprecatedSatelliteId , id}
39
45
} = await readJunoConfig ( { mode} ) ;
@@ -62,9 +68,15 @@ const containerSatelliteId = async ({mode}: ConfigArgs): Promise<string> => {
62
68
return DOCKER_SATELLITE_ID ;
63
69
}
64
70
71
+ const config = await readJunoConfig ( { mode} ) ;
72
+
73
+ if ( config == undefined || ! ( 'satellite' in config ) ) {
74
+ return DOCKER_SATELLITE_ID ;
75
+ }
76
+
65
77
const {
66
78
satellite : { ids}
67
- } = await readJunoConfig ( { mode } ) ;
79
+ } = config ;
68
80
69
81
return ids ?. [ MODE_DEVELOPMENT ] ?? DOCKER_SATELLITE_ID ;
70
82
} ;
Original file line number Diff line number Diff line change @@ -206,12 +206,19 @@ describe('init', () => {
206
206
} ) ;
207
207
208
208
it ( 'throws if satelliteId is missing in config in production' , async ( ) => {
209
- vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValueOnce ( {
210
- satellite : { }
211
- } as unknown as JunoConfig ) ;
209
+ vi . spyOn ( configLoader , 'readJunoConfig' ) . mockImplementation (
210
+ // eslint-disable-next-line require-await
211
+ async ( ) => ( { satellite : { } } ) as unknown as JunoConfig
212
+ ) ;
212
213
213
214
await expect ( initConfig ( args ) ) . rejects . toThrow (
214
215
'Your project needs a Satellite for production. Create one at https://console.juno.build and set its ID in your configuration file.'
215
216
) ;
216
217
} ) ;
218
+
219
+ it ( 'throws if readJunoConfig returns undefined' , async ( ) => {
220
+ vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValue ( undefined as unknown as JunoConfig ) ;
221
+
222
+ await expect ( initConfig ( args ) ) . rejects . toThrow ( 'No configuration exported for production.' ) ;
223
+ } ) ;
217
224
} ) ;
You can’t perform that action at this time.
0 commit comments