summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-06-01 02:05:57 +0800
committerGitHub <noreply@github.com>2021-05-31 20:05:57 +0200
commit330cd6b7ea46524783e5d1a8654153b459931cd7 (patch)
tree3abb2ba14722fabe2e021bb60af93b7bb14d64aa /cli/tests
parentea2c7ac5566e6973cdd68aaa8aa3dcb8c51a5865 (diff)
feat(cli): support URL overloads for `Deno.utime` and `Deno.utimeSync` (#10792)
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/unit/utime_test.ts39
1 files changed, 39 insertions, 0 deletions
diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts
index 4e56ff193..32b631406 100644
--- a/cli/tests/unit/utime_test.ts
+++ b/cli/tests/unit/utime_test.ts
@@ -3,6 +3,7 @@ import {
assertEquals,
assertThrows,
assertThrowsAsync,
+ pathToAbsoluteFileUrl,
unitTest,
} from "./test_util.ts";
@@ -71,6 +72,25 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
+ function utimeSyncUrlSuccess(): void {
+ const testDir = Deno.makeTempDirSync();
+ const filename = testDir + "/file.txt";
+ Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
+ mode: 0o666,
+ });
+
+ const atime = 1000;
+ const mtime = 50000;
+ Deno.utimeSync(pathToAbsoluteFileUrl(filename), atime, mtime);
+
+ const fileInfo = Deno.statSync(filename);
+ assertEquals(fileInfo.atime, new Date(atime * 1000));
+ assertEquals(fileInfo.mtime, new Date(mtime * 1000));
+ },
+);
+
+unitTest(
+ { perms: { read: true, write: true } },
function utimeSyncDirectorySuccess(): void {
const testDir = Deno.makeTempDirSync();
@@ -179,6 +199,25 @@ unitTest(
unitTest(
{ perms: { read: true, write: true } },
+ async function utimeUrlSuccess(): Promise<void> {
+ const testDir = Deno.makeTempDirSync();
+ const filename = testDir + "/file.txt";
+ Deno.writeFileSync(filename, new TextEncoder().encode("hello"), {
+ mode: 0o666,
+ });
+
+ const atime = 1000;
+ const mtime = 50000;
+ await Deno.utime(pathToAbsoluteFileUrl(filename), atime, mtime);
+
+ const fileInfo = Deno.statSync(filename);
+ assertEquals(fileInfo.atime, new Date(atime * 1000));
+ assertEquals(fileInfo.mtime, new Date(mtime * 1000));
+ },
+);
+
+unitTest(
+ { perms: { read: true, write: true } },
async function utimeDirectorySuccess(): Promise<void> {
const testDir = Deno.makeTempDirSync();