@@ -822,3 +822,122 @@ tap.test(
822
822
t . end ( ) ;
823
823
} ,
824
824
) ;
825
+
826
+ tap . test (
827
+ 'Resource().fetch - hints complete event emitted once all early hints received - single resource component' ,
828
+ async ( t ) => {
829
+ t . plan ( 1 ) ;
830
+ const server = new PodletServer ( {
831
+ version : '1.0.0' ,
832
+ assets : {
833
+ js : '/foo/bar.js' ,
834
+ css : '/foo/bar.css' ,
835
+ } ,
836
+ } ) ;
837
+ const service = await server . listen ( ) ;
838
+
839
+ const client = new Client ( { name : 'podiumClient' } ) ;
840
+ const component = client . register ( service . options ) ;
841
+
842
+ const incoming = new HttpIncoming ( { headers : { } } ) ;
843
+
844
+ incoming . hints . on ( 'complete' , ( ) => {
845
+ t . ok ( true ) ;
846
+ t . end ( ) ;
847
+ } ) ;
848
+
849
+ await component . fetch ( incoming ) ;
850
+
851
+ await server . close ( ) ;
852
+ } ,
853
+ ) ;
854
+
855
+ tap . test (
856
+ 'Resource().fetch - hints complete event emitted once all early hints received - resource is failing' ,
857
+ async ( t ) => {
858
+ t . plan ( 3 ) ;
859
+ const server = new PodletServer ( {
860
+ version : '1.0.0' ,
861
+ assets : {
862
+ js : '/foo/bar.js' ,
863
+ css : '/foo/bar.css' ,
864
+ } ,
865
+ content : '/does/not/exist' ,
866
+ } ) ;
867
+ const service = await server . listen ( ) ;
868
+
869
+ const client = new Client ( { name : 'podiumClient' } ) ;
870
+ const component = client . register ( service . options ) ;
871
+
872
+ const incoming = new HttpIncoming ( { headers : { } } ) ;
873
+
874
+ incoming . hints . on ( 'complete' , ( assets ) => {
875
+ t . ok ( true ) ;
876
+ t . equal ( assets . js . length , 1 ) ;
877
+ t . equal ( assets . css . length , 1 ) ;
878
+ t . end ( ) ;
879
+ } ) ;
880
+
881
+ await component . fetch ( incoming ) ;
882
+
883
+ await server . close ( ) ;
884
+ } ,
885
+ ) ;
886
+
887
+ tap . test (
888
+ 'Resource().fetch - hints complete event emitted once all early hints received - multiple resource components' ,
889
+ async ( t ) => {
890
+ t . plan ( 3 ) ;
891
+ const server1 = new PodletServer ( {
892
+ name : 'one' ,
893
+ version : '1.0.0' ,
894
+ assets : {
895
+ js : '/foo/bar.js' ,
896
+ css : '/foo/bar.css' ,
897
+ } ,
898
+ } ) ;
899
+ const service1 = await server1 . listen ( ) ;
900
+ const server2 = new PodletServer ( {
901
+ name : 'two' ,
902
+ version : '1.0.0' ,
903
+ assets : {
904
+ js : '/foo/bar.js' ,
905
+ css : '/foo/bar.css' ,
906
+ } ,
907
+ } ) ;
908
+ const service2 = await server2 . listen ( ) ;
909
+ const server3 = new PodletServer ( {
910
+ name : 'three' ,
911
+ version : '1.0.0' ,
912
+ assets : {
913
+ js : '/foo/bar.js' ,
914
+ css : '/foo/bar.css' ,
915
+ } ,
916
+ } ) ;
917
+ const service3 = await server3 . listen ( ) ;
918
+
919
+ const client = new Client ( { name : 'podiumClient' } ) ;
920
+ const component1 = client . register ( service1 . options ) ;
921
+ const component2 = client . register ( service2 . options ) ;
922
+ const component3 = client . register ( service3 . options ) ;
923
+
924
+ const incoming = new HttpIncoming ( { headers : { } } ) ;
925
+
926
+ incoming . hints . on ( 'complete' , ( assets ) => {
927
+ t . equal ( assets . js . length , 3 ) ;
928
+ t . equal ( assets . css . length , 3 ) ;
929
+ t . ok ( true ) ;
930
+ t . end ( ) ;
931
+ } ) ;
932
+
933
+ await Promise . all ( [
934
+ component1 . fetch ( incoming ) ,
935
+ component2 . fetch ( incoming ) ,
936
+ component3 . fetch ( incoming ) ,
937
+ ] ) ;
938
+
939
+ await server1 . close ( ) ;
940
+ await server2 . close ( ) ;
941
+ await server3 . close ( ) ;
942
+ } ,
943
+ ) ;
0 commit comments