Skip to content

Commit b83571d

Browse files
ShGKmetargos
authored andcommitted
test: add a test case for the path.posix.resolve
In posix path.resolve should handle relative paths to be safe even if process.cwd fails. At lib/path.js#999: return resolvedPath.length > 0 ? resolvedPath : '.'; Else branch wasn't covered. Add a test case to cover this. PR-URL: #27905 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Сковорода Никита Андреевич <[email protected]>
1 parent f5bb1b3 commit b83571d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

test/parallel/test-path-resolve.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,12 @@ if (common.isWindows) {
6969
const resolvedPath = spawnResult.stdout.toString().trim();
7070
assert.strictEqual(resolvedPath.toLowerCase(), process.cwd().toLowerCase());
7171
}
72+
73+
if (!common.isWindows) {
74+
// Test handling relative paths to be safe when process.cwd() fails.
75+
process.cwd = () => '';
76+
assert.strictEqual(process.cwd(), '');
77+
const resolved = path.resolve();
78+
const expected = '.';
79+
assert.strictEqual(resolved, expected);
80+
}

0 commit comments

Comments
 (0)