From e3555e9c2b2877d1214474647a6bae6207046bfb Mon Sep 17 00:00:00 2001 From: "Grigorii K. Shartsev" Date: Sun, 26 May 2019 17:10:38 +0300 Subject: [PATCH] test: add a test case for the path.posix.resolve MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Ujjwal Sharma Reviewed-By: Rich Trott Reviewed-By: Gireesh Punathil Reviewed-By: Сковорода Никита Андреевич --- test/parallel/test-path-resolve.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/parallel/test-path-resolve.js b/test/parallel/test-path-resolve.js index e9e6d83ff54..ed3c7c4c5a0 100644 --- a/test/parallel/test-path-resolve.js +++ b/test/parallel/test-path-resolve.js @@ -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); +}