summaryrefslogtreecommitdiff
path: root/tests/unit_node/fs_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit_node/fs_test.ts')
-rw-r--r--tests/unit_node/fs_test.ts35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/unit_node/fs_test.ts b/tests/unit_node/fs_test.ts
index caa266ef2..e62a246fa 100644
--- a/tests/unit_node/fs_test.ts
+++ b/tests/unit_node/fs_test.ts
@@ -5,6 +5,7 @@ import { join } from "node:path";
import { tmpdir } from "node:os";
import {
constants,
+ createWriteStream,
existsSync,
mkdtempSync,
promises,
@@ -14,6 +15,7 @@ import {
writeFileSync,
} from "node:fs";
import { constants as fsPromiseConstants, cp } from "node:fs/promises";
+import process from "node:process";
import { pathToAbsoluteFileUrl } from "../unit/test_util.ts";
Deno.test(
@@ -121,3 +123,36 @@ Deno.test(
assert(dataRead === "Hello");
},
);
+
+// TODO(kt3k): Delete this test case, and instead enable the compat case
+// `test/parallel/test-fs-writestream-open-write.js`, when we update
+// `tests/node_compat/runner/suite`.
+Deno.test("[node/fs createWriteStream", async () => {
+ const { promise, resolve, reject } = Promise.withResolvers<void>();
+ const tempDir = await Deno.makeTempDir();
+ const file = join(tempDir, "file.txt");
+ try {
+ const w = createWriteStream(file);
+
+ w.on("open", () => {
+ w.write("hello, ");
+
+ process.nextTick(() => {
+ w.write("world");
+ w.end();
+ });
+ });
+
+ w.on("close", async () => {
+ try {
+ assertEquals(await Deno.readTextFile(file), "hello, world");
+ resolve();
+ } catch (e) {
+ reject(e);
+ }
+ });
+ await promise;
+ } finally {
+ await Deno.remove(tempDir, { recursive: true });
+ }
+});