@@ -15,7 +15,11 @@ import * as api from '../src/api';
1515import * as app from '../src/app' ;
1616import * as utils from '../src/utils' ;
1717import * as git from '../src/utils/git' ;
18- import { bindVersionToPackages , versionCommands } from '../src/versions' ;
18+ import {
19+ bindVersionToPackages ,
20+ normalizeDeps ,
21+ versionCommands ,
22+ } from '../src/versions' ;
1923
2024describe ( 'bindVersionToPackages' , ( ) => {
2125 let consoleSpy : ReturnType < typeof spyOn > ;
@@ -495,3 +499,60 @@ describe('rollout validation (via versionCommands.update)', () => {
495499 expect ( parseRollout ( '33.7' ) ) . toBe ( 33 ) ;
496500 } ) ;
497501} ) ;
502+
503+ describe ( 'normalizeDeps' , ( ) => {
504+ test ( 'returns undefined for falsy inputs' , ( ) => {
505+ expect ( normalizeDeps ( undefined ) ) . toBeUndefined ( ) ;
506+ expect ( normalizeDeps ( null ) ) . toBeUndefined ( ) ;
507+ expect ( normalizeDeps ( false ) ) . toBeUndefined ( ) ;
508+ expect ( normalizeDeps ( '' ) ) . toBeUndefined ( ) ;
509+ } ) ;
510+
511+ test ( 'handles string inputs' , ( ) => {
512+ // Valid JSON object with string values
513+ expect ( normalizeDeps ( '{"react":"18.2.0","lodash":"4.17.21"}' ) ) . toEqual ( {
514+ react : '18.2.0' ,
515+ lodash : '4.17.21' ,
516+ } ) ;
517+
518+ // Valid JSON but not an object (array)
519+ expect ( normalizeDeps ( '["react", "lodash"]' ) ) . toBeUndefined ( ) ;
520+
521+ // Valid JSON but non-string values
522+ expect ( normalizeDeps ( '{"react": 18, "lodash": true}' ) ) . toBeUndefined ( ) ;
523+
524+ // Invalid JSON
525+ expect ( normalizeDeps ( 'invalid-json' ) ) . toBeUndefined ( ) ;
526+ } ) ;
527+
528+ test ( 'handles object inputs' , ( ) => {
529+ // Valid object
530+ expect ( normalizeDeps ( { react : '18.2.0' , lodash : '4.17.21' } ) ) . toEqual ( {
531+ react : '18.2.0' ,
532+ lodash : '4.17.21' ,
533+ } ) ;
534+
535+ // Object with mixed values (ignores non-strings and empty strings)
536+ expect (
537+ normalizeDeps ( {
538+ react : '18.2.0' ,
539+ lodash : 4 ,
540+ empty : '' ,
541+ bool : true ,
542+ obj : { } ,
543+ } ) ,
544+ ) . toEqual ( {
545+ react : '18.2.0' ,
546+ } ) ;
547+
548+ // Empty object after filtering
549+ expect ( normalizeDeps ( { number : 1 , bool : true } ) ) . toBeUndefined ( ) ;
550+ } ) ;
551+
552+ test ( 'returns undefined for invalid object types' , ( ) => {
553+ // Array
554+ expect ( normalizeDeps ( [ 'react' ] ) ) . toBeUndefined ( ) ;
555+ // Function
556+ expect ( normalizeDeps ( ( ) => { } ) ) . toBeUndefined ( ) ;
557+ } ) ;
558+ } ) ;
0 commit comments