Skip to content

Commit 325cebc

Browse files
committed
updated tests
1 parent 699cb05 commit 325cebc

File tree

3 files changed

+51
-22
lines changed

3 files changed

+51
-22
lines changed

js/tests/contexts.test.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,43 @@ import { sandboxTest } from './setup'
55
sandboxTest('create context with no options', async ({ sandbox }) => {
66
const context = await sandbox.createCodeContext()
77

8-
expect(context.id).toBeDefined()
9-
expect(context.language).toBe('python')
10-
expect(context.cwd).toBe('/home/user')
8+
const contexts = await sandbox.listCodeContexts()
9+
const lastContext = contexts[contexts.length - 1]
10+
11+
expect(lastContext.id).toBeDefined()
12+
expect(lastContext.language).toBe(context.language)
13+
expect(lastContext.cwd).toBe(context.cwd)
1114
})
1215

1316
sandboxTest('create context with options', async ({ sandbox }) => {
1417
const context = await sandbox.createCodeContext({
1518
language: 'python',
16-
cwd: '/home/user/test',
19+
cwd: '/root',
1720
})
1821

19-
expect(context.id).toBeDefined()
20-
expect(context.language).toBe('python')
21-
expect(context.cwd).toBe('/home/user/test')
22+
const contexts = await sandbox.listCodeContexts()
23+
const lastContext = contexts[contexts.length - 1]
24+
25+
expect(lastContext.id).toBeDefined()
26+
expect(lastContext.language).toBe(context.language)
27+
expect(lastContext.cwd).toBe(context.cwd)
2228
})
2329

2430
sandboxTest('remove context', async ({ sandbox }) => {
2531
const context = await sandbox.createCodeContext()
2632

2733
await sandbox.removeCodeContext(context.id)
34+
const contexts = await sandbox.listCodeContexts()
35+
36+
expect(contexts.map((context) => context.id)).not.toContain(context.id)
2837
})
2938

3039
sandboxTest('list contexts', async ({ sandbox }) => {
3140
const contexts = await sandbox.listCodeContexts()
3241

33-
expect(contexts.length).toBeGreaterThan(0)
42+
// default contexts should include python and javascript
43+
expect(contexts.map((context) => context.language)).toContain('python')
44+
expect(contexts.map((context) => context.language)).toContain('javascript')
3445
})
3546

3647
sandboxTest('restart context', async ({ sandbox }) => {

python/tests/async/test_async_contexts.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
async def test_create_context_with_no_options(async_sandbox: AsyncSandbox):
55
context = await async_sandbox.create_code_context()
66

7-
assert context.id is not None
8-
assert context.language == "python"
9-
assert context.cwd == "/home/user"
7+
contexts = await async_sandbox.list_code_contexts()
8+
last_context = contexts[-1]
9+
10+
assert last_context.id is not None
11+
assert last_context.language == context.language
12+
assert last_context.cwd == context.cwd
1013

1114

1215
async def test_create_context_with_options(async_sandbox: AsyncSandbox):
@@ -15,9 +18,12 @@ async def test_create_context_with_options(async_sandbox: AsyncSandbox):
1518
cwd="/home/user/test",
1619
)
1720

18-
assert context.id is not None
19-
assert context.language == "python"
20-
assert context.cwd == "/home/user/test"
21+
contexts = await async_sandbox.list_code_contexts()
22+
last_context = contexts[-1]
23+
24+
assert last_context.id is not None
25+
assert last_context.language == context.language
26+
assert last_context.cwd == context.cwd
2127

2228

2329
async def test_remove_context(async_sandbox: AsyncSandbox):
@@ -29,7 +35,10 @@ async def test_remove_context(async_sandbox: AsyncSandbox):
2935
async def test_list_contexts(async_sandbox: AsyncSandbox):
3036
contexts = await async_sandbox.list_code_contexts()
3137

32-
assert len(contexts) > 0
38+
# default contexts should include python and javascript
39+
languages = [context.language for context in contexts]
40+
assert "python" in languages
41+
assert "javascript" in languages
3342

3443

3544
async def test_restart_context(async_sandbox: AsyncSandbox):

python/tests/sync/test_contexts.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
def test_create_context_with_no_options(sandbox: Sandbox):
55
context = sandbox.create_code_context()
66

7-
assert context.id is not None
8-
assert context.language == "python"
9-
assert context.cwd == "/home/user"
7+
contexts = sandbox.list_code_contexts()
8+
last_context = contexts[-1]
9+
10+
assert last_context.id is not None
11+
assert last_context.language == context.language
12+
assert last_context.cwd == context.cwd
1013

1114

1215
def test_create_context_with_options(sandbox: Sandbox):
@@ -15,9 +18,12 @@ def test_create_context_with_options(sandbox: Sandbox):
1518
cwd="/home/user/test",
1619
)
1720

18-
assert context.id is not None
19-
assert context.language == "python"
20-
assert context.cwd == "/home/user/test"
21+
contexts = sandbox.list_code_contexts()
22+
last_context = contexts[-1]
23+
24+
assert last_context.id is not None
25+
assert last_context.language == context.language
26+
assert last_context.cwd == context.cwd
2127

2228

2329
def test_remove_context(sandbox: Sandbox):
@@ -29,7 +35,10 @@ def test_remove_context(sandbox: Sandbox):
2935
def test_list_contexts(sandbox: Sandbox):
3036
contexts = sandbox.list_code_contexts()
3137

32-
assert len(contexts) > 0
38+
# default contexts should include python and javascript
39+
languages = [context.language for context in contexts]
40+
assert "python" in languages
41+
assert "javascript" in languages
3342

3443

3544
def test_restart_context(sandbox: Sandbox):

0 commit comments

Comments
 (0)