Skip to content

Commit

Permalink
Add display test
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Oct 31, 2024
1 parent 646ea1e commit 7c42c43
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
21 changes: 20 additions & 1 deletion js/tests/languages/deno.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sandboxTest('js context', async ({ sandbox }) => {
})

sandboxTest('js cwd', async ({ sandbox }) => {
const result = await sandbox.runCode('process.cwd()', {language: "deno})
const result = await sandbox.runCode('process.cwd()', {language: "deno"})
expect(result.results[0].text).toEqual('/home/user')

const ctx = await sandbox.createCodeContext( {cwd: '/home', language: "deno"})
Expand All @@ -59,3 +59,22 @@ subtract(1, 2)

expect(result.results[0].text).toEqual('-1')
})

sandboxTest('test display', async ({ sandbox }) => {
const result = await sandbox.runCode(`
{
[Symbol.for("Jupyter.display")]() {
return {
// Plain text content
"text/plain": "Hello world!",
// HTML output
"text/html": "<h1>Hello world!</h1>",
}
}
}
`, {language: "deno"})

expect(result.results[0].html).toBe('<h1>Hello world!</h1>')
expect(result.results[0].text).toBe('Hello world!')
})
19 changes: 19 additions & 0 deletions python/tests/languages/test_deno.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,22 @@ async def test_typescript(async_sandbox: AsyncSandbox):
language="deno",
)
assert execution.results[0].text == "-1"


async def test_display(async_sandbox: AsyncSandbox):
code = """
{
[Symbol.for("Jupyter.display")]() {
return {
// Plain text content
"text/plain": "Hello world!",
// HTML output
"text/html": "<h1>Hello world!</h1>",
}
}
}
"""
execution = await async_sandbox.run_code(code, language="deno")
assert execution.results[0].text == "Hello world!"
assert execution.results[0].html == "<h1>Hello world!</h1>"

0 comments on commit 7c42c43

Please sign in to comment.