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 <anna@addaleax.net>
Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
  • 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.