@@ -12,7 +12,6 @@ import { APPLICATION_BUILDER_INFO, BASE_OPTIONS, describeBuilder } from '../setu
1212describeBuilder ( buildApplication , APPLICATION_BUILDER_INFO , ( harness ) => {
1313 describe ( 'Option: "index"' , ( ) => {
1414 beforeEach ( async ( ) => {
15- // Application code is not needed for index tests
1615 await harness . writeFile ( 'src/main.ts' , 'console.log("TEST");' ) ;
1716 } ) ;
1817
@@ -140,92 +139,72 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {
140139 } ) ;
141140 } ) ;
142141
143- it ( 'should generate initial preload link elements when preloadInitial is true' , async ( ) => {
144- harness . useTarget ( 'build' , {
145- ...BASE_OPTIONS ,
146- index : {
147- input : 'src/index.html' ,
148- preloadInitial : true ,
149- } ,
150- } ) ;
151-
152- // Setup an initial chunk usage for JS
153- await harness . writeFile ( 'src/a.ts' , 'console.log("TEST");' ) ;
154- await harness . writeFile ( 'src/b.ts' , 'import "./a";' ) ;
155- await harness . writeFile ( 'src/main.ts' , 'import "./a";\n(() => import("./b"))();' ) ;
142+ describe ( 'preload' , ( ) => {
143+ it ( 'should generate initial preload link elements when preloadInitial is true' , async ( ) => {
144+ harness . useTarget ( 'build' , {
145+ ...BASE_OPTIONS ,
146+ index : {
147+ input : 'src/index.html' ,
148+ preloadInitial : true ,
149+ } ,
150+ } ) ;
156151
157- const { result } = await harness . executeOnce ( ) ;
152+ // Setup an initial chunk usage for JS
153+ await harness . writeFile ( 'src/a.ts' , 'console.log("TEST");' ) ;
154+ await harness . writeFile ( 'src/b.ts' , 'import "./a";' ) ;
155+ await harness . writeFile ( 'src/main.ts' , 'import "./a";\n(() => import("./b"))();' ) ;
158156
159- expect ( result ?. success ) . toBe ( true ) ;
160- harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'chunk-' ) ;
161- harness . expectFile ( 'dist/browser/index.html' ) . content . toContain ( 'modulepreload' ) ;
162- harness . expectFile ( 'dist/browser/index.html' ) . content . toContain ( 'chunk-' ) ;
163- } ) ;
157+ const { result } = await harness . executeOnce ( ) ;
164158
165- it ( 'should generate initial preload link elements when preloadInitial is undefined' , async ( ) => {
166- harness . useTarget ( 'build' , {
167- ...BASE_OPTIONS ,
168- index : {
169- input : 'src/index.html' ,
170- preloadInitial : undefined ,
171- } ,
159+ expect ( result ?. success ) . toBe ( true ) ;
160+ harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'chunk-' ) ;
161+ harness . expectFile ( 'dist/browser/index.html' ) . content . toContain ( 'modulepreload' ) ;
162+ harness . expectFile ( 'dist/browser/index.html' ) . content . toContain ( 'chunk-' ) ;
172163 } ) ;
173164
174- // Setup an initial chunk usage for JS
175- await harness . writeFile ( 'src/a.ts' , 'console.log("TEST");' ) ;
176- await harness . writeFile ( 'src/b.ts' , 'import "./a";' ) ;
177- await harness . writeFile ( 'src/main.ts' , 'import "./a";\n(() => import("./b"))();' ) ;
165+ it ( 'should generate initial preload link elements when preloadInitial is undefined' , async ( ) => {
166+ harness . useTarget ( 'build' , {
167+ ...BASE_OPTIONS ,
168+ index : {
169+ input : 'src/index.html' ,
170+ preloadInitial : undefined ,
171+ } ,
172+ } ) ;
178173
179- const { result } = await harness . executeOnce ( ) ;
174+ // Setup an initial chunk usage for JS
175+ await harness . writeFile ( 'src/a.ts' , 'console.log("TEST");' ) ;
176+ await harness . writeFile ( 'src/b.ts' , 'import "./a";' ) ;
177+ await harness . writeFile ( 'src/main.ts' , 'import "./a";\n(() => import("./b"))();' ) ;
180178
181- expect ( result ?. success ) . toBe ( true ) ;
182- harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'chunk-' ) ;
183- harness . expectFile ( 'dist/browser/index.html' ) . content . toContain ( 'modulepreload' ) ;
184- harness . expectFile ( 'dist/browser/index.html' ) . content . toContain ( 'chunk-' ) ;
185- } ) ;
179+ const { result } = await harness . executeOnce ( ) ;
186180
187- it ( 'should not generate initial preload link elements when preloadInitial is false' , async ( ) => {
188- harness . useTarget ( 'build' , {
189- ...BASE_OPTIONS ,
190- index : {
191- input : 'src/index.html' ,
192- preloadInitial : false ,
193- } ,
181+ expect ( result ?. success ) . toBe ( true ) ;
182+ harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'chunk-' ) ;
183+ harness . expectFile ( 'dist/browser/index.html' ) . content . toContain ( 'modulepreload' ) ;
184+ harness . expectFile ( 'dist/browser/index.html' ) . content . toContain ( 'chunk-' ) ;
194185 } ) ;
195186
196- // Setup an initial chunk usage for JS
197- await harness . writeFile ( 'src/a.ts' , 'console.log("TEST");' ) ;
198- await harness . writeFile ( 'src/b.ts' , 'import "./a";' ) ;
199- await harness . writeFile ( 'src/main.ts' , 'import "./a";\n(() => import("./b"))();' ) ;
200-
201- const { result } = await harness . executeOnce ( ) ;
202-
203- expect ( result ?. success ) . toBe ( true ) ;
204- harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'chunk-' ) ;
205- harness . expectFile ( 'dist/browser/index.html' ) . content . not . toContain ( 'modulepreload' ) ;
206- harness . expectFile ( 'dist/browser/index.html' ) . content . not . toContain ( 'chunk-' ) ;
207- } ) ;
187+ it ( 'should not generate initial preload link elements when preloadInitial is false' , async ( ) => {
188+ harness . useTarget ( 'build' , {
189+ ...BASE_OPTIONS ,
190+ index : {
191+ input : 'src/index.html' ,
192+ preloadInitial : false ,
193+ } ,
194+ } ) ;
208195
209- it ( `should generate 'index.csr.html' instead of 'index.html' by default when ssr is enabled.` , async ( ) => {
210- await harness . modifyFile ( 'src/tsconfig.app.json' , ( content ) => {
211- const tsConfig = JSON . parse ( content ) ;
212- tsConfig . files ??= [ ] ;
213- tsConfig . files . push ( 'main.server.ts' ) ;
196+ // Setup an initial chunk usage for JS
197+ await harness . writeFile ( 'src/a.ts' , 'console.log("TEST");' ) ;
198+ await harness . writeFile ( 'src/b.ts' , 'import "./a";' ) ;
199+ await harness . writeFile ( 'src/main.ts' , 'import "./a";\n(() => import("./b"))();' ) ;
214200
215- return JSON . stringify ( tsConfig ) ;
216- } ) ;
201+ const { result } = await harness . executeOnce ( ) ;
217202
218- harness . useTarget ( 'build' , {
219- ... BASE_OPTIONS ,
220- server : 'src/main.server.ts' ,
221- ssr : true ,
203+ expect ( result ?. success ) . toBe ( true ) ;
204+ harness . expectFile ( 'dist/browser/main.js' ) . content . toContain ( 'chunk-' ) ;
205+ harness . expectFile ( 'dist/browser/index.html' ) . content . not . toContain ( 'modulepreload' ) ;
206+ harness . expectFile ( 'dist/browser/index.html' ) . content . not . toContain ( 'chunk-' ) ;
222207 } ) ;
223-
224- const { result } = await harness . executeOnce ( ) ;
225- expect ( result ?. success ) . toBeTrue ( ) ;
226- harness . expectDirectory ( 'dist/server' ) . toExist ( ) ;
227- harness . expectFile ( 'dist/browser/index.csr.html' ) . toExist ( ) ;
228- harness . expectFile ( 'dist/browser/index.html' ) . toNotExist ( ) ;
229208 } ) ;
230209 } ) ;
231210} ) ;
0 commit comments