forked from rwaldron/johnny-five
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepl.js
70 lines (61 loc) · 1.47 KB
/
repl.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
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
65
66
67
68
69
70
require("./common/bootstrap");
exports["Repl"] = {
setUp(done) {
this.sandbox = sinon.sandbox.create();
this.board = newBoard();
done();
},
tearDown(done) {
Board.purge();
this.sandbox.restore();
done();
},
instanceof(test) {
test.expect(1);
test.equal(new Repl({ board: this.board }) instanceof Repl, true);
test.done();
},
repl(test) {
const io = new MockFirmata();
const board = new Board({
io,
debug: false
});
test.expect(3);
board.on("ready", function() {
test.ok(this.repl === board.repl);
test.ok(this.repl instanceof Repl);
test.ok(this.repl.context);
test.done();
});
io.emit("connect");
io.emit("ready");
},
fwdExitEvent(test) {
test.expect(1);
const io = new MockFirmata();
const board = new Board({
io,
debug: false
});
// Extra-careful guard against calling test.done() twice here.
// This was causing "Cannot read property 'setUp' of undefined" errors
// See https://github.com/caolan/nodeunit/issues/234
let calledTestDone = false;
const reallyExit = this.sandbox.stub(process, "reallyExit", () => {
reallyExit.restore();
if (!calledTestDone) {
calledTestDone = true;
test.done();
}
});
board.on("ready", function() {
this.on("exit", () => {
test.ok(true);
});
this.repl.close();
});
io.emit("connect");
io.emit("ready");
},
};