test(fs): improve copy() testing (#5084)

This commit is contained in:
Yoshiya Hinosawa 2024-06-20 18:14:34 +09:00 committed by GitHub
parent 09d758aaaa
commit de40243520
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -122,6 +122,7 @@ testCopy(
testCopy(
"copy() copies with preserve timestamps",
async (tempDir: string) => {
{
const srcFile = path.join(testdataDir, "copy_file.txt");
const destFile = path.join(tempDir, "copy_file_copy.txt");
@ -142,6 +143,33 @@ testCopy(
assert(destStatInfo.mtime instanceof Date);
assertEquals(destStatInfo.atime, srcStatInfo.atime);
assertEquals(destStatInfo.mtime, srcStatInfo.mtime);
}
// copy dir with preserve timestamps
{
const srcDir = path.join(testdataDir, "copy_dir");
const destDir = path.join(tempDir, "copy_dir");
const srcFile = path.join(srcDir, "0.txt");
const destFile = path.join(destDir, "0.txt");
const srcNestFile = path.join(srcDir, "nest", "0.txt");
const destNestFile = path.join(destDir, "nest", "0.txt");
await copy(srcDir, destDir, { preserveTimestamps: true });
const srcDirInfo = await Deno.stat(srcFile);
const destDirInfo = await Deno.stat(destFile);
const srcFileInfo = await Deno.stat(srcFile);
const destFileInfo = await Deno.stat(destFile);
const srcNestFileInfo = await Deno.stat(srcNestFile);
const destNestFileInfo = await Deno.stat(destNestFile);
assertEquals(srcDirInfo.atime, destDirInfo.atime);
assertEquals(srcDirInfo.mtime, destDirInfo.mtime);
assertEquals(srcFileInfo.atime, destFileInfo.atime);
assertEquals(srcFileInfo.mtime, destFileInfo.mtime);
assertEquals(srcNestFileInfo.atime, destNestFileInfo.atime);
assertEquals(srcNestFileInfo.mtime, destNestFileInfo.mtime);
}
},
);
@ -284,6 +312,7 @@ testCopySync(
testCopySync(
"copySync() copies with preserve timestamps",
(tempDir: string) => {
{
const srcFile = path.join(testdataDir, "copy_file.txt");
const destFile = path.join(tempDir, "copy_file_copy.txt");
@ -304,6 +333,33 @@ testCopySync(
assert(destStatInfo.mtime instanceof Date);
assertEquals(destStatInfo.atime, srcStatInfo.atime);
assertEquals(destStatInfo.mtime, srcStatInfo.mtime);
}
// copy dir with preserve timestamps
{
const srcDir = path.join(testdataDir, "copy_dir");
const destDir = path.join(tempDir, "copy_dir");
const srcFile = path.join(srcDir, "0.txt");
const destFile = path.join(destDir, "0.txt");
const srcNestFile = path.join(srcDir, "nest", "0.txt");
const destNestFile = path.join(destDir, "nest", "0.txt");
copySync(srcDir, destDir, { preserveTimestamps: true });
const srcDirInfo = Deno.statSync(srcFile);
const destDirInfo = Deno.statSync(destFile);
const srcFileInfo = Deno.statSync(srcFile);
const destFileInfo = Deno.statSync(destFile);
const srcNestFileInfo = Deno.statSync(srcNestFile);
const destNestFileInfo = Deno.statSync(destNestFile);
assertEquals(srcDirInfo.atime, destDirInfo.atime);
assertEquals(srcDirInfo.mtime, destDirInfo.mtime);
assertEquals(srcFileInfo.atime, destFileInfo.atime);
assertEquals(srcFileInfo.mtime, destFileInfo.mtime);
assertEquals(srcNestFileInfo.atime, destNestFileInfo.atime);
assertEquals(srcNestFileInfo.mtime, destNestFileInfo.mtime);
}
},
);