From 9f9c3d9048108200a888c508328d2a19cbbd6164 Mon Sep 17 00:00:00 2001 From: sigmaSd Date: Sun, 22 Oct 2023 09:02:55 +0100 Subject: fix(polyfill): correctly handle flag when its equal 0 (#20953) Fixes https://github.com/denoland/deno/issues/20910 --- cli/tests/unit_node/_fs/_fs_open_test.ts | 10 ++++++++++ cli/tests/unit_node/_fs/_fs_read_test.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+) (limited to 'cli/tests/unit_node/_fs') diff --git a/cli/tests/unit_node/_fs/_fs_open_test.ts b/cli/tests/unit_node/_fs/_fs_open_test.ts index b64e6c4c5..d9f5e5796 100644 --- a/cli/tests/unit_node/_fs/_fs_open_test.ts +++ b/cli/tests/unit_node/_fs/_fs_open_test.ts @@ -397,4 +397,14 @@ Deno.test("[std/node/fs] open callback isn't called twice if error is thrown", a await Deno.remove(tempFile); }, }); + + Deno.test({ + name: "SYNC: open file with flag set to 0 (readonly)", + fn() { + const file = Deno.makeTempFileSync(); + const fd = openSync(file, 0); + assert(Deno.resources()[fd]); + closeSync(fd); + }, + }); }); diff --git a/cli/tests/unit_node/_fs/_fs_read_test.ts b/cli/tests/unit_node/_fs/_fs_read_test.ts index 66906ccbc..34b029d9f 100644 --- a/cli/tests/unit_node/_fs/_fs_read_test.ts +++ b/cli/tests/unit_node/_fs/_fs_read_test.ts @@ -306,3 +306,18 @@ Deno.test({ await Deno.remove(file); }, }); + +Deno.test({ + name: "SYNC: read with no offsetOropts argument", + fn() { + const moduleDir = path.dirname(path.fromFileUrl(import.meta.url)); + const testData = path.resolve(moduleDir, "testdata", "hello.txt"); + const buffer = Buffer.alloc(1024); + const fd = openSync(testData, "r"); + const _bytesRead = readSync( + fd, + buffer, + ); + closeSync(fd); + }, +}); -- cgit v1.2.3