Skip to content

Commit

Permalink
Fix sandbox killing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentaTomas committed Oct 28, 2024
1 parent eac4592 commit 497bdc9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
12 changes: 9 additions & 3 deletions packages/js-sdk/tests/runtimes/browser/run.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ function E2BTest() {
useEffect(() => {
const getText = async () => {
const sandbox = await Sandbox.create()
await sandbox.commands.run('echo "Hello World" > hello.txt')
const content = await sandbox.files.read('hello.txt')
setText(content)

try {
await sandbox.commands.run('echo "Hello World" > hello.txt')
const content = await sandbox.files.read('hello.txt')
setText(content)
} finally {
await sandbox.kill()
}
}

getText()
}, [])

Expand Down
10 changes: 7 additions & 3 deletions packages/js-sdk/tests/sandbox/commands/envVars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ sandboxTest.skipIf(isDebug)('env vars', async ({ sandbox }) => {
sandboxTest.skipIf(isDebug)('env vars on sandbox', async () => {
const sandbox = await Sandbox.create({ envs: { FOO: 'bar' } })

const cmd = await sandbox.commands.run('echo "$FOO"')
try {
const cmd = await sandbox.commands.run('echo "$FOO"')

assert.equal(cmd.exitCode, 0)
assert.equal(cmd.stdout.trim(), 'bar')
assert.equal(cmd.exitCode, 0)
assert.equal(cmd.stdout.trim(), 'bar')
} finally {
await sandbox.kill()
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ async def test_command_envs(async_sandbox: AsyncSandbox):

@pytest.mark.skip_debug()
async def test_sandbox_envs(template: str):
sbx = await AsyncSandbox.create(template, envs={"FOO": "bar"})
cmd = await sbx.commands.run("echo $FOO")
assert cmd.stdout.strip() == "bar"

await sbx.kill()
try:
sbx = await AsyncSandbox.create(template, envs={"FOO": "bar"})
cmd = await sbx.commands.run("echo $FOO")
assert cmd.stdout.strip() == "bar"
finally:
await sbx.kill()
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def test_command_envs(sandbox: Sandbox):
@pytest.mark.skip_debug()
def test_sandbox_envs(template: str):
sandbox = Sandbox(template, envs={"FOO": "bar"})
cmd = sandbox.commands.run("echo $FOO")
assert cmd.stdout.strip() == "bar"

sandbox.kill()
try:
cmd = sandbox.commands.run("echo $FOO")
assert cmd.stdout.strip() == "bar"
finally:
sandbox.kill()

0 comments on commit 497bdc9

Please sign in to comment.