1+ function abortable ( fn ) {
2+ return new Promise ( ( resolve ) => {
3+ const timeoutId = setTimeout ( ( ) => {
4+ fn = undefined ;
5+ resolve ( 'Promise resolved after delay' ) ;
6+ clearTimeout ( timeoutId ) ;
7+ } , 1000 ) ;
8+
9+ return fn ( ) ;
10+ } ) ;
11+ }
12+
113it ( "should set fetchPriority" , ( ) => {
214 // Single Chunk
3- import ( /* webpackFetchPriority: "high" */ "./a" ) ;
15+ abortable ( ( ) => import ( /* webpackFetchPriority: "high" */ "./a" ) ) ;
416 expect ( document . head . _children ) . toHaveLength ( 1 ) ;
517 const script1 = document . head . _children [ 0 ] ;
618 expect ( script1 . _attributes . fetchpriority ) . toBe ( "high" ) ;
719
820 // Multiple Chunks
9- import ( /* webpackFetchPriority: "high" */ "./b" ) ;
10- import ( /* webpackFetchPriority: "high" */ "./b2" ) ;
21+ abortable ( ( ) => import ( /* webpackFetchPriority: "high" */ "./b" ) ) ;
22+ abortable ( ( ) => import ( /* webpackFetchPriority: "high" */ "./b2" ) ) ;
1123 expect ( document . head . _children ) . toHaveLength ( 4 ) ;
1224 const script2 = document . head . _children [ 1 ] ;
1325 const script3 = document . head . _children [ 2 ] ;
@@ -17,19 +29,19 @@ it("should set fetchPriority", () => {
1729 expect ( script4 . _attributes . fetchpriority ) . toBe ( "high" ) ;
1830
1931 // Single Chunk, low
20- import ( /* webpackFetchPriority: "low" */ "./c" ) ;
32+ abortable ( ( ) => import ( /* webpackFetchPriority: "low" */ "./c" ) ) ;
2133 expect ( document . head . _children ) . toHaveLength ( 5 ) ;
2234 const script5 = document . head . _children [ 4 ] ;
2335 expect ( script5 . _attributes . fetchpriority ) . toBe ( "low" ) ;
2436
2537 // Single Chunk, auto
26- import ( /* webpackFetchPriority: "auto" */ "./d" ) ;
38+ abortable ( ( ) => import ( /* webpackFetchPriority: "auto" */ "./d" ) ) ;
2739 expect ( document . head . _children ) . toHaveLength ( 6 ) ;
2840 const script6 = document . head . _children [ 5 ] ;
2941 expect ( script6 . _attributes . fetchpriority ) . toBe ( "auto" ) ;
3042
3143 // No fetch priority
32- import ( "./e" ) ;
44+ abortable ( ( ) => import ( "./e" ) ) ;
3345 expect ( document . head . _children ) . toHaveLength ( 7 ) ;
3446 const script7 = document . head . _children [ 6 ] ;
3547 expect ( script7 . _attributes . fetchpriority ) . toBeUndefined ( ) ;
@@ -44,49 +56,49 @@ it("should set fetchPriority", () => {
4456 const script8 = document . head . _children [ 7 ] ;
4557 expect ( script8 . _attributes . fetchpriority ) . toBeUndefined ( ) ;
4658
47- import ( /* webpackFetchPriority: "auto" */ "./g" ) ;
59+ abortable ( ( ) => import ( /* webpackFetchPriority: "auto" */ "./g" ) ) ;
4860 expect ( document . head . _children ) . toHaveLength ( 9 ) ;
4961 const script9 = document . head . _children [ 8 ] ;
5062 expect ( script9 . _attributes . fetchpriority ) . toBe ( "auto" ) ;
5163
52- import ( /* webpackFetchPriority: "unknown" */ "./h.js" ) ;
64+ abortable ( ( ) => import ( /* webpackFetchPriority: "unknown" */ "./h.js" ) ) ;
5365 expect ( document . head . _children ) . toHaveLength ( 10 ) ;
5466 const script10 = document . head . _children [ 9 ] ;
5567 expect ( script10 . _attributes . fetchpriority ) . toBeUndefined ( ) ;
5668
57- import ( /* webpackFetchPriority: "high" */ "./i" ) ;
58- import ( /* webpackFetchPriority: "low" */ "./i" ) ;
69+ abortable ( ( ) => import ( /* webpackFetchPriority: "high" */ "./i" ) ) ;
70+ abortable ( ( ) => import ( /* webpackFetchPriority: "low" */ "./i" ) ) ;
5971 expect ( document . head . _children ) . toHaveLength ( 11 ) ;
6072 const script11 = document . head . _children [ 10 ] ;
6173 expect ( script11 . _attributes . fetchpriority ) . toBe ( "high" ) ;
6274
63- import ( /* webpackFetchPriority: "low" */ "./j" ) ;
64- import ( /* webpackFetchPriority: "high" */ "./j" ) ;
75+ abortable ( ( ) => import ( /* webpackFetchPriority: "low" */ "./j" ) ) ;
76+ abortable ( ( ) => import ( /* webpackFetchPriority: "high" */ "./j" ) ) ;
6577 expect ( document . head . _children ) . toHaveLength ( 12 ) ;
6678 const script12 = document . head . _children [ 11 ] ;
6779
6880 expect ( script12 . _attributes . fetchpriority ) . toBe ( "low" ) ;
69- import ( /* webpackFetchPriority: "low" */ "./k" ) ;
70- import ( "./e" ) ;
71- import ( /* webpackFetchPriority: "high" */ "./k" ) ;
72- expect ( document . head . _children ) . toHaveLength ( 13 ) ;
81+ abortable ( ( ) => import ( /* webpackFetchPriority: "low" */ "./k" ) ) ;
82+ abortable ( ( ) => import ( "./e" ) ) ;
83+ abortable ( ( ) => import ( /* webpackFetchPriority: "high" */ "./k" ) ) ;
84+ abortable ( ( ) => expect ( document . head . _children ) . toHaveLength ( 13 ) ) ;
7385 const script13 = document . head . _children [ 12 ] ;
7486 expect ( script13 . _attributes . fetchpriority ) . toBe ( "low" ) ;
7587
7688 __non_webpack_require__ ( "./125.js" ) ;
77- import ( /* webpackFetchPriority: "high" */ "./style.css" ) ;
89+ abortable ( ( ) => import ( /* webpackFetchPriority: "high" */ "./style.css" ) ) ;
7890 expect ( document . head . _children ) . toHaveLength ( 14 ) ;
7991 const link1 = document . head . _children [ 13 ] ;
8092 expect ( link1 . _attributes . fetchpriority ) . toBe ( "high" ) ;
8193
8294 __non_webpack_require__ ( "./499.js" ) ;
83- import ( "./style-1.css" ) ;
95+ abortable ( ( ) => import ( "./style-1.css" ) ) ;
8496 expect ( document . head . _children ) . toHaveLength ( 15 ) ;
8597 const link2 = document . head . _children [ 14 ] ;
8698 expect ( link2 . _attributes . fetchpriority ) . toBeUndefined ( ) ;
8799
88100 __non_webpack_require__ ( "./616.js" ) ;
89- import ( /* webpackFetchPriority: "low" */ "./style-2.css" ) ;
101+ abortable ( ( ) => import ( /* webpackFetchPriority: "low" */ "./style-2.css" ) ) ;
90102 expect ( document . head . _children ) . toHaveLength ( 16 ) ;
91103 const link3 = document . head . _children [ 15 ] ;
92104 expect ( link3 . _attributes . fetchpriority ) . toBe ( "low" ) ;
0 commit comments