@@ -24,32 +24,131 @@ describe('Core: preload plugin', () => {
24
24
} ,
25
25
] ,
26
26
} ) ;
27
- let app = await GarfishInstance . loadApp ( 'vue-app' ) ;
27
+ const app = await GarfishInstance . loadApp ( 'vue-app' ) ;
28
28
await app ?. mount ( ) ;
29
- app ?. addSourceList ( { tagName : 'fetch' , url : "http://localhost/resources/scripts/fetch.js" } ) ;
30
- app ?. addSourceList ( { tagName : 'fetch' , url : "http://localhost/resources/scripts/no-entry.js" } ) ;
31
- app ?. addSourceList ( { tagName : 'style' , url : "http://localhost/resources/scripts/style.js" } ) ;
29
+ app ?. addSourceList ( {
30
+ tagName : 'fetch' ,
31
+ url : 'http://localhost/resources/scripts/fetch.js' ,
32
+ } ) ;
33
+ app ?. addSourceList ( {
34
+ tagName : 'fetch' ,
35
+ url : 'http://localhost/resources/scripts/no-entry.js' ,
36
+ } ) ;
37
+ app ?. addSourceList ( {
38
+ tagName : 'fetch' ,
39
+ url : new URL ( 'http://localhost/resources/reactApp.html' ) ,
40
+ } ) ;
41
+ app ?. addSourceList ( {
42
+ tagName : 'fetch' ,
43
+ url : new Request ( 'http://localhost/resources/vue3App.html' ) ,
44
+ } ) ;
45
+ app ?. addSourceList ( {
46
+ tagName : 'style' ,
47
+ url : 'http://localhost/resources/scripts/style.js' ,
48
+ } ) ;
32
49
app ?. addSourceList ( [
33
- { tagName : 'fetch' , url : " http://localhost/resources/scripts/fetch.js" } ,
34
- { tagName : 'script' , url : " http://localhost/resources/index.js" } ,
50
+ { tagName : 'fetch' , url : ' http://localhost/resources/scripts/fetch.js' } ,
51
+ { tagName : 'script' , url : ' http://localhost/resources/index.js' } ,
35
52
] ) ;
53
+ app ?. addSourceList ( {
54
+ tagName : 'fetch' ,
55
+ url : '/resources/scripts/render.js' ,
56
+ } ) ;
57
+ app ?. addSourceList ( {
58
+ tagName : 'script' ,
59
+ url : '/resources/scripts/render.js' ,
60
+ } ) ;
36
61
37
- expect ( app ! . sourceList . length ) . toBe ( 4 ) ;
62
+ expect ( app ! . sourceList . length ) . toBe ( 7 ) ;
38
63
expect ( app ! . sourceList [ 0 ] ) . toMatchObject ( {
39
64
tagName : 'script' ,
40
- url : 'http://localhost/resources/scripts/no-entry.js'
65
+ url : 'http://localhost/resources/scripts/no-entry.js' ,
41
66
} ) ;
42
67
expect ( app ! . sourceList [ 1 ] ) . toMatchObject ( {
43
68
tagName : 'fetch' ,
44
- url : 'http://localhost/resources/scripts/fetch.js'
69
+ url : 'http://localhost/resources/scripts/fetch.js' ,
45
70
} ) ;
46
71
expect ( app ! . sourceList [ 2 ] ) . toMatchObject ( {
47
- tagName : 'style ' ,
48
- url : 'http://localhost/resources/scripts/style.js'
72
+ tagName : 'fetch ' ,
73
+ url : new URL ( 'http://localhost/resources/reactApp.html' ) ,
49
74
} ) ;
50
75
expect ( app ! . sourceList [ 3 ] ) . toMatchObject ( {
76
+ tagName : 'fetch' ,
77
+ url : new Request ( 'http://localhost/resources/vue3App.html' ) ,
78
+ } ) ;
79
+ expect ( app ! . sourceList [ 4 ] ) . toMatchObject ( {
80
+ tagName : 'style' ,
81
+ url : 'http://localhost/resources/scripts/style.js' ,
82
+ } ) ;
83
+ expect ( app ! . sourceList [ 5 ] ) . toMatchObject ( {
51
84
tagName : 'script' ,
52
- url : 'http://localhost/resources/index.js'
85
+ url : 'http://localhost/resources/index.js' ,
86
+ } ) ;
87
+ expect ( app ! . sourceList [ 6 ] ) . toMatchObject ( {
88
+ tagName : 'fetch' ,
89
+ url : '/resources/scripts/render.js' ,
53
90
} ) ;
54
91
} ) ;
92
+
93
+ it ( 'set disableSourceListCollect true will not collect sourceList' , async ( ) => {
94
+ const GarfishInstance = new Garfish ( { } ) ;
95
+ GarfishInstance . run ( {
96
+ disablePreloadApp : false ,
97
+ apps : [
98
+ {
99
+ name : 'vue-app' ,
100
+ entry : vueSubAppEntry ,
101
+ cache : true ,
102
+ disableSourceListCollect : true ,
103
+ } ,
104
+ ] ,
105
+ } ) ;
106
+ const app = await GarfishInstance . loadApp ( 'vue-app' ) ;
107
+ await app ?. mount ( ) ;
108
+
109
+ app ?. addSourceList ( {
110
+ tagName : 'fetch' ,
111
+ url : 'http://localhost/resources/scripts/fetch.js' ,
112
+ } ) ;
113
+ expect ( app ! . sourceList . length ) . toBe ( 0 ) ;
114
+
115
+ await GarfishInstance . loadApp ( 'vue-app' , {
116
+ disableSourceListCollect : false ,
117
+ } ) ;
118
+
119
+ app ?. addSourceList ( {
120
+ tagName : 'fetch' ,
121
+ url : 'http://localhost/resources/scripts/fetch.js' ,
122
+ } ) ;
123
+
124
+ expect ( app ! . appInfo . disableSourceListCollect ) . toBe ( true ) ;
125
+ expect ( app ! . sourceList . length ) . toBe ( 0 ) ;
126
+
127
+ const app2 = await GarfishInstance . loadApp ( 'vue-app' , {
128
+ cache : false ,
129
+ disableSourceListCollect : false ,
130
+ } ) ;
131
+
132
+ expect ( app2 ) . not . toBe ( app ) ;
133
+ expect ( app ! . appInfo . disableSourceListCollect ) . toBe ( true ) ;
134
+ expect ( app2 ! . appInfo . disableSourceListCollect ) . toBe ( false ) ;
135
+ expect ( app2 ! . sourceList . length ) . toBe ( 1 ) ;
136
+
137
+ expect ( app2 ! . sourceList [ 0 ] ) . toMatchObject ( {
138
+ tagName : 'script' ,
139
+ url : 'http://localhost/resources/scripts/no-entry.js' ,
140
+ } ) ;
141
+
142
+ app2 ?. addSourceList ( {
143
+ tagName : 'fetch' ,
144
+ url : 'http://localhost/resources/scripts/fetch.js' ,
145
+ } ) ;
146
+
147
+ expect ( app2 ! . sourceList . length ) . toBe ( 2 ) ;
148
+ expect ( app2 ! . sourceList [ 1 ] ) . toMatchObject ( {
149
+ tagName : 'fetch' ,
150
+ url : 'http://localhost/resources/scripts/fetch.js' ,
151
+ } ) ;
152
+ } ) ;
153
+
55
154
} ) ;
0 commit comments