@@ -409,6 +409,96 @@ describe("extensibilityService", () => {
409409 assert . isTrue ( isNpmInstallCalled ) ;
410410 } ) ;
411411
412+ it ( "loads already-installed scoped extensions without re-running npm install" , async ( ) => {
413+ const testInjector = getTestInjector ( ) ;
414+ const fs : IFileSystem = testInjector . resolve ( "fs" ) ;
415+ const extensionNames = [ "@scope/extension1" , "extension2" ] ;
416+ fs . exists = ( ) : boolean => true ;
417+ fs . readDirectory = ( dir : string ) : string [ ] => {
418+ if ( path . basename ( dir ) === constants . NODE_MODULES_FOLDER_NAME ) {
419+ return [ "@scope" , "extension2" ] ;
420+ }
421+ if ( path . basename ( dir ) === "@scope" ) {
422+ return [ "extension1" ] ;
423+ }
424+ return [ ] ;
425+ } ;
426+
427+ mockFsReadJson ( testInjector , extensionNames ) ;
428+
429+ let isNpmInstallCalled = false ;
430+ const npm : INodePackageManager = testInjector . resolve ( "npm" ) ;
431+ npm . install = async ( ) : Promise < any > => {
432+ isNpmInstallCalled = true ;
433+ return { } ;
434+ } ;
435+
436+ const expectedResults : IExtensionData [ ] = _ . map (
437+ extensionNames ,
438+ ( extensionName ) => ( {
439+ extensionName,
440+ version : "1.0.0" ,
441+ pathToExtension : getExpectedInstallationPathForExtension (
442+ testInjector ,
443+ extensionName ,
444+ ) ,
445+ docs : undefined as any ,
446+ } ) ,
447+ ) ;
448+
449+ const extensibilityService : IExtensibilityService =
450+ testInjector . resolve ( ExtensibilityService ) ;
451+ const actualResult = await Promise . all (
452+ extensibilityService . loadExtensions ( ) ,
453+ ) ;
454+ assert . deepStrictEqual ( actualResult , expectedResults ) ;
455+ assert . isFalse ( isNpmInstallCalled ) ;
456+ } ) ;
457+
458+ it ( "installs a missing scoped extension when its scope directory exists without the package" , async ( ) => {
459+ const testInjector = getTestInjector ( ) ;
460+ const fs : IFileSystem = testInjector . resolve ( "fs" ) ;
461+ const extensionName = "@scope/missing-ext" ;
462+ fs . exists = ( pathToCheck : string ) : boolean =>
463+ pathToCheck !== path . resolve ( extensionName ) ;
464+ fs . readDirectory = ( dir : string ) : string [ ] => {
465+ if ( path . basename ( dir ) === constants . NODE_MODULES_FOLDER_NAME ) {
466+ return [ "@scope" ] ;
467+ }
468+ if ( path . basename ( dir ) === "@scope" ) {
469+ return [ "other-ext" ] ;
470+ }
471+ return [ ] ;
472+ } ;
473+
474+ mockFsReadJson ( testInjector , [ extensionName ] ) ;
475+
476+ const installedPackages : string [ ] = [ ] ;
477+ const npm : INodePackageManager = testInjector . resolve ( "npm" ) ;
478+ npm . install = async ( packageName : string ) : Promise < any > => {
479+ installedPackages . push ( packageName ) ;
480+ return { name : packageName } ;
481+ } ;
482+
483+ const extensibilityService : IExtensibilityService =
484+ testInjector . resolve ( ExtensibilityService ) ;
485+ const actualResult = await Promise . all (
486+ extensibilityService . loadExtensions ( ) ,
487+ ) ;
488+ assert . deepStrictEqual ( installedPackages , [ extensionName ] ) ;
489+ assert . deepStrictEqual ( actualResult , [
490+ {
491+ extensionName,
492+ version : "1.0.0" ,
493+ pathToExtension : getExpectedInstallationPathForExtension (
494+ testInjector ,
495+ extensionName ,
496+ ) ,
497+ docs : undefined as any ,
498+ } ,
499+ ] ) ;
500+ } ) ;
501+
412502 it ( "rejects only promises for extensions that cannot be loaded" , async ( ) => {
413503 const testInjector = getTestInjector ( ) ;
414504 const fs : IFileSystem = testInjector . resolve ( "fs" ) ;
0 commit comments