Skip to content

Commit

Permalink
test: add a test case for the path.posix.resolve
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ShGKme authored and targos committed May 28, 2019
1 parent f5bb1b3 commit b83571d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/parallel/test-path-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ if (common.isWindows) {
const resolvedPath = spawnResult.stdout.toString().trim();
assert.strictEqual(resolvedPath.toLowerCase(), process.cwd().toLowerCase());
}

if (!common.isWindows) {
// Test handling relative paths to be safe when process.cwd() fails.
process.cwd = () => '';
assert.strictEqual(process.cwd(), '');
const resolved = path.resolve();
const expected = '.';
assert.strictEqual(resolved, expected);
}

0 comments on commit b83571d

Please sign in to comment.