test: use case-insensitive path checking on Windows in fs.cpSync tests

In certain machine configurations on Windows, fs.readlinkSync() may
return a path with upper case drive letter while the other paths may be
constructed from a base path with a lower case drive letter (e.g.
from process.cwd()). Checking path mismatch in a case-sensitive
manner can lead to failure in some tests, specifically with the
Windows machine configurations in the Jenkins CI. Since paths
are case-insensitive on Windows anyway, compare them in a
case-insensitive manner in the tests.

PR-URL: https://github.com/nodejs/node/pull/59475
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
This commit is contained in:
Joyee Cheung 2025-08-17 00:08:36 +02:00 committed by GitHub
parent 80fb4fe2a2
commit f3d248b921
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 9 deletions

View File

@ -26,12 +26,9 @@ test-async-context-frame: PASS, FLAKY
test-runner-run-watch: PASS, FLAKY
# https://github.com/nodejs/node/pull/59408#issuecomment-3170650933
test-fs-cp-sync-error-on-exist: PASS, FLAKY
test-fs-cp-sync-copy-symlink-not-pointing-to-folder: PASS, FLAKY
test-fs-cp-sync-symlink-points-to-dest-error: PASS, FLAKY
test-fs-cp-sync-resolve-relative-symlinks-false: PASS, FLAKY
test-fs-cp-async-symlink-points-to-dest: PASS, FLAKY
test-fs-cp-sync-unicode-folder-names: PASS, FLAKY
test-fs-cp-sync-resolve-relative-symlinks-default: PASS, FLAKY
# https://github.com/nodejs/node/issues/56751
test-without-async-context-frame: PASS, FLAKY

View File

@ -1,5 +1,5 @@
// This tests that cpSync copies link if it does not point to folder in src.
import { mustNotMutateObjectDeep } from '../common/index.mjs';
import { mustNotMutateObjectDeep, isWindows } from '../common/index.mjs';
import { nextdir } from '../common/fs.js';
import assert from 'node:assert';
import { cpSync, mkdirSync, symlinkSync, readlinkSync } from 'node:fs';
@ -16,4 +16,11 @@ mkdirSync(join(dest, 'a'), mustNotMutateObjectDeep({ recursive: true }));
symlinkSync(dest, join(dest, 'a', 'c'));
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
const link = readlinkSync(join(dest, 'a', 'c'));
assert.strictEqual(link, src);
if (isWindows) {
// On Windows, readlinkSync() may return a path with uppercase drive letter,
// but paths are case-insensitive.
assert.strictEqual(link.toLowerCase(), src.toLowerCase());
} else {
assert.strictEqual(link, src);
}

View File

@ -1,5 +1,5 @@
// This tests that cpSync resolves relative symlinks to their absolute path by default.
import { mustNotMutateObjectDeep } from '../common/index.mjs';
import { mustNotMutateObjectDeep, isWindows } from '../common/index.mjs';
import { nextdir } from '../common/fs.js';
import assert from 'node:assert';
import { cpSync, mkdirSync, writeFileSync, symlinkSync, readlinkSync } from 'node:fs';
@ -18,4 +18,11 @@ mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true }));
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
const link = readlinkSync(join(dest, 'bar.js'));
assert.strictEqual(link, join(src, 'foo.js'));
if (isWindows) {
// On Windows, readlinkSync() may return a path with uppercase drive letter,
// but paths are case-insensitive.
assert.strictEqual(link.toLowerCase(), join(src, 'foo.js').toLowerCase());
} else {
assert.strictEqual(link, join(src, 'foo.js'));
}

View File

@ -1,5 +1,5 @@
// This tests that cpSync resolves relative symlinks when verbatimSymlinks is false.
import { mustNotMutateObjectDeep } from '../common/index.mjs';
import { mustNotMutateObjectDeep, isWindows } from '../common/index.mjs';
import { nextdir } from '../common/fs.js';
import assert from 'node:assert';
import { cpSync, mkdirSync, writeFileSync, symlinkSync, readlinkSync } from 'node:fs';
@ -18,4 +18,11 @@ mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true }));
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true, verbatimSymlinks: false }));
const link = readlinkSync(join(dest, 'bar.js'));
assert.strictEqual(link, join(src, 'foo.js'));
if (isWindows) {
// On Windows, readlinkSync() may return a path with uppercase drive letter,
// but paths are case-insensitive.
assert.strictEqual(link.toLowerCase(), join(src, 'foo.js').toLowerCase());
} else {
assert.strictEqual(link, join(src, 'foo.js'));
}