|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { checkManualChunksCompat } from '../compat.js'; |
| 4 | +import { createMigrationReport } from '../report.js'; |
| 5 | + |
| 6 | +describe('checkManualChunksCompat', () => { |
| 7 | + it('should warn when manualChunks is an object', () => { |
| 8 | + const report = createMigrationReport(); |
| 9 | + checkManualChunksCompat({ manualChunks: { react: ['react', 'react-dom'] } }, report); |
| 10 | + expect(report.warnings).toHaveLength(1); |
| 11 | + expect(report.warnings[0]).toContain('Object-form'); |
| 12 | + expect(report.warnings[0]).toContain('codeSplitting'); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should not warn when manualChunks is a function', () => { |
| 16 | + const report = createMigrationReport(); |
| 17 | + checkManualChunksCompat({ manualChunks: () => undefined }, report); |
| 18 | + expect(report.warnings).toHaveLength(0); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should not warn when manualChunks is not set', () => { |
| 22 | + const report = createMigrationReport(); |
| 23 | + checkManualChunksCompat({}, report); |
| 24 | + expect(report.warnings).toHaveLength(0); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should not warn when output is undefined', () => { |
| 28 | + const report = createMigrationReport(); |
| 29 | + checkManualChunksCompat(undefined, report); |
| 30 | + expect(report.warnings).toHaveLength(0); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should handle array of outputs', () => { |
| 34 | + const report = createMigrationReport(); |
| 35 | + checkManualChunksCompat( |
| 36 | + [{ manualChunks: () => undefined }, { manualChunks: { vendor: ['lodash'] } }], |
| 37 | + report, |
| 38 | + ); |
| 39 | + expect(report.warnings).toHaveLength(1); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should only add one warning for multiple object-form outputs', () => { |
| 43 | + const report = createMigrationReport(); |
| 44 | + checkManualChunksCompat( |
| 45 | + [{ manualChunks: { react: ['react'] } }, { manualChunks: { lodash: ['lodash'] } }], |
| 46 | + report, |
| 47 | + ); |
| 48 | + expect(report.warnings).toHaveLength(1); |
| 49 | + }); |
| 50 | +}); |
0 commit comments