-
Notifications
You must be signed in to change notification settings - Fork 0
/
p5js-cli.test.js
31 lines (29 loc) · 904 Bytes
/
p5js-cli.test.js
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
const path = require("path");
const exec = require("child_process").exec;
const sketchName = require("uuid").v4();
describe("create new sketch", () => {
test("create successfully.", async () => {
const result = await cli(["new", sketchName], "/tmp");
expect(result.code).toBe(0);
});
test("failed when exists.", async () => {
const result = await cli(["new", sketchName], "/tmp");
expect(result.code).toBe(1);
});
});
function cli(args, cwd) {
return new Promise((resolve) => {
exec(
`node ${path.resolve("./p5js-cli")} ${args.join(" ")}`,
{ cwd },
(error, stdout, stderr) => {
resolve({
code: error && error.code ? error.code : 0,
error,
stdout,
stderr,
});
}
);
});
}