chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { expect, inject, test } from 'vitest'
|
||||
import { render } from 'vitest-browser-react'
|
||||
import React from 'react'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
import { Sandbox } from '../../../src'
|
||||
import { template } from '../../template'
|
||||
|
||||
function E2BTest() {
|
||||
const [text, setText] = useState<string>()
|
||||
|
||||
useEffect(() => {
|
||||
const getText = async () => {
|
||||
const sandbox = await Sandbox.create(template, {
|
||||
apiKey: inject('E2B_API_KEY'),
|
||||
domain: inject('E2B_DOMAIN'),
|
||||
})
|
||||
|
||||
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()
|
||||
}, [])
|
||||
|
||||
return <div>{text}</div>
|
||||
}
|
||||
test('browser test', async () => {
|
||||
const screen = await render(<E2BTest />)
|
||||
await expect
|
||||
.element(screen.getByText('Hello World'), { timeout: 30_000 })
|
||||
.toBeInTheDocument()
|
||||
}, 40_000)
|
||||
@@ -0,0 +1,30 @@
|
||||
import { expect, test } from 'bun:test'
|
||||
|
||||
import { Sandbox } from '../../../src'
|
||||
import { template } from '../../template'
|
||||
|
||||
test(
|
||||
'Bun test',
|
||||
async () => {
|
||||
const sbx = await Sandbox.create(template, { timeoutMs: 5_000 })
|
||||
try {
|
||||
const isRunning = await sbx.isRunning()
|
||||
expect(isRunning).toBeTruthy()
|
||||
|
||||
const text = 'Hello, World!'
|
||||
|
||||
const cmd = await sbx.commands.run(`echo "${text}"`)
|
||||
|
||||
expect(cmd.exitCode).toBe(0)
|
||||
expect(cmd.stdout).toEqual(`${text}\n`)
|
||||
|
||||
await sbx.files.write('test.txt', text)
|
||||
const test = await sbx.files.read('test.txt')
|
||||
|
||||
expect(test).toEqual(text)
|
||||
} finally {
|
||||
await sbx.kill()
|
||||
}
|
||||
},
|
||||
{ timeout: 20_000 }
|
||||
)
|
||||
@@ -0,0 +1,27 @@
|
||||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
} from 'https://deno.land/std@0.224.0/assert/mod.ts'
|
||||
import { load } from 'https://deno.land/std@0.224.0/dotenv/mod.ts'
|
||||
|
||||
await load({ envPath: '.env', export: true })
|
||||
|
||||
import { Sandbox } from '../../../dist/index.mjs'
|
||||
import { template } from '../../template'
|
||||
|
||||
Deno.test('Deno test', async () => {
|
||||
const sbx = await Sandbox.create(template, { timeoutMs: 5_000 })
|
||||
try {
|
||||
const isRunning = await sbx.isRunning()
|
||||
assert(isRunning)
|
||||
|
||||
const text = 'Hello, World!'
|
||||
|
||||
const cmd = await sbx.commands.run(`echo "${text}"`)
|
||||
|
||||
assertEquals(cmd.exitCode, 0)
|
||||
assertEquals(cmd.stdout, `${text}\n`)
|
||||
} finally {
|
||||
await sbx.kill()
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user