@@ -10,6 +10,7 @@ import { TestConfig, testPlan, TestResource, TestStatefulParameter } from '../ut
1010import { tildify , untildify } from '../utils/utils.js' ;
1111import { ArrayStatefulParameter , StatefulParameter } from '../stateful-parameter/stateful-parameter.js' ;
1212import { Plan } from '../plan/plan.js' ;
13+ import os from 'node:os' ;
1314
1415describe ( 'Resource tests' , ( ) => {
1516
@@ -828,6 +829,107 @@ describe('Resource tests', () => {
828829 }
829830
830831 const controller = new ResourceController ( resource ) ;
831- const plan = await controller . import ( { type : 'path' } , { } ) ;
832+ await controller . import ( { type : 'path' } , { } ) ;
833+ ;
834+ } )
835+
836+ it ( 'Can import and return all of the imported parameters' , async ( ) => {
837+ const resource = new class extends TestResource {
838+ getSettings ( ) : ResourceSettings < any > {
839+ return {
840+ id : 'path' ,
841+ parameterSettings : {
842+ path : { type : 'directory' } ,
843+ paths : { canModify : true , type : 'array' , itemType : 'directory' } ,
844+ prepend : { default : false , setting : true } ,
845+ declarationsOnly : { default : false , setting : true } ,
846+ } ,
847+ importAndDestroy : {
848+ refreshMapper : ( input , context ) => {
849+ if ( Object . keys ( input ) . length === 0 ) {
850+ return { paths : [ ] , declarationsOnly : true } ;
851+ }
852+
853+ return input ;
854+ }
855+ } ,
856+ allowMultiple : {
857+ matcher : ( desired , current ) => {
858+ if ( desired . path ) {
859+ return desired . path === current . path ;
860+ }
861+
862+ const currentPaths = new Set ( current . paths )
863+ return desired . paths ?. some ( ( p ) => currentPaths . has ( p ) ) ;
864+ }
865+ }
866+ }
867+ }
868+
869+ async refresh ( parameters : Partial < TestConfig > ) : Promise < Partial < TestConfig > | null > {
870+ return {
871+ paths : [
872+ `${ os . homedir ( ) } /.pyenv/bin` ,
873+ `${ os . homedir ( ) } /.bun/bin` ,
874+ `${ os . homedir ( ) } /.deno/bin` ,
875+ `${ os . homedir ( ) } /.jenv/bin` ,
876+ `${ os . homedir ( ) } /a/random/path` ,
877+ `${ os . homedir ( ) } /.nvm/.bin/2` ,
878+ `${ os . homedir ( ) } /.nvm/.bin/3`
879+ ]
880+ }
881+ }
882+ }
883+
884+ const oldProcessEnv = structuredClone ( process . env ) ;
885+
886+ process . env [ 'PYENV_ROOT' ] = `${ os . homedir ( ) } /.pyenv`
887+ process . env [ 'BUN_INSTALL' ] = `${ os . homedir ( ) } /.bun`
888+ process . env [ 'DENO_INSTALL' ] = `${ os . homedir ( ) } /.deno`
889+ process . env [ 'JENV' ] = `${ os . homedir ( ) } /.jenv`
890+ process . env [ 'NVM_DIR' ] = `${ os . homedir ( ) } /.nvm`
891+
892+ const controller = new ResourceController ( resource ) ;
893+ const importResult1 = await controller . import ( { type : 'path' } , { } ) ;
894+ expect ( importResult1 ) . toMatchObject ( [
895+ {
896+ 'core' : {
897+ 'type' : 'path'
898+ } ,
899+ 'parameters' : {
900+ 'paths' : [
901+ '$PYENV_ROOT/bin' ,
902+ '$BUN_INSTALL/bin' ,
903+ '$DENO_INSTALL/bin' ,
904+ '$JENV/bin' ,
905+ '~/a/random/path' ,
906+ '$NVM_DIR/.bin/2' ,
907+ '$NVM_DIR/.bin/3'
908+ ]
909+ }
910+ }
911+ ] )
912+
913+ const importResult2 = await controller . import ( { type : 'path' } , { paths : [ '$PYENV_ROOT/bin' , '$BUN_INSTALL/bin' ] } ) ;
914+ expect ( importResult2 ) . toMatchObject ( [
915+ {
916+ 'core' : {
917+ 'type' : 'path'
918+ } ,
919+ 'parameters' : {
920+ 'paths' : [
921+ '$PYENV_ROOT/bin' ,
922+ '$BUN_INSTALL/bin' ,
923+ '$DENO_INSTALL/bin' ,
924+ '$JENV/bin' ,
925+ '~/a/random/path' ,
926+ '$NVM_DIR/.bin/2' ,
927+ '$NVM_DIR/.bin/3'
928+ ]
929+ }
930+ }
931+ ] )
932+
933+ process . env = oldProcessEnv ;
832934 } )
833935} ) ;
0 commit comments