node-stubby-server-cli
Module which exposes the Stubby Server API interface from node. The API is clean and simple to use. Note that if you
mute() the client, you cannot get any events so it's NOT recommended to do this.
We also use ES6 weakmaps to make certain properties private, however, a polyfill is included in the event your
application isn't ES6 ready. Please fork and enhance or file a bug ticket if you notice any issues
ES6
node --harmony <script>.js
< ES6
node <script>.js
Example usage
var cli = new CLI();
cli.admin(8001)
.stubs(8000)
.tls(8002)
.help()
.mute()
.data(__dirname + '/data.yml')
.unmute()
.start()
.on(cli.events.REQUEST, function(data) {
console.log(data);
}).on(cli.events.RESPONSE, function(data) {
console.log(data);
});
cli.once('LOADED_ROUTE', function() {
next();
});
Gulp.js Example
var gulp = require('gulp');
var mocha = require('gulp-mocha');
var StubbyCLI = require('node-stubby-server-cli');
var cli = new StubbyCLI();
gulp.task('start:stubby', function(next) {
cli.admin(<admin port>)
.stubs(<stubs port>)
.tls(<tls port>)
.data(<path to data file>)
.unmute()
.start();
// The server should be listening
// after this event...
cli.once('LOADED_ROUTE', function() {
next();
});
});
gulp.task('test', ['start:stubby'], function() {
// run your tests after the stub server starts
});
gulp.task('stop:stubby', ['test'], function(next) {
cli.kill();
next();
});
// Default tasks to run
gulp.task('default', [
'start:stubby',
'test',
'stop:stubby'
]);
Event.REQUEST Payload
{
"time": "10:27:25",
"method": "GET",
"location": "stubs",
"path": "/hello"
}
Event.RESPONSE Payload
{
"time": "09:26:47",
"statusCode": "404",
"location": "stubs",
"path": "/your/awesome/endpoint",
"message": "is not a registered endpoint"
}
TODO