@@ -716,7 +716,7 @@ export default function Home() {
716716 expect ( fsSpy . glob ) . toHaveBeenCalledTimes ( 5 ) ;
717717 } ) ;
718718
719- it ( "Should update package.json files from workspaces" , async ( ) => {
719+ it ( "Should update package.json files from workspaces with glob patterns " , async ( ) => {
720720 const mockFileArray : MockFile [ ] = [
721721 {
722722 path : "package.json" ,
@@ -730,8 +730,7 @@ export default function Home() {
730730 "some-package": "^0.0.0"
731731 },
732732 "workspaces": [
733- "projectA",
734- "projectB"
733+ "projects/*"
735734 ]
736735}
737736 ` ,
@@ -745,17 +744,16 @@ export default function Home() {
745744 "some-package": "^0.0.0"
746745 },
747746 "workspaces": [
748- "projectA",
749- "projectB"
747+ "projects/*"
750748 ]
751749}
752750`
753751 } ,
754752 {
755- path : "./projectA /package.json" ,
753+ path : "./projects/charts /package.json" ,
756754 content :
757755 `{
758- "name": "projectA ",
756+ "name": "charts-project ",
759757 "dependencies": {
760758 "igniteui-dockmanager": "^1.0.0",
761759 "igniteui-react": "^18.5.1",
@@ -766,7 +764,7 @@ export default function Home() {
766764 ` ,
767765 expected :
768766 `{
769- "name": "projectA ",
767+ "name": "charts-project ",
770768 "dependencies": {
771769 "@infragistics/igniteui-dockmanager": "^1.0.0",
772770 "@infragistics/igniteui-react": "^18.5.1",
@@ -777,10 +775,10 @@ export default function Home() {
777775`
778776 } ,
779777 {
780- path : "./projectB /package.json" ,
778+ path : "./projects/charts /package.json" ,
781779 content :
782780 `{
783- "name": "projectB ",
781+ "name": "charts-project ",
784782 "dependencies": {
785783 "igniteui-dockmanager": "^1.0.0",
786784 "igniteui-react": "^18.5.1",
@@ -791,7 +789,7 @@ export default function Home() {
791789 ` ,
792790 expected :
793791 `{
794- "name": "projectB ",
792+ "name": "charts-project ",
795793 "dependencies": {
796794 "@infragistics/igniteui-dockmanager": "^1.0.0",
797795 "@infragistics/igniteui-react": "^18.5.1",
@@ -802,31 +800,50 @@ export default function Home() {
802800`
803801 } ] ;
804802 ( fsSpy . fileExists as jasmine . Spy ) . and . returnValue ( true ) ;
805- ( fsSpy . glob as jasmine . Spy ) . and . returnValues // per workspace
806- ( [ "package.json" ] , // root package.json
807- [ ] , // index.html
808- [ ] , // projectA logic files
809- [ ] , // projectA for each style extension
810- [ "./projectA/package.json" ] , // projectA package.json
811- [ ] , // projectB logic files
812- [ ] , // projectB for each style extension
813- [ "./projectB/package.json" ] ) ; // projectB package.json
803+ // Mock directoryExists to return true for valid workspace directories
804+ ( fsSpy . directoryExists as jasmine . Spy ) . and . callFake ( ( dirPath : string ) => {
805+ return dirPath . includes ( "projects/charts" ) || dirPath . includes ( "projects" ) ;
806+ } ) ;
807+
808+ // Mock glob to simulate finding workspace directories and files
809+ ( fsSpy . glob as jasmine . Spy ) . and . callFake ( ( dirPath : string , pattern : string ) => {
810+ if ( pattern === "projects/*" ) {
811+ return [ "projects/charts" ] ;
812+ } else if ( pattern === "package.json" ) {
813+ return [ "package.json" ] ;
814+ } else if ( pattern === "**/*.tsx" ) {
815+ if ( dirPath . includes ( "charts" ) ) {
816+ return [ ] ;
817+ }
818+ return [ ] ;
819+ } else if ( pattern === "**/*.css" ) {
820+ return [ ] ;
821+ } else if ( pattern === "**/package.json" ) {
822+ if ( dirPath . includes ( "charts" ) ) {
823+ return [ "./projects/charts/package.json" ] ;
824+ }
825+ return [ ] ;
826+ }
827+ return [ ] ;
828+ } ) ;
829+
814830 ( fsSpy . readFile as jasmine . Spy ) . and . callFake ( ( filePath : string ) => {
815831 if ( filePath . indexOf ( "package.json" ) < 0 ) {
816832 return ;
817833 } else if ( filePath === "package.json" || filePath === "./package.json" ) {
818834 return mockFileArray . find ( entry => entry . path === "package.json" ) . content ;
819835 }
820836 const fileEntry = mockFileArray . find ( entry => entry . path === filePath ) ;
821- return fileEntry . content ;
837+ return fileEntry ? fileEntry . content : "" ;
822838 } ) ;
823839 spyOn ( PackageManager , "ensureRegistryUser" ) . and . returnValue ( true ) ;
824840 spyOn ( Util , "log" ) ;
825841 expect ( await updateWorkspace ( "" ) ) . toEqual ( true ) ;
826842 for ( const fileEntry of mockFileArray ) {
827843 expect ( ( fsSpy . writeFile as jasmine . Spy ) ) . toHaveBeenCalledWith ( fileEntry . path , fileEntry . expected ) ;
828844 }
829- expect ( fsSpy . glob ) . toHaveBeenCalledTimes ( 8 ) ;
845+ // Expect: 1 for projects/*, 1 for package.json files at root, 1 for logic files, 1 for style files, 1 for package.json in workspace
846+ expect ( fsSpy . glob ) . toHaveBeenCalledTimes ( 6 ) ;
830847 } ) ;
831848 } ) ;
832849
0 commit comments