Skip to content

Commit 7f457f8

Browse files
joyeecheungtargos
authored andcommitted
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: #59475 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com>
1 parent 3e1551d commit 7f457f8

4 files changed

+27
-9
lines changed

test/parallel/parallel.status

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@ test-async-context-frame: PASS, FLAKY
2626
test-runner-run-watch: PASS, FLAKY
2727
# https://github.com/nodejs/node/pull/59408#issuecomment-3170650933
2828
test-fs-cp-sync-error-on-exist: PASS, FLAKY
29-
test-fs-cp-sync-copy-symlink-not-pointing-to-folder: PASS, FLAKY
3029
test-fs-cp-sync-symlink-points-to-dest-error: PASS, FLAKY
31-
test-fs-cp-sync-resolve-relative-symlinks-false: PASS, FLAKY
3230
test-fs-cp-async-symlink-points-to-dest: PASS, FLAKY
3331
test-fs-cp-sync-unicode-folder-names: PASS, FLAKY
34-
test-fs-cp-sync-resolve-relative-symlinks-default: PASS, FLAKY
3532

3633
# https://github.com/nodejs/node/issues/56751
3734
test-without-async-context-frame: PASS, FLAKY

test/parallel/test-fs-cp-sync-copy-symlink-not-pointing-to-folder.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This tests that cpSync copies link if it does not point to folder in src.
2-
import { mustNotMutateObjectDeep } from '../common/index.mjs';
2+
import { mustNotMutateObjectDeep, isWindows } from '../common/index.mjs';
33
import { nextdir } from '../common/fs.js';
44
import assert from 'node:assert';
55
import { cpSync, mkdirSync, symlinkSync, readlinkSync } from 'node:fs';
@@ -16,4 +16,11 @@ mkdirSync(join(dest, 'a'), mustNotMutateObjectDeep({ recursive: true }));
1616
symlinkSync(dest, join(dest, 'a', 'c'));
1717
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
1818
const link = readlinkSync(join(dest, 'a', 'c'));
19-
assert.strictEqual(link, src);
19+
20+
if (isWindows) {
21+
// On Windows, readlinkSync() may return a path with uppercase drive letter,
22+
// but paths are case-insensitive.
23+
assert.strictEqual(link.toLowerCase(), src.toLowerCase());
24+
} else {
25+
assert.strictEqual(link, src);
26+
}

test/parallel/test-fs-cp-sync-resolve-relative-symlinks-default.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This tests that cpSync resolves relative symlinks to their absolute path by default.
2-
import { mustNotMutateObjectDeep } from '../common/index.mjs';
2+
import { mustNotMutateObjectDeep, isWindows } from '../common/index.mjs';
33
import { nextdir } from '../common/fs.js';
44
import assert from 'node:assert';
55
import { cpSync, mkdirSync, writeFileSync, symlinkSync, readlinkSync } from 'node:fs';
@@ -18,4 +18,11 @@ mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true }));
1818

1919
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true }));
2020
const link = readlinkSync(join(dest, 'bar.js'));
21-
assert.strictEqual(link, join(src, 'foo.js'));
21+
22+
if (isWindows) {
23+
// On Windows, readlinkSync() may return a path with uppercase drive letter,
24+
// but paths are case-insensitive.
25+
assert.strictEqual(link.toLowerCase(), join(src, 'foo.js').toLowerCase());
26+
} else {
27+
assert.strictEqual(link, join(src, 'foo.js'));
28+
}

test/parallel/test-fs-cp-sync-resolve-relative-symlinks-false.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// This tests that cpSync resolves relative symlinks when verbatimSymlinks is false.
2-
import { mustNotMutateObjectDeep } from '../common/index.mjs';
2+
import { mustNotMutateObjectDeep, isWindows } from '../common/index.mjs';
33
import { nextdir } from '../common/fs.js';
44
import assert from 'node:assert';
55
import { cpSync, mkdirSync, writeFileSync, symlinkSync, readlinkSync } from 'node:fs';
@@ -18,4 +18,11 @@ mkdirSync(dest, mustNotMutateObjectDeep({ recursive: true }));
1818

1919
cpSync(src, dest, mustNotMutateObjectDeep({ recursive: true, verbatimSymlinks: false }));
2020
const link = readlinkSync(join(dest, 'bar.js'));
21-
assert.strictEqual(link, join(src, 'foo.js'));
21+
22+
if (isWindows) {
23+
// On Windows, readlinkSync() may return a path with uppercase drive letter,
24+
// but paths are case-insensitive.
25+
assert.strictEqual(link.toLowerCase(), join(src, 'foo.js').toLowerCase());
26+
} else {
27+
assert.strictEqual(link, join(src, 'foo.js'));
28+
}

0 commit comments

Comments
 (0)