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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Grigorii K. Shartsev 2019-05-26 17:10:38 +03:00 committed by Сковорода Никита Андреевич
parent 55de6ff38d
commit e3555e9c2b

View File

@ -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);
}