|
1 | 1 | import { describe, expect, it } from 'vitest' |
2 | | -import { defuOverrideArray, groupBy, isMap, isRegexp, noop, regExpTest, removeExt } from '@/index' |
| 2 | +import { |
| 3 | + cleanUrl, |
| 4 | + defuOverrideArray, |
| 5 | + ensurePosix, |
| 6 | + groupBy, |
| 7 | + isHttp, |
| 8 | + isMap, |
| 9 | + isRegexp, |
| 10 | + noop, |
| 11 | + normalizeRelativeImport, |
| 12 | + normalizeRoot, |
| 13 | + regExpTest, |
| 14 | + removeExt, |
| 15 | + toArray, |
| 16 | +} from '@/index' |
3 | 17 |
|
4 | 18 | describe('shared utils', () => { |
5 | 19 | it('isRegexp correctly detects regular expressions', () => { |
@@ -94,4 +108,35 @@ describe('shared utils', () => { |
94 | 108 | it('noop returns undefined without side effects', () => { |
95 | 109 | expect(noop()).toBeUndefined() |
96 | 110 | }) |
| 111 | + |
| 112 | + it('toArray normalizes values to arrays', () => { |
| 113 | + expect(toArray(null)).toEqual([]) |
| 114 | + expect(toArray('a')).toEqual(['a']) |
| 115 | + expect(toArray(['a', 'b'])).toEqual(['a', 'b']) |
| 116 | + }) |
| 117 | + |
| 118 | + it('ensurePosix normalizes windows separators', () => { |
| 119 | + expect(ensurePosix('C:\\Users\\file.css')).toBe('C:/Users/file.css') |
| 120 | + }) |
| 121 | + |
| 122 | + it('normalizeRoot trims and normalizes root paths', () => { |
| 123 | + expect(normalizeRoot('./src/')).toBe('src') |
| 124 | + expect(normalizeRoot(' /src/app ')).toBe('src/app') |
| 125 | + }) |
| 126 | + |
| 127 | + it('normalizeRelativeImport prepends dot for bare paths', () => { |
| 128 | + expect(normalizeRelativeImport('styles/index.css')).toBe('./styles/index.css') |
| 129 | + expect(normalizeRelativeImport('./styles/index.css')).toBe('./styles/index.css') |
| 130 | + expect(normalizeRelativeImport('/styles/index.css')).toBe('/styles/index.css') |
| 131 | + }) |
| 132 | + |
| 133 | + it('cleanUrl strips query and hash', () => { |
| 134 | + expect(cleanUrl('style.css?inline#hash')).toBe('style.css') |
| 135 | + }) |
| 136 | + |
| 137 | + it('isHttp detects http/https urls', () => { |
| 138 | + expect(isHttp('http://example.com')).toBe(true) |
| 139 | + expect(isHttp('https://example.com')).toBe(true) |
| 140 | + expect(isHttp('ftp://example.com')).toBe(false) |
| 141 | + }) |
97 | 142 | }) |
0 commit comments