-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathsetup.ts
More file actions
40 lines (34 loc) · 913 Bytes
/
setup.ts
File metadata and controls
40 lines (34 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Sandbox } from '../src'
import { test as base } from 'vitest'
const timeoutMs = 60_000
const template = process.env.E2B_TESTS_TEMPLATE || 'code-interpreter-v1'
interface SandboxFixture {
sandbox: Sandbox
}
export const sandboxTest = base.extend<SandboxFixture>({
sandbox: [
async ({}, use) => {
const sandbox = await Sandbox.create(template, {
timeoutMs,
})
try {
await use(sandbox)
} finally {
try {
await sandbox.kill()
} catch (err) {
if (!isDebug) {
console.warn(
'Failed to kill sandbox — this is expected if the test runs with local envd.'
)
}
}
}
},
{ auto: true },
],
})
export const isDebug = process.env.E2B_DEBUG !== undefined
export async function wait(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}