{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "182aef1d", "metadata": {}, "source": [ "# Integration Tests for Deno Jupyter\n", "This notebook contains a number of tests to ensure that Jupyter is working as expected. You should be able to select \"Kernel -> Restart Kernel and Run All\" in Jupyter's notebook UI to run the tests." ] }, { "attachments": {}, "cell_type": "markdown", "id": "d7705d88", "metadata": {}, "source": [ "## Passing Tests" ] }, { "attachments": {}, "cell_type": "markdown", "id": "669f972e", "metadata": { "heading_collapsed": true }, "source": [ "### Simple Tests" ] }, { "attachments": {}, "cell_type": "markdown", "id": "e7e8a512", "metadata": { "hidden": true }, "source": [ "#### This test should print \"hi\".\n", "If this doesn't work, everything else will probably fail :)" ] }, { "cell_type": "code", "execution_count": 1, "id": "a5d38758", "metadata": { "hidden": true }, "outputs": [ { "data": {}, "execution_count": 1, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "hi\n" ] } ], "source": [ "console.log(\"hi\")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "bc5ce8e3", "metadata": { "hidden": true }, "source": [ "#### Top-level await" ] }, { "cell_type": "code", "execution_count": 2, "id": "f7fa885a", "metadata": { "hidden": true }, "outputs": [ { "data": {}, "execution_count": 2, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "x is \u001b[33m42\u001b[39m\n" ] } ], "source": [ "let x = await Promise.resolve(42);\n", "console.log(\"x is\", x);" ] }, { "attachments": {}, "cell_type": "markdown", "id": "c21455ae", "metadata": { "hidden": true }, "source": [ "#### TypeScript transpiling\n", "Credit to [typescriptlang.org](https://www.typescriptlang.org/docs/handbook/interfaces.html) for this code" ] }, { "cell_type": "code", "execution_count": 3, "id": "08a17340", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "{ color: \u001b[32m\"red\"\u001b[39m, area: \u001b[33m10000\u001b[39m }" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "interface SquareConfig {\n", " color?: string;\n", " width?: number;\n", "}\n", " \n", "function createSquare(config: SquareConfig): { color: string; area: number } {\n", " return {\n", " color: config.color || \"red\",\n", " area: config.width ? config.width * config.width : 20,\n", " };\n", "}\n", " \n", "createSquare({ colour: \"red\", width: 100 });" ] }, { "attachments": {}, "cell_type": "markdown", "id": "eaa0ebc0", "metadata": { "heading_collapsed": true }, "source": [ "### Return Values" ] }, { "attachments": {}, "cell_type": "markdown", "id": "52876276", "metadata": { "hidden": true }, "source": [ "#### undefined should not return a value" ] }, { "cell_type": "code", "execution_count": 4, "id": "bbf2c09b", "metadata": { "hidden": true }, "outputs": [ { "data": {}, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "undefined" ] }, { "attachments": {}, "cell_type": "markdown", "id": "e175c803", "metadata": { "hidden": true }, "source": [ "#### null should return \"null\"" ] }, { "cell_type": "code", "execution_count": 5, "id": "d9801d80", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "\u001b[1mnull\u001b[22m" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "null" ] }, { "attachments": {}, "cell_type": "markdown", "id": "a2a716dc", "metadata": { "hidden": true }, "source": [ "#### boolean should return the boolean" ] }, { "cell_type": "code", "execution_count": 6, "id": "cfaac330", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "\u001b[33mtrue\u001b[39m" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "true" ] }, { "attachments": {}, "cell_type": "markdown", "id": "8d9f1aba", "metadata": { "hidden": true }, "source": [ "#### number should return the number" ] }, { "cell_type": "code", "execution_count": 7, "id": "ec3be2da", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "\u001b[33m42\u001b[39m" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "42" ] }, { "attachments": {}, "cell_type": "markdown", "id": "60965915", "metadata": { "hidden": true }, "source": [ "#### string should return the string" ] }, { "cell_type": "code", "execution_count": 8, "id": "997cf2d7", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "\u001b[32m\"this is a test of the emergency broadcast system\"\u001b[39m" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"this is a test of the emergency broadcast system\"" ] }, { "attachments": {}, "cell_type": "markdown", "id": "fe38dc27", "metadata": { "hidden": true }, "source": [ "#### bigint should return the bigint in literal format" ] }, { "cell_type": "code", "execution_count": 9, "id": "44b63807", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "\u001b[33m31337n\u001b[39m" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "31337n" ] }, { "attachments": {}, "cell_type": "markdown", "id": "843ccb6c", "metadata": { "hidden": true }, "source": [ "#### symbol should return a string describing the symbol" ] }, { "cell_type": "code", "execution_count": 10, "id": "e10c0d31", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "\u001b[32mSymbol(foo)\u001b[39m" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Symbol(\"foo\")" ] }, { "attachments": {}, "cell_type": "markdown", "id": "171b817f", "metadata": { "hidden": true }, "source": [ "#### object should describe the object inspection" ] }, { "cell_type": "code", "execution_count": 11, "id": "81c99233", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "{ foo: \u001b[32m\"bar\"\u001b[39m }" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "{foo: \"bar\"}" ] }, { "attachments": {}, "cell_type": "markdown", "id": "6caeb583", "metadata": { "hidden": true }, "source": [ "#### resolve returned promise" ] }, { "cell_type": "code", "execution_count": 12, "id": "43c1581b", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "Promise { \u001b[32m\"it worked!\"\u001b[39m }" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Promise.resolve(\"it worked!\")" ] }, { "cell_type": "code", "execution_count": 13, "id": "9a34b725", "metadata": { "hidden": true }, "outputs": [ { "data": { "text/plain": [ "Promise {\n", " \u001b[36m\u001b[39m Error: it failed!\n", " at :2:16\n", "}" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Promise.reject(new Error(\"it failed!\"));" ] }, { "cell_type": "code", "execution_count": 14, "id": "b5c7b819", "metadata": { "scrolled": true }, "outputs": [ { "ename": "Error", "evalue": "this is a test", "output_type": "error", "traceback": [ "Stack trace:", "Error: this is a test", " at foo (:3:9)", " at :4:3" ] } ], "source": [ "(function foo() {\n", " throw new Error(\"this is a test\")\n", "})()" ] }, { "cell_type": "code", "execution_count": 15, "id": "14844fc9-536e-4121-a9bd-fc2d3f7b6395", "metadata": {}, "outputs": [ { "ename": "Unknown error", "evalue": "a party", "output_type": "error", "traceback": [ "Stack trace:", "\"a party\"", " at " ] } ], "source": [ "throw \"a party\"" ] }, { "cell_type": "code", "execution_count": 16, "id": "72d01fdd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Promise {\n", " \u001b[36m\u001b[39m NotFound: No such file or directory (os error 2): readfile ''\n", " at async Object.readFile (ext:deno_fs/30_fs.js:716:18) {\n", " name: \u001b[32m\"NotFound\"\u001b[39m,\n", " code: \u001b[32m\"ENOENT\"\u001b[39m\n", " }\n", "}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Deno.readFile(1)" ] }, { "cell_type": "code", "execution_count": 17, "id": "28cf59d0-6908-4edc-bb10-c325beeee362", "metadata": {}, "outputs": [ { "data": {}, "execution_count": 17, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "Hello from Deno!\n" ] } ], "source": [ "console.log(\"Hello from Deno!\")" ] }, { "cell_type": "code", "execution_count": 18, "id": "8d5485c3-0da3-43fe-8ef5-a61e672f5e81", "metadata": {}, "outputs": [ { "data": {}, "execution_count": 18, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "\u001b[48;2;21;128;61m\u001b[37m Hello Deno \u001b[0m\n" ] } ], "source": [ "console.log(\"%c Hello Deno \", \"background-color: #15803d; color: white;\");" ] }, { "cell_type": "code", "execution_count": 19, "id": "1401d9d5-6994-4c7b-b55a-db3c16a1e2dc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\u001b[32m\"Cool 🫡\"\u001b[39m" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"Cool 🫡\"" ] }, { "cell_type": "code", "execution_count": 20, "id": "7afdaa0a-a2a0-4f52-8c7d-b6c5f237aa0d", "metadata": {}, "outputs": [ { "data": {}, "execution_count": 20, "metadata": {}, "output_type": "execute_result" }, { "name": "stdout", "output_type": "stream", "text": [ "┌───────┬────────┐\n", "│ (idx) │ Values │\n", "├───────┼────────┤\n", "│ 0 │ 1 │\n", "│ 1 │ 2 │\n", "│ 2 │ 3 │\n", "└───────┴────────┘\n" ] } ], "source": [ "console.table([1, 2, 3])" ] }, { "cell_type": "code", "execution_count": 21, "id": "8e93df23-06eb-414b-98d4-51fbebb53d1f", "metadata": {}, "outputs": [ { "data": { "text/html": [ "Complete ✅" ] }, "metadata": {}, "output_type": "display_data" }, { "data": {}, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "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": [] } ], "metadata": { "kernelspec": { "display_name": "Deno", "language": "typescript", "name": "deno" }, "language_info": { "file_extension": ".ts", "mimetype": "text/x.typescript", "name": "typescript", "nb_converter": "script", "pygments_lexer": "typescript", "version": "5.2.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 5 }