Skip to content

Commit cdb355f

Browse files
committed
[test] Add useful mocks
This adds basic mocks for: * `ChildProcess` * `Stream` * `forever.Monitor`
1 parent ed75bd4 commit cdb355f

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

test/helpers/mocks/child-process.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var util = require('util'),
2+
EventEmitter2 = require('eventemitter2').EventEmitter2,
3+
StreamMock = require('./stream').StreamMock;
4+
5+
var ChildProcessMock = exports.ChildProcessMock = function () {
6+
EventEmitter2.call(this);
7+
8+
this.stdout = new StreamMock();
9+
this.stderr = new StreamMock();
10+
};
11+
util.inherits(ChildProcessMock, EventEmitter2);
12+

test/helpers/mocks/monitor.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var util = require('util'),
2+
broadway = require('broadway'),
3+
ChildProcessMock = require('./child-process').ChildProcessMock;
4+
5+
var MonitorMock = exports.MonitorMock = function (options) {
6+
broadway.App.call(this, options);
7+
8+
this.child = new ChildProcessMock();
9+
};
10+
util.inherits(MonitorMock, broadway.App);
11+

test/helpers/mocks/stream.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var util = require('util'),
2+
EventEmitter2 = require('eventemitter2').EventEmitter2;
3+
4+
var StreamMock = exports.StreamMock = function () {
5+
EventEmitter2.call(this);
6+
7+
this.contents = [];
8+
this.closed = false;
9+
};
10+
util.inherits(StreamMock, EventEmitter2);
11+
12+
StreamMock.prototype.write = function (data) {
13+
this.contents.push(data);
14+
};
15+
16+
StreamMock.prototype.close = function () {
17+
this.closed = true;
18+
};
19+

0 commit comments

Comments
 (0)