diff options
-rw-r--r-- | src/bun.js/node/types.zig | 4 | ||||
-rw-r--r-- | test/js/node/path/path.test.js | 22 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/bun.js/node/types.zig b/src/bun.js/node/types.zig index 6bee1243f..2dcbad38f 100644 --- a/src/bun.js/node/types.zig +++ b/src/bun.js/node/types.zig @@ -1556,9 +1556,9 @@ pub const Path = struct { const base_slice = path.slice(); const out = if (isWindows) - std.fs.path.dirnameWindows(base_slice) orelse "C:\\" + std.fs.path.dirnameWindows(base_slice) orelse "." else - std.fs.path.dirnamePosix(base_slice) orelse "/"; + std.fs.path.dirnamePosix(base_slice) orelse "."; return JSC.ZigString.init(out).toValueGC(globalThis); } diff --git a/test/js/node/path/path.test.js b/test/js/node/path/path.test.js index 86807b325..d2880f124 100644 --- a/test/js/node/path/path.test.js +++ b/test/js/node/path/path.test.js @@ -13,6 +13,28 @@ it("should not inherit Object.prototype", () => { expect(path).not.toHaveProperty("toString"); }); +it("path.dirname", () => { + const fixtures = [ + ["yo", "."], + ["/yo", "/"], + ["/yo/", "/"], + ["/yo/123", "/yo"], + [".", "."], + ["../", "."], + ["../../", ".."], + ["../../foo", "../.."], + ["../../foo/../", "../../foo"], + ["/foo/../", "/foo"], + ["../../foo/../bar", "../../foo/.."], + ]; + for (const [input, expected] of fixtures) { + expect(path.posix.dirname(input)).toBe(expected); + if (process.platform !== "win32") { + expect(path.dirname(input)).toBe(expected); + } + } +}); + it("path.basename", () => { strictEqual(path.basename(file), "path.test.js"); strictEqual(path.basename(file, ".js"), "path.test"); |