forked from nowk/gulp-go
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index_test.js
98 lines (82 loc) · 2.15 KB
/
index_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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var util = require("util");
var assert = require("chai").assert;
var gulpgo = require("./");
var GoRun = gulpgo.GoRun;
function MyRun() {
var args = Array.prototype.slice.call(arguments);
GoRun.apply(this, args);
}
util.inherits(MyRun, GoRun);
var noop = function() {
//
};
describe("GoRun", function() {
var args;
var start = 0;
var stop = 0;
var pid = 123;
var callback = 0;
// stub _spawn
MyRun.prototype._spawn = function() {
args = Array.prototype.slice.call(arguments);
start++;
return {
pid: pid,
stdout: {on: noop},
stderr: {on: noop},
on: noop
};
};
// stup _stop
MyRun.prototype._stop = function(callback) {
stop++;
callback();
};
beforeEach(function() {
args = null;
start = 0;
stop = 0;
pid = 123;
callback = 0;
});
it("starts a go run process", function() {
var go = new MyRun("mymain.go", ["--foo", "bar"]);
assert.deepEqual(go, go.run());
assert.deepEqual(["run", "mymain.go", "--foo", "bar"], args);
assert.equal(start, 1);
});
it("appends args sent on run", function() {
var go = new MyRun("mymain.go", ["--foo", "bar"]);
go.run("--baz", "qux", "--foo", "bar");
assert.deepEqual([
"run", "mymain.go", "--foo", "bar", "--baz", "qux", "--foo", "bar"
], args);
});
it("adds the process to the global ps store", function() {
var go = new MyRun("main.go");
go.run();
assert.deepEqual(gulpgo.ps()[123], go);
});
it("stop stops and removes from global ps store", function() {
var go = new MyRun("main.go");
go.run();
go.stop(function() {
callback++;
});
assert.deepEqual(gulpgo.ps(), {});
assert.equal(stop, 1);
assert.equal(callback, 1);
});
it("Restart restarts process", function() {
var go = new MyRun("mymain.go", ["--foo", "bar"]);
go.run();
call = ""; // reset call, to re-assert
pid = 456; // change pid
go.restart();
assert.deepEqual(["run", "mymain.go", "--foo", "bar"], args);
assert.equal(start, 2);
assert.equal(stop, 1);
assert.isUndefined(gulpgo.ps()[123]);
assert.deepEqual(gulpgo.ps()[456], go);
});
});