| 
									
										
										
										
											2022-08-25 16:54:30 +08:00
										 |  |  | import * as path from 'path'; | 
					
						
							|  |  |  | import * as fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2022-09-07 14:49:54 +08:00
										 |  |  | import { expect, test, describe, afterAll } from 'vitest'; | 
					
						
							| 
									
										
										
										
											2022-08-25 16:54:30 +08:00
										 |  |  | import { buildFixture } from '../utils/build'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const example = 'single-route'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe(`build ${example}`, () => { | 
					
						
							|  |  |  |   let sizeWithOptimize = 0; | 
					
						
							|  |  |  |   let sizeWithoutOptimize = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test('optimize router', async () => { | 
					
						
							|  |  |  |     await buildFixture(example, { | 
					
						
							| 
									
										
										
										
											2022-09-07 14:49:54 +08:00
										 |  |  |       config: 'optimization.config.mts', | 
					
						
							| 
									
										
										
										
											2022-08-25 16:54:30 +08:00
										 |  |  |     }); | 
					
						
							|  |  |  |     const dataLoaderPath = path.join(__dirname, `../../examples/${example}/build/js/framework.js`); | 
					
						
							|  |  |  |     sizeWithOptimize = fs.statSync(dataLoaderPath).size; | 
					
						
							|  |  |  |   }, 120000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test('disable optimize router', async () => { | 
					
						
							|  |  |  |     await buildFixture(example); | 
					
						
							|  |  |  |     const dataLoaderPath = path.join(__dirname, `../../examples/${example}/build/js/framework.js`); | 
					
						
							|  |  |  |     sizeWithoutOptimize = fs.statSync(dataLoaderPath).size; | 
					
						
							|  |  |  |   }, 120000); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   afterAll(async () => { | 
					
						
							|  |  |  |     expect(sizeWithOptimize).toBeLessThan(sizeWithoutOptimize); | 
					
						
							| 
									
										
										
										
											2022-09-07 14:49:54 +08:00
										 |  |  |     expect(sizeWithoutOptimize - sizeWithOptimize).toBeGreaterThan(6 * 1024); // reduce more than 6kb after minify
 | 
					
						
							| 
									
										
										
										
											2022-08-25 16:54:30 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | }); |