From 0dace4f05ed54ae42fb7a25672bac227aa7b9bf9 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 14 Aug 2025 22:49:13 +0200 Subject: [PATCH] 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. --- test/parallel/parallel.status | 3 --- ...fs-cp-sync-copy-symlink-not-pointing-to-folder.mjs | 11 +++++++++-- ...t-fs-cp-sync-resolve-relative-symlinks-default.mjs | 11 +++++++++-- ...est-fs-cp-sync-resolve-relative-symlinks-false.mjs | 11 +++++++++-- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index 76e46b80719e07..a46d3c52b1500e 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -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 diff --git a/test/parallel/test-fs-cp-sync-copy-symlink-not-pointing-to-folder.mjs b/test/parallel/test-fs-cp-sync-copy-symlink-not-pointing-to-folder.mjs index d23a2c8be63e6c..fa5ec6a7dbc821 100644 --- a/test/parallel/test-fs-cp-sync-copy-symlink-not-pointing-to-folder.mjs +++ b/test/parallel/test-fs-cp-sync-copy-symlink-not-pointing-to-folder.mjs @@ -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); +} diff --git a/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-default.mjs b/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-default.mjs index 070fabd438749e..7c7622ed4050b2 100644 --- a/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-default.mjs +++ b/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-default.mjs @@ -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')); +} diff --git a/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-false.mjs b/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-false.mjs index e5f59d655f33f7..ac1ec01fd0b6ef 100644 --- a/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-false.mjs +++ b/test/parallel/test-fs-cp-sync-resolve-relative-symlinks-false.mjs @@ -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')); +}