diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-05-20 01:01:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-19 19:01:06 -0400 |
commit | 62c34bc21e8864ec5701ad493c73224367627580 (patch) | |
tree | 217cf3cf379cd60a3c03c5b0314e7872be27aa75 /std/node/_fs/_fs_close_test.ts | |
parent | 0fb5f23466a84835cb1b4202d06ec53dc1592961 (diff) |
fix(std/node) improve fs.close compatibility (#5649)
Diffstat (limited to 'std/node/_fs/_fs_close_test.ts')
-rw-r--r-- | std/node/_fs/_fs_close_test.ts | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/std/node/_fs/_fs_close_test.ts b/std/node/_fs/_fs_close_test.ts index 8bcd662c9..1ea324cb4 100644 --- a/std/node/_fs/_fs_close_test.ts +++ b/std/node/_fs/_fs_close_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. const { test } = Deno; -import { fail, assert } from "../../testing/asserts.ts"; +import { fail, assert, assertThrows } from "../../testing/asserts.ts"; import { close, closeSync } from "./_fs_close.ts"; test({ @@ -12,7 +12,7 @@ test({ assert(Deno.resources()[file.rid]); await new Promise((resolve, reject) => { close(file.rid, (err) => { - if (err) reject(); + if (err !== null) reject(); else resolve(); }); }) @@ -29,6 +29,38 @@ test({ }); test({ + name: "ASYNC: Invalid fd", + async fn() { + await new Promise((resolve, reject) => { + close(-1, (err) => { + if (err !== null) return resolve(); + reject(); + }); + }); + }, +}); + +test({ + name: "close callback should be asynchronous", + async fn() { + const tempFile: string = Deno.makeTempFileSync(); + const file: Deno.File = Deno.openSync(tempFile); + + let foo: string; + const promise = new Promise((resolve) => { + close(file.rid, () => { + assert(foo === "bar"); + resolve(); + }); + foo = "bar"; + }); + + await promise; + Deno.removeSync(tempFile); + }, +}); + +test({ name: "SYNC: File is closed", fn() { const tempFile: string = Deno.makeTempFileSync(); @@ -40,3 +72,10 @@ test({ Deno.removeSync(tempFile); }, }); + +test({ + name: "SYNC: Invalid fd", + fn() { + assertThrows(() => closeSync(-1)); + }, +}); |