Skip to content

Adds tests for the updated JavaScript kernel #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions js/tests/defaultKernels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@ sandboxTest('test js kernel', async ({ sandbox }) => {
expect(output.logs.stdout).toEqual(['Hello World!\n'])
})

sandboxTest('test esm imports', async ({ sandbox }) => {
const output = await sandbox.runCode(
`
import { readFileSync } from 'fs'
console.log(typeof readFileSync)
`,
{
language: 'js',
}
)
expect(output.logs.stdout).toEqual(['function\n'])
})

sandboxTest(
'test top-level await and promise resolution',
async ({ sandbox }) => {
const output = await sandbox.runCode(
`
await Promise.resolve('Hello World!')
`,
{
language: 'js',
}
)
expect(output.text).toEqual('Hello World!')
}
)

sandboxTest('test ts kernel', async ({ sandbox }) => {
const output = await sandbox.runCode(
'const message: string = "Hello World!"; console.log(message)',
Expand Down
14 changes: 14 additions & 0 deletions python/tests/async/test_async_default_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ async def test_js_kernel(async_sandbox: AsyncSandbox):
)
assert execution.logs.stdout == ["Hello, World!\n"]

async def test_js_esm_imports(async_sandbox: AsyncSandbox):
execution = await async_sandbox.run_code("""
import { readFileSync } from 'fs'
console.log(typeof readFileSync)
""", language="js")
assert execution.logs.stdout == ["function\n"]


async def test_js_top_level_await(async_sandbox: AsyncSandbox):
execution = await async_sandbox.run_code("""
await Promise.resolve('Hello World!')
""", language="js")
assert execution.text == "Hello World!"


async def test_ts_kernel(async_sandbox: AsyncSandbox):
execution = await async_sandbox.run_code(
Expand Down
15 changes: 15 additions & 0 deletions python/tests/sync/test_default_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ def test_java_kernel(sandbox: Sandbox):
assert execution.logs.stdout[0] == "Hello, World!"


def test_js_esm_imports(sandbox: Sandbox):
execution = sandbox.run_code("""
import { readFileSync } from 'fs'
console.log(typeof readFileSync)
""", language="js")
assert execution.logs.stdout == ["function\n"]


def test_js_top_level_await(sandbox: Sandbox):
execution = sandbox.run_code("""
await Promise.resolve('Hello World!')
""", language="js")
assert execution.text == "Hello World!"


@pytest.mark.skip_debug()
def test_ts_kernel(sandbox: Sandbox):
execution = sandbox.run_code("const message: string = 'Hello, World!'; console.log(message)", language="ts")
Expand Down
Loading