mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
test(fs): improve copy()
testing (#5084)
This commit is contained in:
parent
09d758aaaa
commit
de40243520
@ -122,6 +122,7 @@ testCopy(
|
|||||||
testCopy(
|
testCopy(
|
||||||
"copy() copies with preserve timestamps",
|
"copy() copies with preserve timestamps",
|
||||||
async (tempDir: string) => {
|
async (tempDir: string) => {
|
||||||
|
{
|
||||||
const srcFile = path.join(testdataDir, "copy_file.txt");
|
const srcFile = path.join(testdataDir, "copy_file.txt");
|
||||||
const destFile = path.join(tempDir, "copy_file_copy.txt");
|
const destFile = path.join(tempDir, "copy_file_copy.txt");
|
||||||
|
|
||||||
@ -142,6 +143,33 @@ testCopy(
|
|||||||
assert(destStatInfo.mtime instanceof Date);
|
assert(destStatInfo.mtime instanceof Date);
|
||||||
assertEquals(destStatInfo.atime, srcStatInfo.atime);
|
assertEquals(destStatInfo.atime, srcStatInfo.atime);
|
||||||
assertEquals(destStatInfo.mtime, srcStatInfo.mtime);
|
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(
|
testCopySync(
|
||||||
"copySync() copies with preserve timestamps",
|
"copySync() copies with preserve timestamps",
|
||||||
(tempDir: string) => {
|
(tempDir: string) => {
|
||||||
|
{
|
||||||
const srcFile = path.join(testdataDir, "copy_file.txt");
|
const srcFile = path.join(testdataDir, "copy_file.txt");
|
||||||
const destFile = path.join(tempDir, "copy_file_copy.txt");
|
const destFile = path.join(tempDir, "copy_file_copy.txt");
|
||||||
|
|
||||||
@ -304,6 +333,33 @@ testCopySync(
|
|||||||
assert(destStatInfo.mtime instanceof Date);
|
assert(destStatInfo.mtime instanceof Date);
|
||||||
assertEquals(destStatInfo.atime, srcStatInfo.atime);
|
assertEquals(destStatInfo.atime, srcStatInfo.atime);
|
||||||
assertEquals(destStatInfo.mtime, srcStatInfo.mtime);
|
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);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user