Skip to content

Commit 8a27474

Browse files
abhi128nandanaduh95
authored andcommitted
test: cover cpSync fast path timestamp preservation
Add test coverage for the native cpSync fast path to ensure it matches the existing timestamp preservation behavior. Signed-off-by: Abhinandan Kumar <abhi128618@gmail.com> PR-URL: #65678 Reviewed-By: LiviaMedeiros <livia@cirno.name>
1 parent 1bbc548 commit 8a27474

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

test/parallel/test-fs-cp-sync-preserve-timestamps-dir.mjs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
// This tests that cpSync with a filter preserves directory timestamps
2-
// when preserveTimestamps is true.
1+
// This tests that cpSync preserves directory timestamps
2+
// when preserveTimestamps is true, both on the JS fallback path (with filter)
3+
// and the native fast path (without filter).
34
import '../common/index.mjs';
45
import { nextdir } from '../common/fs.js';
56
import assert from 'node:assert';
@@ -40,3 +41,21 @@ assert.strictEqual(srcDirStat.mtime.getTime(), destDirStat.mtime.getTime());
4041
const srcRootStat = statSync(src);
4142
const destRootStat = statSync(dest);
4243
assert.strictEqual(srcRootStat.mtime.getTime(), destRootStat.mtime.getTime());
44+
45+
// Copy with preserveTimestamps and NO filter (to exercise the native fast path).
46+
const destFast = nextdir();
47+
cpSync(src, destFast, {
48+
recursive: true,
49+
preserveTimestamps: true,
50+
});
51+
52+
// Verify file timestamps are preserved.
53+
const destFastFileStat = statSync(join(destFast, 'subdir', 'file.txt'));
54+
assert.strictEqual(srcFileStat.mtime.getTime(), destFastFileStat.mtime.getTime());
55+
56+
// Verify directory timestamps are preserved.
57+
const destFastDirStat = statSync(join(destFast, 'subdir'));
58+
assert.strictEqual(srcDirStat.mtime.getTime(), destFastDirStat.mtime.getTime());
59+
60+
const destFastRootStat = statSync(destFast);
61+
assert.strictEqual(srcRootStat.mtime.getTime(), destFastRootStat.mtime.getTime());

0 commit comments

Comments
 (0)