CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/project/exec_shell_code.test.ts
Views: 687
1
// jest test if calling something in bash works
2
3
import { exec_shell_code } from "@cocalc/project/exec_shell_code";
4
5
test("exec_shell_code", (done) => {
6
const mesg = {
7
id: "abf3b9ca-47e3-4d77-a0f7-eec04952c684",
8
event: "project_exec",
9
command: "echo $(( 2 * 21 ))",
10
bash: true,
11
};
12
13
// make socket a mock object with a method write_mesg
14
const socket = {
15
write_mesg: (type, mesg) => {
16
//console.log("type", type, "mesg", mesg);
17
expect(type).toBe("json");
18
expect(mesg).toEqual({
19
event: "project_exec_output",
20
id: mesg.id,
21
stdout: expect.any(String),
22
stderr: "",
23
exit_code: 0,
24
type: "blocking",
25
});
26
expect(mesg.stdout).toBe("42\n");
27
done();
28
},
29
};
30
31
exec_shell_code(socket as any, mesg);
32
});
33
34