@@ -474,369 +474,4 @@ describe(`Configuration`, () => {
474474 expect ( array [ 1 ] ) . toBe ( `2` ) ;
475475 } ) ;
476476 } ) ;
477-
478- describe ( `useWithSource` , ( ) => {
479- it ( `it should set the correct value according to the options (single value)` , async ( ) => {
480- const { plugins, pluginConfiguration} = await initConfigurationPlugin ( `{
481- any: {
482- description: "",
483- type: "ANY",
484- default: "",
485- },
486- boolean: {
487- description: "",
488- type: "BOOLEAN",
489- default: false,
490- },
491- absolutePath: {
492- description: "",
493- type: "ABSOLUTE_PATH",
494- default: ".",
495- },
496- locator: {
497- description: "",
498- type: "LOCATOR",
499- default: "",
500- },
501- locatorLoose: {
502- description: "",
503- type: "LOCATOR_LOOSE",
504- default: "",
505- },
506- number: {
507- description: "",
508- type: "NUMBER",
509- default: 0,
510- },
511- string: {
512- description: "",
513- type: "STRING",
514- default: "",
515- },
516- secret: {
517- description: "",
518- type: "SECRET",
519- default: "",
520- },
521- }` ) ;
522- await initializeConfiguration ( {
523- plugins,
524- any : `any` ,
525- boolean : true ,
526- absolutePath : `/absolutePath` ,
527- locator : `locator` ,
528- locatorLoose : `locatorLoose` ,
529- number : 1 ,
530- string : `string` ,
531- secret : `secret` ,
532- } , async dir => {
533- const configuration = await Configuration . find ( dir , pluginConfiguration ) ;
534-
535- configuration . useWithSource ( `second file` , {
536- any : `any2` ,
537- boolean : false ,
538- absolutePath : `/absolutePath2` ,
539- locator : `locator2` ,
540- locatorLoose : `locatorLoose2` ,
541- number : 2 ,
542- string : `string2` ,
543- secret : `secret2` ,
544- } , dir ) ;
545- expect ( configuration . get ( `any` ) ) . toBe ( `any` ) ;
546- expect ( configuration . get ( `boolean` ) ) . toBe ( true ) ;
547- expect ( configuration . get ( `absolutePath` ) ) . toBe ( `/absolutePath` ) ;
548- expect ( configuration . get ( `locator` ) ) . toStrictEqual ( structUtils . parseLocator ( `locator` ) ) ;
549- expect ( configuration . get ( `locatorLoose` ) ) . toStrictEqual ( structUtils . parseLocator ( `locatorLoose` , false ) ) ;
550- expect ( configuration . get ( `number` ) ) . toBe ( 1 ) ;
551- expect ( configuration . get ( `string` ) ) . toBe ( `string` ) ;
552- expect ( configuration . get ( `secret` ) ) . toBe ( `secret` ) ;
553-
554- configuration . useWithSource ( `third file` , {
555- any : `any2` ,
556- boolean : true ,
557- absolutePath : `/absolutePath2` ,
558- locator : `locator2` ,
559- locatorLoose : `locatorLoose2` ,
560- number : 2 ,
561- string : `string2` ,
562- secret : `secret2` ,
563- } , dir , { overwrite : true } ) ;
564- expect ( configuration . get ( `any` ) ) . toBe ( `any2` ) ;
565- expect ( configuration . get ( `boolean` ) ) . toBe ( true ) ;
566- expect ( configuration . get ( `absolutePath` ) ) . toBe ( `/absolutePath2` ) ;
567- expect ( configuration . get ( `locator` ) ) . toStrictEqual ( structUtils . parseLocator ( `locator2` ) ) ;
568- expect ( configuration . get ( `locatorLoose` ) ) . toStrictEqual ( structUtils . parseLocator ( `locatorLoose2` , false ) ) ;
569- expect ( configuration . get ( `number` ) ) . toBe ( 2 ) ;
570- expect ( configuration . get ( `string` ) ) . toBe ( `string2` ) ;
571- expect ( configuration . get ( `secret` ) ) . toBe ( `secret2` ) ;
572-
573- configuration . useWithSource ( `fourth file` , {
574- any : `any3` ,
575- boolean : false ,
576- absolutePath : `/absolutePath3` ,
577- locator : `locator3` ,
578- locatorLoose : `locatorLoose3` ,
579- number : 3 ,
580- string : `string3` ,
581- secret : `secret3` ,
582- } , dir , { reset : true } ) ;
583- expect ( configuration . get ( `any` ) ) . toBe ( `any3` ) ;
584- expect ( configuration . get ( `boolean` ) ) . toBe ( false ) ;
585- expect ( configuration . get ( `absolutePath` ) ) . toBe ( `/absolutePath3` ) ;
586- expect ( configuration . get ( `locator` ) ) . toEqual ( structUtils . parseLocator ( `locator3` ) ) ;
587- expect ( configuration . get ( `locatorLoose` ) ) . toEqual ( structUtils . parseLocator ( `locatorLoose3` , false ) ) ;
588- expect ( configuration . get ( `number` ) ) . toBe ( 3 ) ;
589- expect ( configuration . get ( `string` ) ) . toBe ( `string3` ) ;
590- expect ( configuration . get ( `secret` ) ) . toBe ( `secret3` ) ;
591- } ) ;
592- } ) ;
593-
594- it ( `it should set the correct value according to the options (complex value)` , async ( ) => {
595- const { plugins, pluginConfiguration} = await initConfigurationPlugin ( `{
596- stringArray: {
597- description: "",
598- type: "STRING",
599- isArray: true,
600- default: [],
601- },
602- stringConcatenateArray: {
603- description: "",
604- type: "STRING",
605- isArray: true,
606- concatenateValues: true,
607- default: [],
608- },
609- shape: {
610- description: "",
611- type: "SHAPE",
612- properties: {
613- number: {
614- description: "",
615- type: "NUMBER",
616- default: 0,
617- },
618- string: {
619- description: "",
620- type: "STRING",
621- default: "default",
622- },
623- },
624- },
625- map: {
626- description: "",
627- type: "MAP",
628- valueDefinition: {
629- description: "",
630- type: "SHAPE",
631- properties: {
632- number: {
633- description: "",
634- type: "NUMBER",
635- default: 0,
636- },
637- string: {
638- description: "",
639- type: "STRING",
640- default: "default",
641- },
642- },
643- },
644- },
645- }` ) ;
646- await initializeConfiguration ( {
647- plugins,
648- stringArray : [ `foo` ] ,
649- stringConcatenateArray : [ `foo` ] ,
650- shape : {
651- number : 1 , string : `foo` ,
652- } ,
653- map : {
654- foo : { number : 1 , string : `foo` } ,
655- bar : { number : 1 , string : `foo` } ,
656- } ,
657- } , async dir => {
658- const configuration = await Configuration . find ( dir , pluginConfiguration ) ;
659-
660- configuration . useWithSource ( `second file` , {
661- stringArray : [ `bar` ] ,
662- stringConcatenateArray : [ `bar` ] ,
663- shape : {
664- number : 2 , string : `bar` ,
665- } ,
666- map : {
667- foo : { number : 2 , string : `bar` } ,
668- bar : { number : 2 , string : `bar` } ,
669- } ,
670- } , dir ) ;
671- expect ( configuration . get ( `stringArray` ) ) . toEqual ( [ `foo` , `bar` ] ) ;
672- expect ( configuration . get ( `stringConcatenateArray` ) ) . toEqual ( [ `bar` , `foo` ] ) ;
673- expect ( configuration . get ( `shape` ) ) . toEqual ( new Map < string , any > ( [ [ `number` , 1 ] , [ `string` , `foo` ] ] ) ) ;
674- expect ( configuration . get ( `map` ) ) . toEqual ( new Map ( [
675- [
676- `foo` , new Map < string , any > ( [ [ `number` , 1 ] , [ `string` , `foo` ] ] ) ,
677- ] , [
678- `bar` , new Map < string , any > ( [ [ `number` , 1 ] , [ `string` , `foo` ] ] ) ,
679- ] ,
680- ] ) ) ;
681-
682- configuration . useWithSource ( `third file` , {
683- stringArray : [ `baz` ] ,
684- stringConcatenateArray : [ `baz` ] ,
685- shape : {
686- number : 2 , string : `bar` ,
687- } ,
688- map : {
689- foo : { number : 2 , string : `bar` } ,
690- bar : { number : 2 , string : `bar` } ,
691- } ,
692- } , dir , { overwrite : true } ) ;
693- expect ( configuration . get ( `stringArray` ) ) . toEqual ( [ `foo` , `bar` , `baz` ] ) ;
694- expect ( configuration . get ( `stringConcatenateArray` ) ) . toEqual ( [ `bar` , `foo` , `baz` ] ) ;
695- expect ( configuration . get ( `shape` ) ) . toEqual ( new Map < string , any > ( [ [ `number` , 2 ] , [ `string` , `bar` ] ] ) ) ;
696- expect ( configuration . get ( `map` ) ) . toEqual ( new Map ( [
697- [
698- `foo` , new Map < string , any > ( [ [ `number` , 2 ] , [ `string` , `bar` ] ] ) ,
699- ] , [
700- `bar` , new Map < string , any > ( [ [ `number` , 2 ] , [ `string` , `bar` ] ] ) ,
701- ] ,
702- ] ) ) ;
703-
704- configuration . useWithSource ( `fourth file` , {
705- stringArray : [ `qux` ] ,
706- stringConcatenateArray : [ `qux` ] ,
707- shape : {
708- string : `bar` ,
709- } ,
710- map : {
711- bar : { number : 3 } ,
712- baz : { } ,
713- } ,
714- } , dir , { reset : true } ) ;
715- expect ( configuration . get ( `stringArray` ) ) . toEqual ( [ `qux` ] ) ;
716- expect ( configuration . get ( `stringConcatenateArray` ) ) . toEqual ( [ `qux` ] ) ;
717- expect ( configuration . get ( `shape` ) ) . toEqual ( new Map < string , any > ( [ [ `number` , 0 ] , [ `string` , `bar` ] ] ) ) ;
718- expect ( configuration . get ( `map` ) ) . toEqual ( new Map ( [
719- [
720- `bar` , new Map < string , any > ( [ [ `number` , 3 ] , [ `string` , `default` ] ] ) ,
721- ] ,
722- [
723- `baz` , new Map < string , any > ( [ [ `number` , 0 ] , [ `string` , `default` ] ] ) ,
724- ] ,
725- ] ) ) ;
726- } ) ;
727- } ) ;
728- } ) ;
729-
730- describe ( `multiple RC files` , ( ) => {
731- it ( `it should correctly merge or override the values` , async ( ) => {
732- const { plugins, pluginConfiguration} = await initConfigurationPlugin ( `{
733- string: {
734- description: "",
735- type: "STRING",
736- default: "",
737- },
738- stringArray: {
739- description: "",
740- type: "STRING",
741- isArray: true,
742- default: [],
743- },
744- shape: {
745- description: "",
746- type: "SHAPE",
747- properties: {
748- number: {
749- description: "",
750- type: "NUMBER",
751- default: 0,
752- },
753- string: {
754- description: "",
755- type: "STRING",
756- default: "default",
757- },
758- },
759- },
760- map: {
761- description: "",
762- type: "MAP",
763- valueDefinition: {
764- description: "",
765- type: "SHAPE",
766- properties: {
767- number: {
768- description: "",
769- type: "NUMBER",
770- default: 0,
771- },
772- string: {
773- description: "",
774- type: "STRING",
775- default: "default",
776- },
777- },
778- },
779- },
780- }` ) ;
781- await initializeConfiguration ( {
782- plugins,
783- string : `foo` ,
784- stringArray : [ `foo` ] ,
785- shape : {
786- number : 1 , string : `foo` ,
787- } ,
788- map : {
789- foo : { number : 1 , string : `foo` } ,
790- bar : { number : 1 , string : `foo` } ,
791- baz : { number : 2 , string : `bar` } ,
792- } ,
793- } , async dir => {
794- const workspaceDirectory = `${ dir } /workspace` as PortablePath ;
795-
796- await xfs . mkdirPromise ( workspaceDirectory ) ;
797- await xfs . writeFilePromise ( `${ workspaceDirectory } /.yarnrc.yml` as PortablePath , stringifySyml ( {
798- string : `bar` ,
799- stringArray : [ `bar` ] ,
800- shape : {
801- string : `bar` ,
802- } ,
803- map : {
804- foo : { } ,
805- bar : { string : `bar` } ,
806- } ,
807- } ) ) ;
808-
809- const configuration = await Configuration . find ( workspaceDirectory , pluginConfiguration ) ;
810-
811- expect ( configuration . get ( `string` ) ) . toBe ( `bar` ) ;
812- expect ( configuration . get ( `stringArray` ) ) . toEqual ( [ `bar` , `foo` ] ) ;
813- expect ( configuration . get ( `shape` ) ) . toEqual ( new Map < string , any > ( [ [ `number` , 1 ] , [ `string` , `bar` ] ] ) ) ; // the number is default value
814- expect ( configuration . get ( `map` ) ) . toEqual (
815- new Map ( [
816- [
817- `foo` ,
818- new Map < string , any > ( [
819- [ `number` , 1 ] ,
820- [ `string` , `foo` ] ,
821- ] ) ,
822- ] ,
823- [
824- `bar` ,
825- new Map < string , any > ( [
826- [ `number` , 1 ] ,
827- [ `string` , `bar` ] ,
828- ] ) ,
829- ] ,
830- [
831- `baz` ,
832- new Map < string , any > ( [
833- [ `number` , 2 ] ,
834- [ `string` , `bar` ] ,
835- ] ) ,
836- ] ,
837- ] ) ,
838- ) ;
839- } ) ;
840- } ) ;
841- } ) ;
842477} ) ;
0 commit comments