Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Add tests for stdout/err

Jakub Novakafbececfd0dd
diff --git a/packages/js-sdk/test/runCode.test.mjs b/packages/js-sdk/test/runCode.test.mjs
index 2333c4447..fb606f0c9 100644
--- a/packages/js-sdk/test/runCode.test.mjs
+++ b/packages/js-sdk/test/runCode.test.mjs
@@ -1,18 +1,19 @@
-import { runCode } from '../src'
-import { expect, test } from 'vitest'
+import {runCode} from '../src'
+import {expect, test} from 'vitest'
-// test('run code', async () => {
-// const code = `
-// print("hello")
-// raise Exception("err")
-// `
-// const { stdout, stderr } = await runCode('Python3', code)
-// console.log('stdout', stdout)
-// console.log('stderr', stderr)
+test('run code', async () => {
-// expect(stdout).toEqual('hello')
-// // expect(stderr).toContain('Exception: err')
-// })
+ const code = `
+test="test\\n"
+print(10*test)
+raise Exception("err")
+`
+ const {stdout, stderr} = await runCode('PPSrlH5TIvFx', code)
+ console.log('stdout', stdout)
+ console.log('stderr', stderr)
+ expect(stdout.length).toEqual(50)
+ expect(stderr).toContain('Exception: err')
+})
test('run code using unsupported runtime', async () => {
await expect(() => runCode('Unsupported', 'print("hello")')).rejects.toThrowError(
diff --git a/packages/python-sdk/tests/test_run_code.py b/packages/python-sdk/tests/test_run_code.py
index cd2f4574d..5407cfd70 100644
--- a/packages/python-sdk/tests/test_run_code.py
+++ b/packages/python-sdk/tests/test_run_code.py
@@ -5,10 +5,10 @@ from e2b.session.exception import UnsupportedRuntimeException
async def test_run_code():
- code = "console.log('hello'); throw new Error('error')"
+ code = "console.log('hello\\n'.repeat(10)); throw new Error('error')"
stdout, stderr = await run_code("Node16", code)
- assert stdout == "hello"
+ assert len(stdout) == 60
assert "Error: error" in stderr
diff --git a/packages/python-sdk/tests/test_session.py b/packages/python-sdk/tests/test_session.py
index e227bb927..29f06786a 100644
--- a/packages/python-sdk/tests/test_session.py
+++ b/packages/python-sdk/tests/test_session.py
@@ -22,7 +22,7 @@ async def test_custom_cwd():
# filesystem ops does not respect the cwd yet
await session.filesystem.write("hello.txt", "Hello VM!")
- proc = await session.process.start("cat /hello.txt") # notice the file is in root
+ proc = await session.process.start("cat /hello.txt") # notice the file is in root
output = await proc
assert output.stdout == "Hello VM!"