Skip to content

Commit

Permalink
render the bundle inline instead of relying on static/, now works wit…
Browse files Browse the repository at this point in the history
…h test file arguments
  • Loading branch information
James Halliday committed Jun 25, 2012
1 parent 9d57cd8 commit 4a636db
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
24 changes: 17 additions & 7 deletions bin/cmd.js
@@ -1,16 +1,16 @@
#!/usr/bin/env node
var shoe = require('shoe');
var http = require('http');
var ecstatic = require('ecstatic')(__dirname + '/../static');
var argv = require('optimist').argv;
var mkdirp = require('mkdirp');
var bundle = require('../lib/bundle')(argv._);

var insertProxy = require('../lib/proxy');
var producer = require('../lib/producer');

//var profileDir = '/tmp/' + Math.random().toString(16).slice(2);
var profileDir = '/tmp/02faf1b1';
mkdirp.sync(profileDir);
(function () {
var mkdirp = require('mkdirp');
mkdirp.sync(profileDir);
})();

var port = {
proxy : 54045,
Expand All @@ -22,7 +22,17 @@ var script = '<script src="'
+ '"></script>'
;
var proxy = insertProxy(script, [ 'http://localhost:' + port.server ]);
var server = http.createServer(ecstatic);
var server = (function () {
var http = require('http');
var ecstatic = require('ecstatic')(__dirname + '/../static');
return http.createServer(function (req, res) {
if (req.url.split('?')[0] === '/') {
res.setHeader('content-type', 'text/html');
res.end('<script>' + bundle + '</script>');
}
else ecstatic(req, res)
});
})();

var launcher = require('../lib/launcher');
var browser;
Expand All @@ -41,12 +51,12 @@ var browser;
})();

var JSONStream = require('JSONStream');
var shoe = require('shoe');
var sock = shoe(function (stream) {
stream
.pipe(JSONStream.parse([ true ]))
.pipe(producer())
.on('end', function () {
console.log('--------')
server.close();
proxy.close();
browser.kill();
Expand Down
9 changes: 9 additions & 0 deletions lib/bundle.js
@@ -0,0 +1,9 @@
var browserify = require('browserify');

module.exports = function (testFiles) {
var bundle = browserify();
testFiles.forEach(function (file) {
bundle.addEntry(file);
});
return bundle.bundle();
};
4 changes: 2 additions & 2 deletions lib/launcher.js
Expand Up @@ -2,11 +2,11 @@ var spawn = require('child_process').spawn;

module.exports = function (opts) {
var args = [
'xvfb-run', '-w', '0', '-a',
'xvfb-run', '-w', '0', '-a',
'google-chrome',
'--proxy-server=localhost:' + opts.proxy,
'--user-data-dir=' + opts.profileDir,
'http://localhost:' + opts.server
'http://localhost:' + opts.server + '/?' + Math.random()
];
var ps = spawn(args[0], args.slice(1));
return ps;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -28,8 +28,8 @@
"optimist" : "~0.3.4",
"mkdirp" : "~0.3.3",
"tap" : "~0.2.5",
"browserify" : "~1.13.1",
"shoe" : "~0.0.1",
"browserify" : "~1.13.3",
"shoe" : "~0.0.2",
"event-stream" : "~2.0.4",
"JSONStream" : "~0.3.0"
},
Expand Down

0 comments on commit 4a636db

Please sign in to comment.