summaryrefslogtreecommitdiff
path: root/cli/tests/unit
diff options
context:
space:
mode:
authorAsher Gomez <ashersaupingomez@gmail.com>2024-01-24 10:31:52 +1100
committerGitHub <noreply@github.com>2024-01-24 00:31:52 +0100
commit2f47ec6c3a583c8323a06c386feeaee4fbf75edc (patch)
tree92511f544d3b8466fb84fa40f3e68163a4e97324 /cli/tests/unit
parent947ce41e99637dae4cf46126b8bb2d4107fb9913 (diff)
feat: `Deno.FsFile.dataSync()` and `Deno.FsFile.dataSyncSync()` (#22019)
This change: 1. Implements `Deno.FsFile.dataSync()` and `Deno.FsFile.dataSyncSync()`. 2. Deprecates `Deno.fdatasync()` and `Deno.fdatasyncSync()` for removal in Deno v2, in favour of the above corresponding methods. 3. Replaces use of `Deno.fdatasync()` and `Deno.fdatasyncSync()` with the above instance methods. Related #21995
Diffstat (limited to 'cli/tests/unit')
-rw-r--r--cli/tests/unit/files_test.ts36
-rw-r--r--cli/tests/unit/utime_test.ts4
2 files changed, 38 insertions, 2 deletions
diff --git a/cli/tests/unit/files_test.ts b/cli/tests/unit/files_test.ts
index 977d6463d..d02471b07 100644
--- a/cli/tests/unit/files_test.ts
+++ b/cli/tests/unit/files_test.ts
@@ -824,3 +824,39 @@ Deno.test(
// calling [Symbol.dispose] after manual close is a no-op
},
);
+
+Deno.test(
+ { permissions: { read: true, write: true } },
+ function fsFileDatasyncSyncSuccess() {
+ const filename = Deno.makeTempDirSync() + "/test_fdatasyncSync.txt";
+ const file = Deno.openSync(filename, {
+ read: true,
+ write: true,
+ create: true,
+ });
+ const data = new Uint8Array(64);
+ file.writeSync(data);
+ file.dataSyncSync();
+ assertEquals(Deno.readFileSync(filename), data);
+ file.close();
+ Deno.removeSync(filename);
+ },
+);
+
+Deno.test(
+ { permissions: { read: true, write: true } },
+ async function fsFileDatasyncSuccess() {
+ const filename = (await Deno.makeTempDir()) + "/test_fdatasync.txt";
+ const file = await Deno.open(filename, {
+ read: true,
+ write: true,
+ create: true,
+ });
+ const data = new Uint8Array(64);
+ await file.write(data);
+ await file.dataSync();
+ assertEquals(await Deno.readFile(filename), data);
+ file.close();
+ await Deno.remove(filename);
+ },
+);
diff --git a/cli/tests/unit/utime_test.ts b/cli/tests/unit/utime_test.ts
index 02566bad6..48f4f405a 100644
--- a/cli/tests/unit/utime_test.ts
+++ b/cli/tests/unit/utime_test.ts
@@ -19,7 +19,7 @@ Deno.test(
const atime = 1000;
const mtime = 50000;
await Deno.futime(file.rid, atime, mtime);
- await Deno.fdatasync(file.rid);
+ await file.dataSync();
const fileInfo = Deno.statSync(filename);
assertEquals(fileInfo.atime, new Date(atime * 1000));
@@ -40,7 +40,7 @@ Deno.test(
const atime = 1000;
const mtime = 50000;
Deno.futimeSync(file.rid, atime, mtime);
- Deno.fdatasyncSync(file.rid);
+ file.dataSyncSync();
const fileInfo = Deno.statSync(filename);
assertEquals(fileInfo.atime, new Date(atime * 1000));