From 8dbe77dd29a3791db58fda392dea45d8249b6bc9 Mon Sep 17 00:00:00 2001 From: Mohammad Sulaiman Date: Tue, 15 Oct 2024 01:04:18 +0300 Subject: fix(console/ext/repl): support using parseFloat() (#25900) Fixes #21428 Co-authored-by: tannal --- tests/unit/console_test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/console_test.ts b/tests/unit/console_test.ts index 878d17ae3..42cff7c70 100644 --- a/tests/unit/console_test.ts +++ b/tests/unit/console_test.ts @@ -1162,7 +1162,7 @@ Deno.test(function consoleTestWithIntegerFormatSpecifier() { assertEquals(stringify("%i"), "%i"); assertEquals(stringify("%i", 42.0), "42"); assertEquals(stringify("%i", 42), "42"); - assertEquals(stringify("%i", "42"), "NaN"); + assertEquals(stringify("%i", "42"), "42"); assertEquals(stringify("%i", 1.5), "1"); assertEquals(stringify("%i", -0.5), "0"); assertEquals(stringify("%i", ""), "NaN"); @@ -1172,7 +1172,7 @@ Deno.test(function consoleTestWithIntegerFormatSpecifier() { assertEquals(stringify("%d", 12345678901234567890123), "1"); assertEquals( stringify("%i", 12345678901234567890123n), - "12345678901234567890123n", + "1.2345678901234568e+22", ); }); @@ -1180,13 +1180,13 @@ Deno.test(function consoleTestWithFloatFormatSpecifier() { assertEquals(stringify("%f"), "%f"); assertEquals(stringify("%f", 42.0), "42"); assertEquals(stringify("%f", 42), "42"); - assertEquals(stringify("%f", "42"), "NaN"); + assertEquals(stringify("%f", "42"), "42"); assertEquals(stringify("%f", 1.5), "1.5"); assertEquals(stringify("%f", -0.5), "-0.5"); assertEquals(stringify("%f", Math.PI), "3.141592653589793"); assertEquals(stringify("%f", ""), "NaN"); assertEquals(stringify("%f", Symbol("foo")), "NaN"); - assertEquals(stringify("%f", 5n), "NaN"); + assertEquals(stringify("%f", 5n), "5"); assertEquals(stringify("%f %f", 42, 43), "42 43"); assertEquals(stringify("%f %f", 42), "42 %f"); }); -- cgit v1.2.3 From f26c8bcf3167069ccd8ac3beb9185d1bf480a83f Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 22 Oct 2024 01:41:08 -0700 Subject: refactor(runtime/ops): use concrete error types (#26409) --- tests/unit/signal_test.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/signal_test.ts b/tests/unit/signal_test.ts index 65b5ba78e..8923aa75b 100644 --- a/tests/unit/signal_test.ts +++ b/tests/unit/signal_test.ts @@ -5,101 +5,101 @@ Deno.test( { ignore: Deno.build.os !== "windows" }, function signalsNotImplemented() { const msg = - "Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK)."; + "Windows only supports ctrl-c (SIGINT) and ctrl-break (SIGBREAK), but got "; assertThrows( () => { Deno.addSignalListener("SIGALRM", () => {}); }, Error, - msg, + msg + "SIGALRM", ); assertThrows( () => { Deno.addSignalListener("SIGCHLD", () => {}); }, Error, - msg, + msg + "SIGCHLD", ); assertThrows( () => { Deno.addSignalListener("SIGHUP", () => {}); }, Error, - msg, + msg + "SIGHUP", ); assertThrows( () => { Deno.addSignalListener("SIGIO", () => {}); }, Error, - msg, + msg + "SIGIO", ); assertThrows( () => { Deno.addSignalListener("SIGPIPE", () => {}); }, Error, - msg, + msg + "SIGPIPE", ); assertThrows( () => { Deno.addSignalListener("SIGQUIT", () => {}); }, Error, - msg, + msg + "SIGQUIT", ); assertThrows( () => { Deno.addSignalListener("SIGTERM", () => {}); }, Error, - msg, + msg + "SIGTERM", ); assertThrows( () => { Deno.addSignalListener("SIGUSR1", () => {}); }, Error, - msg, + msg + "SIGUSR1", ); assertThrows( () => { Deno.addSignalListener("SIGUSR2", () => {}); }, Error, - msg, + msg + "SIGUSR2", ); assertThrows( () => { Deno.addSignalListener("SIGWINCH", () => {}); }, Error, - msg, + msg + "SIGWINCH", ); assertThrows( () => Deno.addSignalListener("SIGKILL", () => {}), Error, - msg, + msg + "SIGKILL", ); assertThrows( () => Deno.addSignalListener("SIGSTOP", () => {}), Error, - msg, + msg + "SIGSTOP", ); assertThrows( () => Deno.addSignalListener("SIGILL", () => {}), Error, - msg, + msg + "SIGILL", ); assertThrows( () => Deno.addSignalListener("SIGFPE", () => {}), Error, - msg, + msg + "SIGFPE", ); assertThrows( () => Deno.addSignalListener("SIGSEGV", () => {}), Error, - msg, + msg + "SIGSEGV", ); }, ); -- cgit v1.2.3 From 9696e0b3780ede9bb59ab3cf3bf4f2df179d0b32 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Tue, 22 Oct 2024 01:57:58 -0700 Subject: fix(ext/console): ignore casing for named colors in css parsing (#26466) --- tests/unit/console_test.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/unit') diff --git a/tests/unit/console_test.ts b/tests/unit/console_test.ts index 42cff7c70..06f5dd7e6 100644 --- a/tests/unit/console_test.ts +++ b/tests/unit/console_test.ts @@ -1227,6 +1227,7 @@ Deno.test(function consoleParseCssColor() { assertEquals(parseCssColor("inherit"), null); assertEquals(parseCssColor("black"), [0, 0, 0]); assertEquals(parseCssColor("darkmagenta"), [139, 0, 139]); + assertEquals(parseCssColor("darkMaGenta"), [139, 0, 139]); assertEquals(parseCssColor("slateblue"), [106, 90, 205]); assertEquals(parseCssColor("#ffaa00"), [255, 170, 0]); assertEquals(parseCssColor("#ffAA00"), [255, 170, 0]); -- cgit v1.2.3 From fb1d33a7111e45e9b414cfe922a5db5ee4daf3ea Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Tue, 5 Nov 2024 02:17:11 +0900 Subject: chore: update dlint to v0.68.0 for internal (#26711) --- tests/unit/globals_test.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/unit') diff --git a/tests/unit/globals_test.ts b/tests/unit/globals_test.ts index 45a045835..6de228e1c 100644 --- a/tests/unit/globals_test.ts +++ b/tests/unit/globals_test.ts @@ -1,4 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-node-globals import { assert, -- cgit v1.2.3 From b9262130fec34137e38c922015c6b671c0fa9396 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 7 Nov 2024 17:12:13 +0530 Subject: feat(ext/http): abort signal when request is cancelled (#26761) Closes https://github.com/denoland/deno/issues/21653 --- tests/unit/serve_test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index 439d71d55..9822a0ce2 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -4270,3 +4270,32 @@ Deno.test({ assertEquals(hostname, "0.0.0.0"); await server.shutdown(); }); + +Deno.test({ + name: "AbortSignal aborted when request is cancelled", +}, async () => { + const { promise, resolve } = Promise.withResolvers(); + + let cancelled = false; + + const server = Deno.serve({ + hostname: "0.0.0.0", + port: servePort, + onListen: () => resolve(), + }, async (request) => { + request.signal.addEventListener("abort", () => cancelled = true); + assert(!request.signal.aborted); + await new Promise((resolve) => setTimeout(resolve, 3000)); // abort during waiting + assert(request.signal.aborted); + return new Response("Ok"); + }); + + await promise; + await fetch(`http://localhost:${servePort}/`, { + signal: AbortSignal.timeout(1000), + }).catch(() => {}); + + await server.shutdown(); + + assert(cancelled); +}); -- cgit v1.2.3 From bf82c6697a9cb734998ceaa3f45768c3d8bd79b7 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Thu, 7 Nov 2024 15:02:33 -0800 Subject: chore: make commandWithCwdIsAsync test less flaky (#26770) --- tests/unit/command_test.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/command_test.ts b/tests/unit/command_test.ts index 51bbdd860..8345548f8 100644 --- a/tests/unit/command_test.ts +++ b/tests/unit/command_test.ts @@ -14,27 +14,31 @@ Deno.test( const enc = new TextEncoder(); const cwd = await Deno.makeTempDir({ prefix: "deno_command_test" }); + const exitCodeFileLock = "deno_was_here.lock"; const exitCodeFile = "deno_was_here"; const programFile = "poll_exit.ts"; const program = ` +const file = await Deno.open("${exitCodeFileLock}", { write: true, create: true }); async function tryExit() { + await file.lock(true); try { const code = parseInt(await Deno.readTextFile("${exitCodeFile}")); Deno.exit(code); } catch { // Retry if we got here before deno wrote the file. setTimeout(tryExit, 0.01); + } finally { + await file.unlock(); } } tryExit(); `; - Deno.writeFileSync(`${cwd}/${programFile}`, enc.encode(program)); const command = new Deno.Command(Deno.execPath(), { cwd, - args: ["run", "--allow-read", programFile], + args: ["run", "-RW", programFile], stdout: "inherit", stderr: "inherit", }); @@ -43,12 +47,18 @@ tryExit(); // Write the expected exit code *after* starting deno. // This is how we verify that `Child` is actually asynchronous. const code = 84; - Deno.writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`)); + await using file = await Deno.open(`${cwd}/${exitCodeFileLock}`, { + write: true, + create: true, + }); + await file.lock(true); + Deno.writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`)); + await file.unlock(); const status = await child.status; await Deno.remove(cwd, { recursive: true }); - assertEquals(status.success, false); assertEquals(status.code, code); + assertEquals(status.success, false); assertEquals(status.signal, null); }, ); -- cgit v1.2.3 From b482a50299ae4f636a186038460e54af65e2b627 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 8 Nov 2024 18:46:11 +0530 Subject: feat(ext/http): abort event when request is cancelled (#26781) ```js Deno.serve(async (req) => { const { promise, resolve } = Promise.withResolvers(); req.signal.addEventListener("abort", () => { resolve(); }); await promise; return new Response("Ok"); }); ``` --- tests/unit/serve_test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts index 9822a0ce2..7d8c6ca06 100644 --- a/tests/unit/serve_test.ts +++ b/tests/unit/serve_test.ts @@ -4299,3 +4299,31 @@ Deno.test({ assert(cancelled); }); + +Deno.test({ + name: "AbortSignal event aborted when request is cancelled", +}, async () => { + const { promise, resolve } = Promise.withResolvers(); + + const server = Deno.serve({ + hostname: "0.0.0.0", + port: servePort, + onListen: () => resolve(), + }, async (request) => { + const { promise: promiseAbort, resolve: resolveAbort } = Promise + .withResolvers(); + request.signal.addEventListener("abort", () => resolveAbort()); + assert(!request.signal.aborted); + + await promiseAbort; + + return new Response("Ok"); + }); + + await promise; + await fetch(`http://localhost:${servePort}/`, { + signal: AbortSignal.timeout(100), + }).catch(() => {}); + + await server.shutdown(); +}); -- cgit v1.2.3 From 3b99f6833cd3354da20785fdcf01e7409e610175 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Tue, 12 Nov 2024 17:10:07 +0530 Subject: fix(ext/websocket): initialize `error` attribute of WebSocket ErrorEvent (#26796) Fixes https://github.com/denoland/deno/issues/26216 Not required by the spec but Discord.js depends on it, see https://github.com/denoland/deno/issues/26216#issuecomment-2466060306 --- tests/unit/websocket_test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/websocket_test.ts b/tests/unit/websocket_test.ts index 7db876b17..3aafe8da2 100644 --- a/tests/unit/websocket_test.ts +++ b/tests/unit/websocket_test.ts @@ -453,7 +453,8 @@ Deno.test("invalid server", async () => { const { promise, resolve } = Promise.withResolvers(); const ws = new WebSocket("ws://localhost:2121"); let err = false; - ws.onerror = () => { + ws.onerror = (e) => { + assert("error" in e); err = true; }; ws.onclose = () => { -- cgit v1.2.3 From 7becd83a3828b35331d0fcb82c64146e520f154b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Czerniawski?= <33061335+lczerniawski@users.noreply.github.com> Date: Wed, 13 Nov 2024 05:35:04 +0100 Subject: feat(ext/fs): add ctime to Deno.stats and use it in node compat layer (#24801) This PR fixes #24453, by introducing a ctime (using ctime for UNIX and ChangeTime for Windows) to Deno.stats. Co-authored-by: Yoshiya Hinosawa --- tests/unit/stat_test.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/stat_test.ts b/tests/unit/stat_test.ts index 59831a069..0609035b4 100644 --- a/tests/unit/stat_test.ts +++ b/tests/unit/stat_test.ts @@ -31,6 +31,13 @@ Deno.test( assert( tempInfo.birthtime === null || now - tempInfo.birthtime.valueOf() < 1000, ); + assert(tempInfo.ctime !== null && now - tempInfo.ctime.valueOf() < 1000); + const mode = tempInfo.mode! & 0o777; + if (Deno.build.os === "windows") { + assertEquals(mode, 0o666); + } else { + assertEquals(mode, 0o600); + } const readmeInfoByUrl = Deno.statSync(pathToAbsoluteFileUrl("README.md")); assert(readmeInfoByUrl.isFile); @@ -65,6 +72,10 @@ Deno.test( tempInfoByUrl.birthtime === null || now - tempInfoByUrl.birthtime.valueOf() < 1000, ); + assert( + tempInfoByUrl.ctime !== null && + now - tempInfoByUrl.ctime.valueOf() < 1000, + ); Deno.removeSync(tempFile, { recursive: true }); Deno.removeSync(tempFileForUrl, { recursive: true }); @@ -171,6 +182,7 @@ Deno.test( assert( tempInfo.birthtime === null || now - tempInfo.birthtime.valueOf() < 1000, ); + assert(tempInfo.ctime !== null && now - tempInfo.ctime.valueOf() < 1000); const tempFileForUrl = await Deno.makeTempFile(); const tempInfoByUrl = await Deno.stat( @@ -191,7 +203,10 @@ Deno.test( tempInfoByUrl.birthtime === null || now - tempInfoByUrl.birthtime.valueOf() < 1000, ); - + assert( + tempInfoByUrl.ctime !== null && + now - tempInfoByUrl.ctime.valueOf() < 1000, + ); Deno.removeSync(tempFile, { recursive: true }); Deno.removeSync(tempFileForUrl, { recursive: true }); }, @@ -271,7 +286,6 @@ Deno.test( const s = Deno.statSync(filename); assert(s.dev !== 0); assert(s.ino === null); - assert(s.mode === null); assert(s.nlink === null); assert(s.uid === null); assert(s.gid === null); -- cgit v1.2.3 From b8cf2599242a9d85d03b57d3649ccdf8bce1530e Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Fri, 15 Nov 2024 15:54:28 +0100 Subject: feat(fetch): accept async iterables for body (#26882) Reland of #24623, but with a fix for `String` objects. Co-authored-by: crowlkats --- tests/unit/fetch_test.ts | 27 +++++++++++++++++++++++++++ tests/unit/streams_test.ts | 15 ++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/fetch_test.ts b/tests/unit/fetch_test.ts index 3ae96746a..6d3fd8cc1 100644 --- a/tests/unit/fetch_test.ts +++ b/tests/unit/fetch_test.ts @@ -2119,3 +2119,30 @@ Deno.test( await server; }, ); + +Deno.test("fetch async iterable", async () => { + const iterable = (async function* () { + yield new Uint8Array([1, 2, 3, 4, 5]); + yield new Uint8Array([6, 7, 8, 9, 10]); + })(); + const res = new Response(iterable); + const actual = await res.bytes(); + const expected = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + assertEquals(actual, expected); +}); + +Deno.test("fetch iterable", async () => { + const iterable = (function* () { + yield new Uint8Array([1, 2, 3, 4, 5]); + yield new Uint8Array([6, 7, 8, 9, 10]); + })(); + const res = new Response(iterable); + const actual = await res.bytes(); + const expected = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + assertEquals(actual, expected); +}); + +Deno.test("fetch string object", async () => { + const res = new Response(Object("hello")); + assertEquals(await res.text(), "hello"); +}); diff --git a/tests/unit/streams_test.ts b/tests/unit/streams_test.ts index b866fa7d5..73f9a6095 100644 --- a/tests/unit/streams_test.ts +++ b/tests/unit/streams_test.ts @@ -1,5 +1,10 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -import { assertEquals, assertRejects, fail } from "./test_util.ts"; +import { + assertEquals, + assertRejects, + assertThrows, + fail, +} from "./test_util.ts"; const { core, @@ -533,3 +538,11 @@ Deno.test(async function decompressionStreamInvalidGzipStillReported() { "corrupt gzip stream does not have a matching checksum", ); }); + +Deno.test(function readableStreamFromWithStringThrows() { + assertThrows( + () => ReadableStream.from("string"), + TypeError, + "Failed to execute 'ReadableStream.from': Argument 1 can not be converted to async iterable.", + ); +}); -- cgit v1.2.3 From a1bcdf17a53fb98c476aae9e205817c4a80a363d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 16 Nov 2024 15:13:50 +0000 Subject: feat(jupyter): Add `Deno.jupyter.image` API (#26284) This commit adds `Deno.jupyter.image` API to display PNG and JPG images: ``` const data = Deno.readFileSync("./my-image.jpg"); Deno.jupyter.image(data); Deno.jupyter.image("./my-image.jpg"); ``` --- tests/unit/ops_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/ops_test.ts b/tests/unit/ops_test.ts index 4ba7c5ce3..6de55f8b6 100644 --- a/tests/unit/ops_test.ts +++ b/tests/unit/ops_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -const EXPECTED_OP_COUNT = 11; +const EXPECTED_OP_COUNT = 12; Deno.test(function checkExposedOps() { // @ts-ignore TS doesn't allow to index with symbol -- cgit v1.2.3