|
1 | 1 | import { describe, it, expect } from "vitest";
|
2 |
| - |
| 2 | +import { isWindows } from 'std-env' |
3 | 3 | import {
|
4 | 4 | isNodeBuiltin,
|
5 | 5 | sanitizeFilePath,
|
@@ -159,27 +159,33 @@ describe("lookupNodeModuleSubpath", () => {
|
159 | 159 | });
|
160 | 160 |
|
161 | 161 | describe("fileURLToPath", () => {
|
162 |
| - const tests = [ |
163 |
| - // ["file:///C:/path/", "C:\\path\\"], // TODO |
164 |
| - // ["file://nas/foo.txt", "\\\\nas\\foo.txt"], // TODO |
| 162 | + const tests = isWindows ? [ |
| 163 | + ["file:///C:/path/", "C:/path/"], |
| 164 | + ["file://nas/foo.txt", "//nas/foo.txt"], |
| 165 | + ["file://C:/你好.txt", "C:/你好.txt"], |
| 166 | + ["file://C:/hello world", "C:/hello world"], |
| 167 | + ] as const : [ |
165 | 168 | ["file:///你好.txt", "/你好.txt"],
|
166 | 169 | ["file:///hello world", "/hello world"],
|
167 | 170 | ] as const;
|
168 |
| - for (const t of tests) { |
169 |
| - it(`${t[0]} should resolve to ${t[1]}`, () => { |
170 |
| - expect(fileURLToPath(t[0])).toBe(t[1]); |
| 171 | + for (const [input, output] of tests) { |
| 172 | + it(`${input} should resolve to ${output}`, () => { |
| 173 | + expect(fileURLToPath(input)).toBe(output); |
171 | 174 | });
|
172 | 175 | }
|
173 | 176 | });
|
174 | 177 |
|
175 | 178 | describe("pathToFileURL", () => {
|
176 |
| - const tests = [ |
| 179 | + const tests = isWindows ? [ |
| 180 | + ["/foo#1", /file:\/\/\/\w:\/foo%231/ ], |
| 181 | + ["/some/path%.c", /file:\/\/\/\w:\/some\/path%25.c/], |
| 182 | + ] as const :[ |
177 | 183 | ["/foo#1", "file:///foo%231"],
|
178 | 184 | ["/some/path%.c", "file:///some/path%25.c"],
|
179 | 185 | ] as const;
|
180 |
| - for (const t of tests) { |
181 |
| - it(`${t[0]} should resolve to ${t[1]}`, () => { |
182 |
| - expect(pathToFileURL(t[0])).toBe(t[1]); |
| 186 | + for (const [input, output] of tests) { |
| 187 | + it(`${input} should resolve to ${output}`, () => { |
| 188 | + expect(pathToFileURL(input)).toMatch(output); |
183 | 189 | });
|
184 | 190 | }
|
185 | 191 | });
|
0 commit comments