@@ -9,11 +9,11 @@ import { AssetManifest, loadFiles, LoadFilesOptions } from './loader';
9
9
jest . mock ( '@bigcommerce/script-loader' , ( ) => {
10
10
return {
11
11
getScriptLoader : jest . fn ( ) . mockReturnValue ( {
12
- loadScripts : jest . fn ( ( ) => Promise . resolve ( ) ) ,
12
+ loadScript : jest . fn ( ( ) => Promise . resolve ( ) ) ,
13
13
preloadScripts : jest . fn ( ( ) => Promise . resolve ( ) ) ,
14
14
} ) ,
15
15
getStylesheetLoader : jest . fn ( ) . mockReturnValue ( {
16
- loadStylesheets : jest . fn ( ( ) => Promise . resolve ( ) ) ,
16
+ loadStylesheet : jest . fn ( ( ) => Promise . resolve ( ) ) ,
17
17
preloadStylesheets : jest . fn ( ( ) => Promise . resolve ( ) ) ,
18
18
} ) ,
19
19
} ;
@@ -37,6 +37,16 @@ describe('loadFiles', () => {
37
37
js : [ 'step-a.js' , 'step-b.js' ] ,
38
38
} ,
39
39
js : [ 'vendor.js' , 'main.js' ] ,
40
+ integrity : {
41
+ 'main.js' : 'hash-main-js' ,
42
+ 'main.css' : 'hash-main-css' ,
43
+ 'vendor.js' : 'hash-vendor-js' ,
44
+ 'vendor.css' : 'hash-vendor-css' ,
45
+ 'step-a.js' : 'hash-step-a-js' ,
46
+ 'step-b.js' : 'hash-step-b-js' ,
47
+ 'step-a.css' : 'hash-step-a-css' ,
48
+ 'step-b.css' : 'hash-step-b-css' ,
49
+ } ,
40
50
} ;
41
51
42
52
( global as any ) . MANIFEST_JSON = manifestJson ;
@@ -46,6 +56,12 @@ describe('loadFiles', () => {
46
56
renderOrderConfirmation : jest . fn ( ) ,
47
57
initializeLanguageService : jest . fn ( ) ,
48
58
} ;
59
+ ( global as any ) . PRELOAD_ASSETS = [
60
+ 'step-a.js' ,
61
+ 'step-b.js' ,
62
+ 'step-a.css' ,
63
+ 'step-b.css' ,
64
+ ] ;
49
65
} ) ;
50
66
51
67
afterEach ( ( ) => {
@@ -57,19 +73,39 @@ describe('loadFiles', () => {
57
73
it ( 'loads required JS files listed in manifest' , async ( ) => {
58
74
await loadFiles ( options ) ;
59
75
60
- expect ( getScriptLoader ( ) . loadScripts ) . toHaveBeenCalledWith ( [
61
- 'https://cdn.foo.bar/vendor.js' ,
62
- 'https://cdn.foo.bar/main.js' ,
63
- ] ) ;
76
+ expect ( getScriptLoader ( ) . loadScript ) . toHaveBeenCalledWith ( 'https://cdn.foo.bar/vendor.js' , {
77
+ async : false ,
78
+ attributes : {
79
+ crossorigin : 'anonymous' ,
80
+ integrity : 'hash-vendor-js' ,
81
+ } ,
82
+ } ) ;
83
+ expect ( getScriptLoader ( ) . loadScript ) . toHaveBeenCalledWith ( 'https://cdn.foo.bar/main.js' , {
84
+ async : false ,
85
+ attributes : {
86
+ crossorigin : 'anonymous' ,
87
+ integrity : 'hash-main-js' ,
88
+ } ,
89
+ } ) ;
64
90
} ) ;
65
91
66
92
it ( 'loads required CSS files listed in manifest' , async ( ) => {
67
93
await loadFiles ( options ) ;
68
94
69
- expect ( getStylesheetLoader ( ) . loadStylesheets ) . toHaveBeenCalledWith (
70
- [ 'https://cdn.foo.bar/vendor.css' , 'https://cdn.foo.bar/main.css' ] ,
71
- { prepend : true } ,
72
- ) ;
95
+ expect ( getStylesheetLoader ( ) . loadStylesheet ) . toHaveBeenCalledWith ( 'https://cdn.foo.bar/vendor.css' , {
96
+ prepend : true ,
97
+ attributes : {
98
+ crossorigin : 'anonymous' ,
99
+ integrity : 'hash-vendor-css' ,
100
+ } ,
101
+ } ) ;
102
+ expect ( getStylesheetLoader ( ) . loadStylesheet ) . toHaveBeenCalledWith ( 'https://cdn.foo.bar/main.css' , {
103
+ prepend : true ,
104
+ attributes : {
105
+ crossorigin : 'anonymous' ,
106
+ integrity : 'hash-main-css' ,
107
+ } ,
108
+ } ) ;
73
109
} ) ;
74
110
75
111
it ( 'prefetches dynamic JS chunks listed in manifest' , async ( ) => {
0 commit comments