summaryrefslogtreecommitdiff
path: root/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts
diff options
context:
space:
mode:
authorAsher Gomez <ashersaupingomez@gmail.com>2024-01-25 01:59:55 +1100
committerGitHub <noreply@github.com>2024-01-24 15:59:55 +0100
commit62786cfebb5c9fe36d0930582951f442bdfe9441 (patch)
treea1bede5492a5b1bf4a202ee8994df027f098e788 /cli/tests/unit_node/_fs/_fs_ftruncate_test.ts
parent4af121687cb4c26f4a2f3e4ad266490d8faa3d2d (diff)
feat: deprecate `Deno.close()` (#22066)
For removal in Deno v2. --------- Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com>
Diffstat (limited to 'cli/tests/unit_node/_fs/_fs_ftruncate_test.ts')
-rw-r--r--cli/tests/unit_node/_fs/_fs_ftruncate_test.ts52
1 files changed, 24 insertions, 28 deletions
diff --git a/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts b/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts
index 4c2c34789..ef59f0577 100644
--- a/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts
+++ b/cli/tests/unit_node/_fs/_fs_ftruncate_test.ts
@@ -23,23 +23,23 @@ Deno.test({
Deno.test({
name: "ASYNC: truncate entire file contents",
async fn() {
- const file: string = Deno.makeTempFileSync();
- await Deno.writeTextFile(file, "hello world");
- const { rid } = await Deno.open(file, {
+ const filePath = Deno.makeTempFileSync();
+ await Deno.writeTextFile(filePath, "hello world");
+ using file = await Deno.open(filePath, {
read: true,
write: true,
create: true,
});
await new Promise<void>((resolve, reject) => {
- ftruncate(rid, (err: Error | null) => {
+ ftruncate(file.rid, (err: Error | null) => {
if (err !== null) reject();
else resolve();
});
})
.then(
() => {
- const fileInfo: Deno.FileInfo = Deno.lstatSync(file);
+ const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath);
assertEquals(fileInfo.size, 0);
},
() => {
@@ -47,8 +47,7 @@ Deno.test({
},
)
.finally(() => {
- Deno.removeSync(file);
- Deno.close(rid);
+ Deno.removeSync(filePath);
});
},
});
@@ -56,23 +55,23 @@ Deno.test({
Deno.test({
name: "ASYNC: truncate file to a size of precisely len bytes",
async fn() {
- const file: string = Deno.makeTempFileSync();
- await Deno.writeTextFile(file, "hello world");
- const { rid } = await Deno.open(file, {
+ const filePath = Deno.makeTempFileSync();
+ await Deno.writeTextFile(filePath, "hello world");
+ using file = await Deno.open(filePath, {
read: true,
write: true,
create: true,
});
await new Promise<void>((resolve, reject) => {
- ftruncate(rid, 3, (err: Error | null) => {
+ ftruncate(file.rid, 3, (err: Error | null) => {
if (err !== null) reject();
else resolve();
});
})
.then(
() => {
- const fileInfo: Deno.FileInfo = Deno.lstatSync(file);
+ const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath);
assertEquals(fileInfo.size, 3);
},
() => {
@@ -80,8 +79,7 @@ Deno.test({
},
)
.finally(() => {
- Deno.removeSync(file);
- Deno.close(rid);
+ Deno.removeSync(filePath);
});
},
});
@@ -89,21 +87,20 @@ Deno.test({
Deno.test({
name: "SYNC: truncate entire file contents",
fn() {
- const file: string = Deno.makeTempFileSync();
- Deno.writeFileSync(file, new TextEncoder().encode("hello world"));
- const { rid } = Deno.openSync(file, {
+ const filePath = Deno.makeTempFileSync();
+ Deno.writeFileSync(filePath, new TextEncoder().encode("hello world"));
+ using file = Deno.openSync(filePath, {
read: true,
write: true,
create: true,
});
try {
- ftruncateSync(rid);
- const fileInfo: Deno.FileInfo = Deno.lstatSync(file);
+ ftruncateSync(file.rid);
+ const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath);
assertEquals(fileInfo.size, 0);
} finally {
- Deno.removeSync(file);
- Deno.close(rid);
+ Deno.removeSync(filePath);
}
},
});
@@ -111,21 +108,20 @@ Deno.test({
Deno.test({
name: "SYNC: truncate file to a size of precisely len bytes",
fn() {
- const file: string = Deno.makeTempFileSync();
- Deno.writeFileSync(file, new TextEncoder().encode("hello world"));
- const { rid } = Deno.openSync(file, {
+ const filePath = Deno.makeTempFileSync();
+ Deno.writeFileSync(filePath, new TextEncoder().encode("hello world"));
+ using file = Deno.openSync(filePath, {
read: true,
write: true,
create: true,
});
try {
- ftruncateSync(rid, 3);
- const fileInfo: Deno.FileInfo = Deno.lstatSync(file);
+ ftruncateSync(file.rid, 3);
+ const fileInfo: Deno.FileInfo = Deno.lstatSync(filePath);
assertEquals(fileInfo.size, 3);
} finally {
- Deno.removeSync(file);
- Deno.close(rid);
+ Deno.removeSync(filePath);
}
},
});