-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrun-command.test.ts
More file actions
64 lines (49 loc) · 1.51 KB
/
run-command.test.ts
File metadata and controls
64 lines (49 loc) · 1.51 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { expect } from "vitest";
import { test } from "../src";
test(
"user can run commands inside webcontainer",
{ retry: 3 },
async ({ webcontainer }) => {
const output = await webcontainer.runCommand("node", ["--version"]);
expect(output).toMatch(/v2[0-9]/);
},
);
test("user can run interactive commands inside webcontainer", async ({
webcontainer,
}) => {
const { exit, waitForText, write } = webcontainer.runCommand("node");
await waitForText("Welcome to Node.js");
await write("console.log(20 + 19)\n");
await waitForText("39");
await write("console.log(os.platform(), os.arch())\n");
await waitForText("linux x64");
await exit();
});
test("user can see timeout errors with clear description", async ({
webcontainer,
}) => {
const { exit, waitForText, isDone } = webcontainer.runCommand("ls", ["/"]);
await isDone;
await expect(waitForText("This won't match anything", 10)).rejects
.toThrowErrorMatchingInlineSnapshot(`
[Error: Timeout when waiting for text "This won't match anything".
Received:
bin dev etc home tmp usr]
`);
await exit();
});
test("user can listen for stream's chunks", async ({ webcontainer }) => {
const { isDone, onData } = webcontainer.runCommand("node", [
"--eval",
"console.log('First'); setTimeout(() => console.log('Second'), 1_000);",
]);
const data: string[] = [];
onData((chunk) => data.push(chunk.trim()));
await isDone;
expect(data).toMatchInlineSnapshot(`
[
"First",
"Second",
]
`);
});