Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
GCheung55 committed Jan 23, 2014
1 parent f5c3c01 commit c3ffde7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 29 deletions.
7 changes: 6 additions & 1 deletion lib/buster-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ var fs = require("fs");
var http = require("http");
var rampResources = require("ramp-resources");

function addExtensions(extensions, config){
var ext = extensions || [];
config.extensions = ext.concat(config.extensions || []);
}

// TODO: add test coverage (integration test?)
function configureGroup(group, extensions, defaultReporter) {
group.extensions = extensions;
addExtensions(extensions, group);
group.on("load:framework", function (resourceSet) {
// Test bed
resourceSet.addResource({
Expand Down
90 changes: 62 additions & 28 deletions test/buster-static-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,112 @@ var buster = require("buster");
var assert = buster.assert;
var cli = require("../lib/buster-static");
var http = require("http");
var testConfig = require('./fixtures/test-config')

var NOOP = function () {};
var NOOP = function() {};

buster.testCase("buster-static", {
setUp: function () {
setUp: function() {
this.s = cli.create();
this.s.logger = { log: NOOP };
this.s.logger = {
log: NOOP,
error: NOOP
};
},

"starts server with no arguments": function (done) {
this.stub(this.s, "startServer", done(function () {
"starts server with no arguments": function(done) {
this.stub(this.s, "startServer", done(function() {
assert(true);
}));
this.s.run(["--config", __dirname + "/fixtures/test-config.js"]);
},

"starts server on specified port with --port": function (done) {
this.stub(this.s, "startServer", function () {
"starts server on specified port with --port": function(done) {
this.stub(this.s, "startServer", function() {
assert(true);
done();
});
this.s.run(["--config",
__dirname + "/fixtures/test-config.js",
"--port",
"4224"]);
__dirname + "/fixtures/test-config.js",
"--port",
"4224"
]);
},

"writes to disk with operand": function (done) {
this.stub(this.s, "writeToDisk", function () {
"// writes to disk with operand": function(done) {
this.stub(this.s, "writeToDisk", function() {
assert(true);
done();
});
this.s.run(["--config",
__dirname + "/fixtures/test-config.js",
"/tmp/static-test"]);
__dirname + "/fixtures/test-config.js"
]);
},

"http server": {
setUp: function (done) {
setUp: function(done) {
var self = this;
this.s.run(["--config",
__dirname + "/fixtures/test-config.js",
"--port",
"17171"]);
__dirname + "/fixtures/test-config.js",
"--port",
"17171"
]);

var oldStartServer = this.s.startServer;
this.s.startServer = function () {
this.s.startServer = function() {
oldStartServer.apply(self.s, arguments);
self.s.httpServer.on("listening", done);
};
},

tearDown: function (done) {
this.s.httpServer.on("close", done);
this.s.httpServer.close();
tearDown: function(done) {
this.s.httpServer.close(done);
},

"gets testbed": function (done) {
var req = http.request({ port: 17171, path: "/" }, function (res) {
"gets testbed": function(done) {
var req = http.request({
port: 17171,
path: "/"
}, function(res) {
assert.equals(res.statusCode, 200);
done();
}).end();
});

// properly disconnect the connection
req.shouldKeepAlive = false;

req.end();
},

"gets none-existent file": function (done) {
"gets none-existent file": function(done) {
var req = http.request({
port: 17171,
path: "/buster-sucks"
}, function (res) {
}, function(res) {
assert.equals(res.statusCode, 404);
done();
}).end();
});

// properly disconnect the connection
req.shouldKeepAlive = false;

req.end();
}
},

"loads optional extensions": function(done) {
testConfig['Tests'].extensions = [{
name: 'test-extension',
create: function() {
assert(true)
delete testConfig['Tests'].extensions;
done();
return Object.create(this)
}
}];

this.s.run(["--config",
__dirname + "/fixtures/test-config.js"
]);
}
});

0 comments on commit c3ffde7

Please sign in to comment.