Skip to content

Commit

Permalink
add tools for test http
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Apr 22, 2013
1 parent 843fa57 commit 01daa62
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test:
make test_http

test_http:
phantomjs tools/phantom.js http://localhost/~lifesinger/seajs/seajs/tests/runner.html?console
@node tools/server.js . phantomjs tools/phantom.js http://127.0.0.1:9012/tests/runner.html?console

test_local:
phantomjs tools/phantom.js tests/runner.html?console
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {},
"devDependencies": {
"grunt": "0.4.0",
"node-static": "~0.6.9",
"grunt-contrib-concat": "0.1.2",
"gcc": "0.2.0"
},
Expand Down
45 changes: 45 additions & 0 deletions tools/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var fs = require('fs');
var http = require('http');
var print = require('util').print;
var spawn = require('child_process').spawn;
var static = require('node-static');

function createServer(dir, cmd) {
dir = dir || '.';

// Server Start
var file = new static.Server(fs.realpathSync(dir));

var server = http.createServer(function(request, response) {
request.addListener('end', function() {
file.serve(request, response);
}).resume();
});

server.listen(9012, function() {
if (cmd) {
var args = cmd.split(' ');
args = args.map(function(arg) {
return arg.trim();
});
args = args.filter(function(arg) {
return arg.length;
});
var runner = spawn(args[0], args.slice(1));
runner.stdout.on('data', function(data) {
print(data.valueOf());
});
runner.on('exit', function(code) {
if (code === 127) {
print(cmd + ' not available');
}
server.close();
process.exit(code);
});
}
});
}

var dir = process.argv[2] || '.';
var cmd = process.argv.slice(3);
createServer(dir, cmd.join(' '));

0 comments on commit 01daa62

Please sign in to comment.