From 46a4bd5178f5aed22041422c431b5ab6f697865d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 27 Sep 2023 02:21:06 +0200 Subject: feat(unstable): add `Deno.jupyter.broadcast` API (#20656) Closes https://github.com/denoland/deno/issues/20591 --------- Co-authored-by: Kyle Kelley --- cli/tests/integration/js_unit_tests.rs | 1 + cli/tests/testdata/jupyter/integration_test.ipynb | 51 ++++++++++++++++++++++- cli/tests/unit/jupyter_test.ts | 9 ++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 cli/tests/unit/jupyter_test.ts (limited to 'cli/tests') diff --git a/cli/tests/integration/js_unit_tests.rs b/cli/tests/integration/js_unit_tests.rs index 4bb2ef73b..a13db02d7 100644 --- a/cli/tests/integration/js_unit_tests.rs +++ b/cli/tests/integration/js_unit_tests.rs @@ -45,6 +45,7 @@ util::unit_test_factory!( internals_test, intl_test, io_test, + jupyter_test, kv_test, kv_queue_test_no_db_close, kv_queue_undelivered_test, diff --git a/cli/tests/testdata/jupyter/integration_test.ipynb b/cli/tests/testdata/jupyter/integration_test.ipynb index e9347750d..1d48c8fc9 100644 --- a/cli/tests/testdata/jupyter/integration_test.ipynb +++ b/cli/tests/testdata/jupyter/integration_test.ipynb @@ -665,9 +665,58 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "8e93df23-06eb-414b-98d4-51fbebb53d1f", "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "Cannot read properties of undefined (reading 'broadcast')", + "output_type": "error", + "traceback": [ + "Stack trace:", + "TypeError: Cannot read properties of undefined (reading 'broadcast')", + " at :2:20" + ] + } + ], + "source": [ + "await Deno.jupyter.broadcast(\"display_data\", {\n", + " data: { \"text/html\": \"Processing.\" },\n", + " metadata: {},\n", + " transient: { display_id: \"progress\" }\n", + "});\n", + "\n", + "await new Promise((resolve) => setTimeout(resolve, 500));\n", + "\n", + "await Deno.jupyter.broadcast(\"update_display_data\", {\n", + " data: { \"text/html\": \"Processing..\" },\n", + " metadata: {},\n", + " transient: { display_id: \"progress\" }\n", + "});\n", + "\n", + "await new Promise((resolve) => setTimeout(resolve, 500));\n", + "\n", + "await Deno.jupyter.broadcast(\"update_display_data\", {\n", + " data: { \"text/html\": \"Processing...\" },\n", + " metadata: {},\n", + " transient: { display_id: \"progress\" }\n", + "});\n", + "\n", + "await new Promise((resolve) => setTimeout(resolve, 500));\n", + "\n", + "await Deno.jupyter.broadcast(\"update_display_data\", {\n", + " data: { \"text/html\": \"Complete ✅\" },\n", + " metadata: {},\n", + " transient: { display_id: \"progress\" }\n", + "});" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0181f28e", + "metadata": {}, "outputs": [], "source": [] } diff --git a/cli/tests/unit/jupyter_test.ts b/cli/tests/unit/jupyter_test.ts new file mode 100644 index 000000000..40eaf4623 --- /dev/null +++ b/cli/tests/unit/jupyter_test.ts @@ -0,0 +1,9 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. +import { assertThrows } from "./test_util.ts"; + +Deno.test("Deno.jupyter is not available", () => { + assertThrows( + () => Deno.jupyter, + "Deno.jupyter is only available in `deno jupyter` subcommand.", + ); +}); -- cgit v1.2.3