Skip to content

Commit 85cac91

Browse files
authored
added tests for new js kernel (#113)
1 parent 585543f commit 85cac91

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

js/tests/defaultKernels.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ sandboxTest('test js kernel', async ({ sandbox }) => {
99
expect(output.logs.stdout).toEqual(['Hello World!\n'])
1010
})
1111

12+
sandboxTest('test esm imports', async ({ sandbox }) => {
13+
const output = await sandbox.runCode(
14+
`
15+
import { readFileSync } from 'fs'
16+
console.log(typeof readFileSync)
17+
`,
18+
{
19+
language: 'js',
20+
}
21+
)
22+
expect(output.logs.stdout).toEqual(['function\n'])
23+
})
24+
25+
sandboxTest(
26+
'test top-level await and promise resolution',
27+
async ({ sandbox }) => {
28+
const output = await sandbox.runCode(
29+
`
30+
await Promise.resolve('Hello World!')
31+
`,
32+
{
33+
language: 'js',
34+
}
35+
)
36+
expect(output.text).toEqual('Hello World!')
37+
}
38+
)
39+
1240
sandboxTest('test ts kernel', async ({ sandbox }) => {
1341
const output = await sandbox.runCode(
1442
'const message: string = "Hello World!"; console.log(message)',

python/tests/async/test_async_default_kernels.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ async def test_js_kernel(async_sandbox: AsyncSandbox):
77
)
88
assert execution.logs.stdout == ["Hello, World!\n"]
99

10+
async def test_js_esm_imports(async_sandbox: AsyncSandbox):
11+
execution = await async_sandbox.run_code("""
12+
import { readFileSync } from 'fs'
13+
console.log(typeof readFileSync)
14+
""", language="js")
15+
assert execution.logs.stdout == ["function\n"]
16+
17+
18+
async def test_js_top_level_await(async_sandbox: AsyncSandbox):
19+
execution = await async_sandbox.run_code("""
20+
await Promise.resolve('Hello World!')
21+
""", language="js")
22+
assert execution.text == "Hello World!"
23+
1024

1125
async def test_ts_kernel(async_sandbox: AsyncSandbox):
1226
execution = await async_sandbox.run_code(

python/tests/sync/test_default_kernels.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ def test_java_kernel(sandbox: Sandbox):
2020
assert execution.logs.stdout[0] == "Hello, World!"
2121

2222

23+
def test_js_esm_imports(sandbox: Sandbox):
24+
execution = sandbox.run_code("""
25+
import { readFileSync } from 'fs'
26+
console.log(typeof readFileSync)
27+
""", language="js")
28+
assert execution.logs.stdout == ["function\n"]
29+
30+
31+
def test_js_top_level_await(sandbox: Sandbox):
32+
execution = sandbox.run_code("""
33+
await Promise.resolve('Hello World!')
34+
""", language="js")
35+
assert execution.text == "Hello World!"
36+
37+
2338
@pytest.mark.skip_debug()
2439
def test_ts_kernel(sandbox: Sandbox):
2540
execution = sandbox.run_code("const message: string = 'Hello, World!'; console.log(message)", language="ts")

0 commit comments

Comments
 (0)