@@ -58,7 +58,7 @@ describe('Config', () => {
58
58
// Check that activation message contains expected text (may have ANSI codes)
59
59
// Strip ANSI escape sequences for testing
60
60
const ansiEscapeRegex = new RegExp ( `${ String . fromCharCode ( 27 ) } \\[[\\d;]*m` , 'g' )
61
- const cleanMessage = defaultConfig . shellActivationMessage . replace ( ansiEscapeRegex , '' )
61
+ const cleanMessage = defaultConfig . shellActivationMessage ? .replace ( ansiEscapeRegex , '' ) || ''
62
62
expect ( cleanMessage ) . toContain ( 'Environment activated for {path}' )
63
63
expect ( defaultConfig . shellDeactivationMessage ) . toBe ( '⚪ Environment deactivated' )
64
64
} )
@@ -88,10 +88,10 @@ describe('Config', () => {
88
88
89
89
it ( 'should have valid installation path' , ( ) => {
90
90
expect ( typeof defaultConfig . installPath ) . toBe ( 'string' )
91
- expect ( defaultConfig . installPath ? .length ) . toBeGreaterThan ( 0 )
91
+ expect ( defaultConfig . installPath ! . length ) . toBeGreaterThan ( 0 )
92
92
93
93
expect ( defaultConfig . shimPath ) . toBeDefined ( )
94
- expect ( defaultConfig . shimPath ? .length ) . toBeGreaterThan ( 0 )
94
+ expect ( defaultConfig . shimPath ! . length ) . toBeGreaterThan ( 0 )
95
95
} )
96
96
97
97
it ( 'should have activation message with path placeholder' , ( ) => {
@@ -175,7 +175,7 @@ describe('Config', () => {
175
175
it ( 'should have reasonable values' , ( ) => {
176
176
expect ( config . maxRetries ) . toBeGreaterThan ( 0 )
177
177
expect ( config . timeout ) . toBeGreaterThan ( 0 )
178
- expect ( config . installPath ? .length ) . toBeGreaterThan ( 0 )
178
+ expect ( ( config . installPath ?? '' ) . length ) . toBeGreaterThan ( 0 )
179
179
expect ( config . shimPath ?. length ) . toBeGreaterThan ( 0 )
180
180
// Shell message validation
181
181
expect ( config . shellActivationMessage ?. length ) . toBeGreaterThan ( 0 )
@@ -186,7 +186,7 @@ describe('Config', () => {
186
186
expect ( config ) . toBeDefined ( )
187
187
expect ( config . installPath ) . toBeDefined ( )
188
188
expect ( typeof config . installPath ) . toBe ( 'string' )
189
- expect ( config . installPath . length ) . toBeGreaterThan ( 0 )
189
+ expect ( ( config . installPath ?? '' ) . length ) . toBeGreaterThan ( 0 )
190
190
191
191
expect ( config . shimPath ) . toBeDefined ( )
192
192
expect ( config . shimPath ?. length ) . toBeGreaterThan ( 0 )
@@ -209,18 +209,18 @@ describe('Config', () => {
209
209
it ( 'should have valid message content' , ( ) => {
210
210
const message = config . shellActivationMessage
211
211
expect ( message ) . toBeDefined ( )
212
- expect ( message ? .length ) . toBeGreaterThan ( 0 )
212
+ expect ( ( message ?? '' ) . length ) . toBeGreaterThan ( 0 )
213
213
214
214
const deactivationMessage = config . shellDeactivationMessage
215
215
expect ( deactivationMessage ) . toBeDefined ( )
216
- expect ( deactivationMessage ? .length ) . toBeGreaterThan ( 0 )
216
+ expect ( ( deactivationMessage ?? '' ) . length ) . toBeGreaterThan ( 0 )
217
217
} )
218
218
219
219
it ( 'should have valid shell message format' , ( ) => {
220
220
if ( config . shellActivationMessage ?. includes ( '{path}' ) ) {
221
221
// Test that the message contains valid characters
222
- const validChars = / ^ [ a - z A - Z 0 - 9 \s \x1B \[ [ 0 - 9 ; ] * [ a - z A - Z ] \{ \ }\- \_ \. \, \: \; \? \! \( \) \ [\] \| \/ \ ~` @ # $ % ^ & * + = < > " ' ] + $ /
223
- expect ( validChars . test ( config . shellActivationMessage || '' ) ) . toBe ( true )
222
+ const validChars = / ^ [ \w \s { } \- . , : ; ? ! ( ) [ \] | / ~ ` @ # $ % ^ & * + = < > " ' ] + $ /
223
+ expect ( validChars . test ( config . shellActivationMessage ?? '' ) ) . toBe ( true )
224
224
225
225
// Test for specific characters that should be present
226
226
const requiredChars = [ '{' , '}' , 'p' , 'a' , 't' , 'h' ]
@@ -233,8 +233,8 @@ describe('Config', () => {
233
233
234
234
if ( config . shellDeactivationMessage ) {
235
235
// Test that the message contains valid characters
236
- const validChars = / ^ [ a - z A - Z 0 - 9 \s \x1B \[ [ 0 - 9 ; ] * [ a - z A - Z ] \{ \ }\- \_ \. \, \: \; \? \! \( \) \ [\] \| \/ \ ~` @ # $ % ^ & * + = < > " ' ] + $ /
237
- expect ( validChars . test ( config . shellDeactivationMessage || '' ) ) . toBe ( true )
236
+ const validChars = / ^ [ \w \s { } \- . , : ; ? ! ( ) [ \] | / ~ ` @ # $ % ^ & * + = < > " ' ] + $ /
237
+ expect ( validChars . test ( config . shellDeactivationMessage ?? '' ) ) . toBe ( true )
238
238
}
239
239
240
240
expect ( config . shellActivationMessage ?. trim ( ) . length ) . toBeGreaterThan ( 0 )
@@ -250,15 +250,15 @@ describe('Config', () => {
250
250
it ( 'should have valid shim path' , ( ) => {
251
251
const homePath = process . env . HOME || process . env . USERPROFILE || '~'
252
252
const isUnderHome = config . shimPath ?. startsWith ( homePath ) || config . shimPath ?. startsWith ( '~' )
253
- const isUnderInstall = config . shimPath ? .startsWith ( config . installPath )
253
+ const isUnderInstall = ( config . shimPath ?? '' ) . startsWith ( config . installPath ?? '' )
254
254
255
255
expect ( config . shimPath ) . toBeDefined ( )
256
256
expect ( config . shimPath ?. length ) . toBeGreaterThan ( 0 )
257
257
expect ( isUnderHome || isUnderInstall ) . toBe ( true )
258
258
} )
259
259
260
260
it ( 'should have valid configuration structure' , ( ) => {
261
- expect ( config . installPath . length ) . toBeGreaterThan ( 0 )
261
+ expect ( ( config . installPath ?? '' ) . length ) . toBeGreaterThan ( 0 )
262
262
expect ( config . shimPath ?. length ) . toBeGreaterThan ( 0 )
263
263
} )
264
264
} )
@@ -279,23 +279,23 @@ describe('Config', () => {
279
279
it ( 'should handle custom activation messages' , ( ) => {
280
280
// The activation message should be customizable
281
281
const message = config . shellActivationMessage
282
- expect ( message . length ) . toBeGreaterThan ( 0 )
282
+ expect ( ( message ?? '' ) . length ) . toBeGreaterThan ( 0 )
283
283
// Should be a valid string that can be used in shell scripts
284
284
expect ( message ) . not . toContain ( '\n' )
285
285
} )
286
286
287
287
it ( 'should handle custom deactivation messages' , ( ) => {
288
288
// The deactivation message should be customizable
289
289
const message = config . shellDeactivationMessage
290
- expect ( message . length ) . toBeGreaterThan ( 0 )
290
+ expect ( ( message ?? '' ) . length ) . toBeGreaterThan ( 0 )
291
291
// Should be a valid string that can be used in shell scripts
292
292
expect ( message ) . not . toContain ( '\n' )
293
293
} )
294
294
295
295
it ( 'should preserve {path} placeholder in activation message' , ( ) => {
296
296
// If the activation message contains {path}, it should be preserved
297
- if ( config . shellActivationMessage . includes ( '{path}' ) ) {
298
- expect ( config . shellActivationMessage ) . toContain ( '{path}' )
297
+ if ( ( config . shellActivationMessage ?? '' ) . includes ( '{path}' ) ) {
298
+ expect ( ( config . shellActivationMessage ?? '' ) . includes ( '{path}' ) ) . toBe ( true )
299
299
}
300
300
} )
301
301
@@ -305,7 +305,7 @@ describe('Config', () => {
305
305
306
306
// Check activation message
307
307
for ( const char of unsafeChars ) {
308
- if ( config . shellActivationMessage . includes ( char ) ) {
308
+ if ( ( config . shellActivationMessage ?? '' ) . includes ( char ) ) {
309
309
// If it contains special chars, they should be properly escaped
310
310
// This is a warning rather than a hard failure since some messages might intentionally use these
311
311
console . warn ( `Activation message contains potentially unsafe character: ${ char } ` )
@@ -314,7 +314,7 @@ describe('Config', () => {
314
314
315
315
// Check deactivation message
316
316
for ( const char of unsafeChars ) {
317
- if ( config . shellDeactivationMessage . includes ( char ) ) {
317
+ if ( ( config . shellDeactivationMessage ?? '' ) . includes ( char ) ) {
318
318
console . warn ( `Deactivation message contains potentially unsafe character: ${ char } ` )
319
319
}
320
320
}
@@ -348,7 +348,7 @@ describe('Config', () => {
348
348
// Shim path should typically be under the installation path or home directory
349
349
const homePath = process . env . HOME || process . env . USERPROFILE || '~'
350
350
const isUnderHome = config . shimPath ?. startsWith ( homePath ) || config . shimPath ?. startsWith ( '~' )
351
- const isUnderInstall = config . shimPath ? .startsWith ( config . installPath )
351
+ const isUnderInstall = ( config . shimPath ?? '' ) . startsWith ( config . installPath ?? '' )
352
352
expect ( isUnderHome || isUnderInstall ) . toBe ( true )
353
353
} )
354
354
} )
@@ -362,7 +362,7 @@ describe('Config', () => {
362
362
363
363
it ( 'should use fallback values when needed' , ( ) => {
364
364
// Installation path should never be empty
365
- expect ( config . installPath ? .length ) . toBeGreaterThan ( 0 )
365
+ expect ( ( config . installPath ?? '' ) . length ) . toBeGreaterThan ( 0 )
366
366
expect ( config . shimPath ?. length ) . toBeGreaterThan ( 0 )
367
367
} )
368
368
} )
0 commit comments