node/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-default.mjs
Joyee Cheung f3d248b921
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>
2025-08-16 22:08:36 +00:00

29 lines
1.1 KiB
JavaScript

// This tests that cpSync resolves relative symlinks to their absolute path by default.
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';
import { join } from 'node:path';
import tmpdir from '../common/tmpdir.js';
tmpdir.refresh();
const src = nextdir();
mkdirSync(src, mustNotMutateObjectDeep({ recursive: true }));
writeFileSync(join(src, 'foo.js'), 'foo', 'utf8');
symlinkSync('foo.js', join(src, 'bar.js'));
const dest = nextdir();
mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true }));
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
const link = readlinkSync(join(dest, 'bar.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'));
}