@@ -28,10 +28,8 @@ import {
2828 getPluginModuleValue ,
2929 processLoadedModule ,
3030 registerPlugin ,
31- sortPluginsByDependency ,
3231 createChainedComponent ,
3332 createChainedPanelComponent ,
34- type PluginManifestPluginInfo ,
3533} from './PluginUtils' ;
3634
3735function TestWidget ( ) {
@@ -609,164 +607,6 @@ describe('processLoadedModule', () => {
609607 } ) ;
610608} ) ;
611609
612- describe ( 'sortPluginsByDependency' , ( ) => {
613- function makeManifestPlugin (
614- name : string ,
615- opts ?: {
616- package ?: string ;
617- dependencies ?: string [ ] ;
618- }
619- ) : PluginManifestPluginInfo {
620- return {
621- name,
622- main : 'index.js' ,
623- version : '1.0.0' ,
624- package : opts ?. package ,
625- dependencies : opts ?. dependencies ,
626- } ;
627- }
628-
629- it ( 'returns plugins in original order when no dependencies' , ( ) => {
630- const plugins = [
631- makeManifestPlugin ( 'a' ) ,
632- makeManifestPlugin ( 'b' ) ,
633- makeManifestPlugin ( 'c' ) ,
634- ] ;
635-
636- const sorted = sortPluginsByDependency ( plugins ) ;
637-
638- expect ( sorted . map ( p => p . name ) ) . toEqual ( [ 'a' , 'b' , 'c' ] ) ;
639- } ) ;
640-
641- it ( 'reorders so dependency loads before consumer' , ( ) => {
642- const plugins = [
643- makeManifestPlugin ( 'consumer' , {
644- dependencies : [ '@scope/dep' ] ,
645- } ) ,
646- makeManifestPlugin ( 'dep' , {
647- package : '@scope/dep' ,
648- } ) ,
649- ] ;
650-
651- const sorted = sortPluginsByDependency ( plugins ) ;
652-
653- expect ( sorted . map ( p => p . name ) ) . toEqual ( [ 'dep' , 'consumer' ] ) ;
654- } ) ;
655-
656- it ( 'handles a chain of dependencies: a → b → c' , ( ) => {
657- const plugins = [
658- makeManifestPlugin ( 'c' , {
659- package : '@scope/c' ,
660- dependencies : [ '@scope/b' ] ,
661- } ) ,
662- makeManifestPlugin ( 'b' , {
663- package : '@scope/b' ,
664- dependencies : [ '@scope/a' ] ,
665- } ) ,
666- makeManifestPlugin ( 'a' , {
667- package : '@scope/a' ,
668- } ) ,
669- ] ;
670-
671- const sorted = sortPluginsByDependency ( plugins ) ;
672-
673- const names = sorted . map ( p => p . name ) ;
674- expect ( names . indexOf ( 'a' ) ) . toBeLessThan ( names . indexOf ( 'b' ) ) ;
675- expect ( names . indexOf ( 'b' ) ) . toBeLessThan ( names . indexOf ( 'c' ) ) ;
676- } ) ;
677-
678- it ( 'preserves original order among independent plugins' , ( ) => {
679- const plugins = [
680- makeManifestPlugin ( 'x' ) ,
681- makeManifestPlugin ( 'dep' , { package : '@scope/dep' } ) ,
682- makeManifestPlugin ( 'y' ) ,
683- makeManifestPlugin ( 'consumer' , { dependencies : [ '@scope/dep' ] } ) ,
684- makeManifestPlugin ( 'z' ) ,
685- ] ;
686-
687- const sorted = sortPluginsByDependency ( plugins ) ;
688-
689- const names = sorted . map ( p => p . name ) ;
690- // dep must come before consumer
691- expect ( names . indexOf ( 'dep' ) ) . toBeLessThan ( names . indexOf ( 'consumer' ) ) ;
692- // independent plugins keep their relative order
693- expect ( names . indexOf ( 'x' ) ) . toBeLessThan ( names . indexOf ( 'y' ) ) ;
694- expect ( names . indexOf ( 'y' ) ) . toBeLessThan ( names . indexOf ( 'z' ) ) ;
695- } ) ;
696-
697- it ( 'throws on circular dependencies' , ( ) => {
698- const plugins = [
699- makeManifestPlugin ( 'a' , {
700- package : '@scope/a' ,
701- dependencies : [ '@scope/b' ] ,
702- } ) ,
703- makeManifestPlugin ( 'b' , {
704- package : '@scope/b' ,
705- dependencies : [ '@scope/a' ] ,
706- } ) ,
707- ] ;
708-
709- expect ( ( ) => sortPluginsByDependency ( plugins ) ) . toThrow (
710- / C i r c u l a r p l u g i n d e p e n d e n c y /
711- ) ;
712- } ) ;
713-
714- it ( 'warns and ignores dependencies not in the manifest' , ( ) => {
715- const plugins = [
716- makeManifestPlugin ( 'consumer' , {
717- dependencies : [ '@scope/nonexistent' ] ,
718- } ) ,
719- ] ;
720-
721- const sorted = sortPluginsByDependency ( plugins ) ;
722-
723- expect ( sorted . map ( p => p . name ) ) . toEqual ( [ 'consumer' ] ) ;
724- } ) ;
725-
726- it ( 'handles multiple dependencies' , ( ) => {
727- const plugins = [
728- makeManifestPlugin ( 'consumer' , {
729- dependencies : [ '@scope/dep-a' , '@scope/dep-b' ] ,
730- } ) ,
731- makeManifestPlugin ( 'dep-a' , { package : '@scope/dep-a' } ) ,
732- makeManifestPlugin ( 'dep-b' , { package : '@scope/dep-b' } ) ,
733- ] ;
734-
735- const sorted = sortPluginsByDependency ( plugins ) ;
736-
737- const names = sorted . map ( p => p . name ) ;
738- expect ( names . indexOf ( 'dep-a' ) ) . toBeLessThan ( names . indexOf ( 'consumer' ) ) ;
739- expect ( names . indexOf ( 'dep-b' ) ) . toBeLessThan ( names . indexOf ( 'consumer' ) ) ;
740- } ) ;
741-
742- it ( 'does not mutate the input array' , ( ) => {
743- const plugins = [
744- makeManifestPlugin ( 'consumer' , { dependencies : [ '@scope/dep' ] } ) ,
745- makeManifestPlugin ( 'dep' , { package : '@scope/dep' } ) ,
746- ] ;
747- const original = [ ...plugins ] ;
748-
749- sortPluginsByDependency ( plugins ) ;
750-
751- expect ( plugins ) . toEqual ( original ) ;
752- } ) ;
753-
754- it ( 'handles empty plugin list' , ( ) => {
755- expect ( sortPluginsByDependency ( [ ] ) ) . toEqual ( [ ] ) ;
756- } ) ;
757-
758- it ( 'handles plugins with empty dependencies array' , ( ) => {
759- const plugins = [
760- makeManifestPlugin ( 'a' , { dependencies : [ ] } ) ,
761- makeManifestPlugin ( 'b' ) ,
762- ] ;
763-
764- const sorted = sortPluginsByDependency ( plugins ) ;
765-
766- expect ( sorted . map ( p => p . name ) ) . toEqual ( [ 'a' , 'b' ] ) ;
767- } ) ;
768- } ) ;
769-
770610describe ( 'createChainedComponent' , ( ) => {
771611 function BaseWidget ( { fetch } : WidgetComponentProps ) {
772612 return < div data-testid = "base" > BaseWidget</ div > ;
0 commit comments