@@ -135,7 +135,8 @@ test.afterEach.always((t) => {
135
135
136
136
function defineTest ( testName , {
137
137
frameworkName,
138
- verbose = false
138
+ verbose = false ,
139
+ librariesInWorkspace = null
139
140
} ) {
140
141
const npmScope = frameworkName === "SAPUI5" ? "@sapui5" : "@openui5" ;
141
142
@@ -410,7 +411,66 @@ function defineTest(testName, {
410
411
const provider = new DependencyTreeProvider ( { dependencyTree} ) ;
411
412
const projectGraph = await projectGraphBuilder ( provider ) ;
412
413
413
- await ui5Framework . enrichProjectGraph ( projectGraph ) ;
414
+ if ( librariesInWorkspace ) {
415
+ const projectNameMap = new Map ( ) ;
416
+ const moduleIdMap = new Map ( ) ;
417
+ librariesInWorkspace . forEach ( ( libName ) => {
418
+ const libraryDistMetadata = distributionMetadata . libraries [ libName ] ;
419
+ const module = {
420
+ getSpecifications : sinon . stub ( ) . resolves ( {
421
+ project : {
422
+ getName : sinon . stub ( ) . returns ( libName ) ,
423
+ getVersion : sinon . stub ( ) . returns ( "1.76.0-SNAPSHOT" ) ,
424
+ getRootPath : sinon . stub ( ) . returns ( path . join ( fakeBaseDir , "workspace" , libName ) ) ,
425
+ isFrameworkProject : sinon . stub ( ) . returns ( true ) ,
426
+ getId : sinon . stub ( ) . returns ( libraryDistMetadata . npmPackageName ) ,
427
+ getRootReader : sinon . stub ( ) . returns ( {
428
+ byPath : sinon . stub ( ) . resolves ( {
429
+ getString : sinon . stub ( ) . resolves ( JSON . stringify ( { dependencies : { } } ) )
430
+ } )
431
+ } ) ,
432
+ getFrameworkDependencies : sinon . stub ( ) . callsFake ( ( ) => {
433
+ const deps = [ ] ;
434
+ libraryDistMetadata . dependencies . forEach ( ( dep ) => {
435
+ deps . push ( { name : dep } ) ;
436
+ } ) ;
437
+ libraryDistMetadata . optionalDependencies . forEach ( ( optDep ) => {
438
+ deps . push ( { name : optDep , optional : true } ) ;
439
+ } ) ;
440
+ return deps ;
441
+ } ) ,
442
+ isDeprecated : sinon . stub ( ) . returns ( false ) ,
443
+ isSapInternal : sinon . stub ( ) . returns ( false ) ,
444
+ getAllowSapInternal : sinon . stub ( ) . returns ( false ) ,
445
+ }
446
+ } ) ,
447
+ getVersion : sinon . stub ( ) . returns ( "1.76.0-SNAPSHOT" ) ,
448
+ getPath : sinon . stub ( ) . returns ( path . join ( fakeBaseDir , "workspace" , libName ) ) ,
449
+ } ;
450
+ projectNameMap . set ( libName , module ) ;
451
+ moduleIdMap . set ( libraryDistMetadata . npmPackageName , module ) ;
452
+ } ) ;
453
+
454
+ const getModuleByProjectName = sinon . stub ( ) . callsFake (
455
+ async ( projectName ) => projectNameMap . get ( projectName )
456
+ ) ;
457
+ const getModules = sinon . stub ( ) . callsFake (
458
+ async ( ) => {
459
+ const sortedMap = new Map ( [ ...moduleIdMap ] . sort ( ( a , b ) => String ( a [ 0 ] ) . localeCompare ( b [ 0 ] ) ) ) ;
460
+ return Array . from ( sortedMap . values ( ) ) ;
461
+ }
462
+ ) ;
463
+
464
+ const workspace = {
465
+ getName : sinon . stub ( ) . returns ( "test" ) ,
466
+ getModules,
467
+ getModuleByProjectName
468
+ } ;
469
+
470
+ await ui5Framework . enrichProjectGraph ( projectGraph , { workspace} ) ;
471
+ } else {
472
+ await ui5Framework . enrichProjectGraph ( projectGraph ) ;
473
+ }
414
474
415
475
const callbackStub = sinon . stub ( ) . resolves ( ) ;
416
476
await projectGraph . traverseDepthFirst ( callbackStub ) ;
@@ -465,6 +525,15 @@ defineTest("ui5Framework helper should enhance project graph with UI5 framework
465
525
verbose : true
466
526
} ) ;
467
527
528
+ defineTest ( "ui5Framework helper should not cause install of libraries within workspace" , {
529
+ frameworkName : "SAPUI5" ,
530
+ librariesInWorkspace : [ "sap.ui.lib1" , "sap.ui.lib2" , "sap.ui.lib8" ]
531
+ } ) ;
532
+ defineTest ( "ui5Framework helper should not cause install of libraries within workspace" , {
533
+ frameworkName : "OpenUI5" ,
534
+ librariesInWorkspace : [ "sap.ui.lib1" , "sap.ui.lib2" , "sap.ui.lib8" ]
535
+ } ) ;
536
+
468
537
function defineErrorTest ( testName , {
469
538
frameworkName,
470
539
failExtract = false ,
@@ -723,8 +792,8 @@ test.serial("ui5Framework translator should not try to install anything when no
723
792
t . is ( pacote . manifest . callCount , 0 , "No manifest should be requested" ) ;
724
793
} ) ;
725
794
726
- test . serial ( "ui5Framework translator should throw an error when framework version is not defined " , async ( t ) => {
727
- const { ui5Framework, projectGraphBuilder} = t . context ;
795
+ test . serial ( "ui5Framework helper shouldn't throw when framework version and libraries are not provided " , async ( t ) => {
796
+ const { ui5Framework, projectGraphBuilder, logStub } = t . context ;
728
797
729
798
const dependencyTree = {
730
799
id : "test-id" ,
@@ -745,13 +814,28 @@ test.serial("ui5Framework translator should throw an error when framework versio
745
814
const provider = new DependencyTreeProvider ( { dependencyTree} ) ;
746
815
const projectGraph = await projectGraphBuilder ( provider ) ;
747
816
748
- await t . throwsAsync ( async ( ) => {
749
- await ui5Framework . enrichProjectGraph ( projectGraph ) ;
750
- } , { message : `No framework version defined for root project test-project` } , "Correct error message" ) ;
817
+ await ui5Framework . enrichProjectGraph ( projectGraph ) ;
818
+
819
+ t . is ( logStub . verbose . callCount , 5 ) ;
820
+ t . deepEqual ( logStub . verbose . getCall ( 0 ) . args , [
821
+ "Configuration for module test-id has been supplied directly"
822
+ ] ) ;
823
+ t . deepEqual ( logStub . verbose . getCall ( 1 ) . args , [
824
+ "Module test-id contains project test-project"
825
+ ] ) ;
826
+ t . deepEqual ( logStub . verbose . getCall ( 2 ) . args , [
827
+ "Root project test-project qualified as application project for project graph"
828
+ ] ) ;
829
+ t . deepEqual ( logStub . verbose . getCall ( 3 ) . args , [
830
+ "Project test-project has no framework dependencies"
831
+ ] ) ;
832
+ t . deepEqual ( logStub . verbose . getCall ( 4 ) . args , [
833
+ "No SAPUI5 libraries referenced in project test-project or in any of its dependencies"
834
+ ] ) ;
751
835
} ) ;
752
836
753
837
test . serial (
754
- "SAPUI5: ui5Framework translator should throw error when using a library that is not part of the dist metadata" ,
838
+ "SAPUI5: ui5Framework helper should throw error when using a library that is not part of the dist metadata" ,
755
839
async ( t ) => {
756
840
const { sinon, ui5Framework, Installer, projectGraphBuilder} = t . context ;
757
841
0 commit comments