|
1 | 1 | import { describe, expect, test } from 'vitest' |
2 | | -import { isFileInTargetPath } from '../static' |
| 2 | +import { isFileInTargetPath, looksLikeWindowsShortNamePath } from '../static' |
3 | 3 |
|
4 | 4 | describe('isFileInTargetPath', () => { |
5 | 5 | const cases = { |
@@ -27,3 +27,38 @@ describe('isFileInTargetPath', () => { |
27 | 27 | } |
28 | 28 | } |
29 | 29 | }) |
| 30 | + |
| 31 | +describe('looksLikeWindowsShortNamePath', () => { |
| 32 | + const shortNamePaths = [ |
| 33 | + // classic 8.3 short names |
| 34 | + 'C:/PROGRA~1/x', |
| 35 | + 'C:/PROGRA~1', |
| 36 | + 'C:/LONGFI~1.TXT', |
| 37 | + 'C:/MICROS~2/foo', |
| 38 | + // short-name-looking directory ancestor, not just the basename |
| 39 | + 'C:/foo/DOCUME~1/bar.js', |
| 40 | + ] |
| 41 | + const legitimateTildePaths = [ |
| 42 | + // real-world case from the reported issue: `~` not followed by a digit |
| 43 | + 'C:/project/dist/0~rslib-runtime.js', |
| 44 | + // ancestor directory containing a tilde that isn't short-name shaped |
| 45 | + 'C:/Users/foo~bar/project/index.js', |
| 46 | + // tilde-prefixed name with no short-name-style prefix/digit suffix |
| 47 | + 'C:/Users/foo/~backup/index.js', |
| 48 | + // prefix longer than the 6 characters a short name can have |
| 49 | + 'C:/project/confirmations~2/index.js', |
| 50 | + // no tilde at all |
| 51 | + 'C:/Users/foo/project/index.js', |
| 52 | + ] |
| 53 | + |
| 54 | + for (const filePath of shortNamePaths) { |
| 55 | + test(`looksLikeWindowsShortNamePath("${filePath}") is true`, () => { |
| 56 | + expect(looksLikeWindowsShortNamePath(filePath)).toBe(true) |
| 57 | + }) |
| 58 | + } |
| 59 | + for (const filePath of legitimateTildePaths) { |
| 60 | + test(`looksLikeWindowsShortNamePath("${filePath}") is false`, () => { |
| 61 | + expect(looksLikeWindowsShortNamePath(filePath)).toBe(false) |
| 62 | + }) |
| 63 | + } |
| 64 | +}) |
0 commit comments