Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Use API key in the JS SDK tests

Tomas Valentad834f295cd28
diff --git a/packages/js-sdk/test/filesystem.test.mjs b/packages/js-sdk/test/filesystem.test.mjs
index c0d2de05a..169a2eb87 100644
--- a/packages/js-sdk/test/filesystem.test.mjs
+++ b/packages/js-sdk/test/filesystem.test.mjs
@@ -1,8 +1,10 @@
import { Session } from '../src'
import { expect, test } from 'vitest'
+const E2B_API_KEY = process.env.E2B_API_KEY
+
test('list files', async () => {
- const session = await Session.create({ id: "Nodejs" })
+ const session = await Session.create({ id: "Nodejs", apiKey: E2B_API_KEY })
await session.filesystem.makeDir("/test/new")
const ls = await session.filesystem.list("/test")
@@ -12,7 +14,7 @@ test('list files', async () => {
})
test('create file', async () => {
- const session = await Session.create({id: "Nodejs" })
+ const session = await Session.create({id: "Nodejs", , apiKey: E2B_API_KEY })
await session.filesystem.makeDir("/test")
await session.filesystem.write("/test/test.txt", "Hello World!")
@@ -23,7 +25,7 @@ test('create file', async () => {
})
test('read and write', async () => {
- const session = await Session.create({id: "Nodejs" })
+ const session = await Session.create({id: "Nodejs", apiKey: E2B_API_KEY })
await session.filesystem.write("/tmp/test.txt", "Hello World!")
@@ -35,7 +37,7 @@ test('read and write', async () => {
})
test('list delete files', async () => {
- const session = await Session.create({id: "Nodejs" })
+ const session = await Session.create({id: "Nodejs", apiKey: E2B_API_KEY })
await session.filesystem.makeDir("/test/new")
let ls = await session.filesystem.list("/test")
@@ -50,11 +52,11 @@ test('list delete files', async () => {
})
test('watch dir', async () => {
- const session = new Session({ id: "Nodejs" })
+ const session = new Session({ id: "Nodejs", apiKey: E2B_API_KEY })
await session.open()
await session.filesystem.write("/tmp/test.txt", "Hello")
- const watcher = await session.filesystem.watchDir("/tmp")
+ const watcher = session.filesystem.watchDir("/tmp")
const events = []
watcher.addEventListener(ev => events.push(ev))
diff --git a/packages/js-sdk/test/process.test.mjs b/packages/js-sdk/test/process.test.mjs
index 1f5d6b8ac..899211571 100644
--- a/packages/js-sdk/test/process.test.mjs
+++ b/packages/js-sdk/test/process.test.mjs
@@ -1,8 +1,10 @@
import { Session } from '../src'
import { expect, test, vi } from 'vitest'
+const E2B_API_KEY = process.env.E2B_API_KEY
+
test('process on stdout/stderr', async () => {
- const session = await Session.create({ id: "Nodejs" })
+ const session = await Session.create({ id: "Nodejs", apiKey: E2B_API_KEY })
const stdout = []
const stderr = []
@@ -25,7 +27,7 @@ test('process on stdout/stderr', async () => {
})
test('process on exit', async () => {
- const session = await Session.create({ id: "Nodejs" })
+ const session = await Session.create({ id: "Nodejs", apiKey: E2B_API_KEY })
const onExit = vi.fn(() => {})
@@ -41,7 +43,7 @@ test('process on exit', async () => {
})
test('process send stdin', async () => {
- const session = await Session.create({ id: "Nodejs" })
+ const session = await Session.create({ id: "Nodejs", apiKey: E2B_API_KEY })
const process = await session.process.start({
cmd: 'while IFS= read -r line; do echo "$line"; sleep 1; done',
diff --git a/packages/js-sdk/test/session.test.mjs b/packages/js-sdk/test/session.test.mjs
index 2887bde3e..0ac6dbff8 100644
--- a/packages/js-sdk/test/session.test.mjs
+++ b/packages/js-sdk/test/session.test.mjs
@@ -1,14 +1,16 @@
import { Session } from '../src'
import { expect, test, vi } from 'vitest'
+const E2B_API_KEY = process.env.E2B_API_KEY
+
test('create session', async () => {
- const session = await Session.create({ id: "Nodejs" })
+ const session = await Session.create({ id: "Nodejs", apiKey: E2B_API_KEY })
await session.close()
})
test('create multiple sessions', async () => {
- const session = await Session.create({ id: "Nodejs" })
- const session2 = await Session.create({ id: "Nodejs" })
+ const session = await Session.create({ id: "Nodejs", apiKey: E2B_API_KEY })
+ const session2 = await Session.create({ id: "Nodejs", apiKey: E2B_API_KEY })
await session.close()
await session2.close()
})