|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { resolvePublicPath } from '../publicPath'; |
| 3 | +import { getDefaultMockOptions } from './helpers'; |
| 4 | + |
| 5 | +describe('resolvePublicPath', () => { |
| 6 | + const mockOptions = getDefaultMockOptions(); |
| 7 | + |
| 8 | + it('should return explicitly set publicPath when provided', () => { |
| 9 | + const options = { |
| 10 | + ...mockOptions, |
| 11 | + publicPath: 'https://cdn.example.com/', |
| 12 | + }; |
| 13 | + expect(resolvePublicPath(options, '/vite/')).toBe('https://cdn.example.com/'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should return "auto" when originalBase is empty string', () => { |
| 17 | + expect(resolvePublicPath(mockOptions, '/vite/', '')).toBe('auto'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should return viteBase with trailing slash when provided', () => { |
| 21 | + expect(resolvePublicPath(mockOptions, '/vite')).toBe('/vite/'); |
| 22 | + expect(resolvePublicPath(mockOptions, '/vite/')).toBe('/vite/'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should return "auto" when no base is specified', () => { |
| 26 | + expect(resolvePublicPath(mockOptions, '')).toBe('auto'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should return "auto" when base is undefined', () => { |
| 30 | + expect(resolvePublicPath(mockOptions, undefined as unknown as string)).toBe('auto'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('should prioritize publicPath over viteBase when both are provided', () => { |
| 34 | + const options = { |
| 35 | + ...mockOptions, |
| 36 | + publicPath: 'https://custom.example/', |
| 37 | + }; |
| 38 | + expect(resolvePublicPath(options, '/vite/')).toBe('https://custom.example/'); |
| 39 | + }); |
| 40 | +}); |
0 commit comments