Skip to content

Commit

Permalink
test: simplify test-path-resolve.js
Browse files Browse the repository at this point in the history
PR-URL: #38671
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
himself65 authored and danielleadams committed May 31, 2021
1 parent 7d3a8cb commit e91d14c
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions test/parallel/test-path-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,24 @@ const resolveTests = [
],
],
];
resolveTests.forEach((test) => {
const resolve = test[0];
test[1].forEach((test) => {
const actual = resolve.apply(null, test[0]);
resolveTests.forEach(([resolve, tests]) => {
tests.forEach(([test, expected]) => {
const actual = resolve.apply(null, test);
let actualAlt;
const os = resolve === path.win32.resolve ? 'win32' : 'posix';
if (resolve === path.win32.resolve && !common.isWindows)
actualAlt = actual.replace(backslashRE, '/');
else if (resolve !== path.win32.resolve && common.isWindows)
actualAlt = actual.replace(slashRE, '\\');

const expected = test[1];
const message =
`path.${os}.resolve(${test[0].map(JSON.stringify).join(',')})\n expect=${
`path.${os}.resolve(${test.map(JSON.stringify).join(',')})\n expect=${
JSON.stringify(expected)}\n actual=${JSON.stringify(actual)}`;
if (actual !== expected && actualAlt !== expected)
failures.push(`\n${message}`);
failures.push(message);
});
});
assert.strictEqual(failures.length, 0, failures.join(''));
assert.strictEqual(failures.length, 0, failures.join('\n'));

if (common.isWindows) {
// Test resolving the current Windows drive letter from a spawned process.
Expand Down

0 comments on commit e91d14c

Please sign in to comment.