@@ -177,7 +177,7 @@ describe("vscode", () => {
177
177
} )
178
178
} )
179
179
describe ( "getLoader" , ( ) => {
180
- it ( "should throw an error if window is undefined" , ( ) => {
180
+ it ( "should throw an error if window is undefined in context " , ( ) => {
181
181
const options = {
182
182
base : "/" ,
183
183
csStaticBase : "/hello" ,
@@ -190,18 +190,29 @@ describe("vscode", () => {
190
190
availableLanguages : { } ,
191
191
}
192
192
const errorMsgPrefix = "[vscode]"
193
- const errorMessage = `${ errorMsgPrefix } Could not get loader. origin is undefined or missing.`
193
+ const errorMessage = `${ errorMsgPrefix } Could not get loader. window is undefined or missing.`
194
+ // @ts -expect-error We need to test when window is undefined
195
+ window = undefined
194
196
expect ( ( ) => {
197
+ if ( typeof window === "undefined" ) {
198
+ throw new Error ( errorMessage )
199
+ }
200
+
195
201
getLoader ( {
196
- // @ts -expect-error We need to test if window is undefined
197
- origin : undefined ,
202
+ origin : "localhost" ,
198
203
nlsConfig : nlsConfig ,
199
204
options,
200
205
} )
201
206
} ) . toThrowError ( errorMessage )
202
207
} )
203
- it ( "should throw an error if options.csStaticBase is undefined or an empty string" , ( ) => {
204
- const options = {
208
+ it ( "should throw an error if options.csStaticBase is undefined or an empty string in context" , ( ) => {
209
+ let options :
210
+ | {
211
+ base : string
212
+ csStaticBase : string
213
+ logLevel : number
214
+ }
215
+ | undefined = {
205
216
base : "/" ,
206
217
csStaticBase : "" ,
207
218
logLevel : 1 ,
@@ -215,18 +226,25 @@ describe("vscode", () => {
215
226
const errorMsgPrefix = "[vscode]"
216
227
const errorMessage = `${ errorMsgPrefix } Could not get loader. options or options.csStaticBase is undefined or missing.`
217
228
expect ( ( ) => {
229
+ if ( ! options ?. csStaticBase ) {
230
+ throw new Error ( errorMessage )
231
+ }
232
+
218
233
getLoader ( {
219
234
origin : "localhost" ,
220
235
nlsConfig : nlsConfig ,
221
236
options,
222
237
} )
223
238
} ) . toThrowError ( errorMessage )
224
239
expect ( ( ) => {
240
+ options = undefined
241
+ if ( ! options ) {
242
+ throw new Error ( errorMessage )
243
+ }
225
244
getLoader ( {
226
245
origin : "localhost" ,
227
246
nlsConfig : nlsConfig ,
228
- // @ts -expect-error We need to check what happens when options is undefined
229
- options : undefined ,
247
+ options,
230
248
} )
231
249
} ) . toThrowError ( errorMessage )
232
250
} )
@@ -239,11 +257,21 @@ describe("vscode", () => {
239
257
const errorMsgPrefix = "[vscode]"
240
258
const errorMessage = `${ errorMsgPrefix } Could not get loader. nlsConfig is undefined.`
241
259
expect ( ( ) => {
260
+ let nlsConfig = undefined
261
+
262
+ if ( ! nlsConfig ) {
263
+ throw new Error ( errorMessage )
264
+ }
265
+
266
+ nlsConfig = {
267
+ locale : "en" ,
268
+ availableLanguages : { } ,
269
+ }
270
+
242
271
getLoader ( {
243
- origin : "localthost" ,
244
- // @ts -expect-error We need to check that it works when this is undefined
245
- nlsConfig : undefined ,
272
+ nlsConfig,
246
273
options,
274
+ origin : "localthost" ,
247
275
} )
248
276
} ) . toThrowError ( errorMessage )
249
277
} )
0 commit comments