Permalink
Browse files

Changes to get performance tests served on Heroku

  • Loading branch information...
jansepar committed Jul 4, 2013
1 parent ba4ac50 commit cf35668e634e713181955554cb12ec0985e1649e
Showing with 30 additions and 17 deletions.
  1. +1 −0 Procfile
  2. +5 −5 package.json
  3. +3 −0 performance/jazzcat.html
  4. +21 −12 server.js
View
@@ -0,0 +1 @@
web: node server.js
View
@@ -3,9 +3,11 @@
"version": "2.0.0alpha4",
"description": "The Mobify.js client side adaptation library.",
"author": "Mobify <dev@mobify.com>",
"devDependencies": {
"connect": "2.3.4",
"dependencies": {
"express": "3.3.1",
"hbs": "~2.3.0"
},
"devDependencies": {
"grunt": "~0.4.0",
"grunt-requirejs": "0.3.2",
"grunt-contrib-watch": "~0.2.x",
@@ -15,9 +17,7 @@
"grunt-s3": "0.2.0-alpha.2",
"grunt-contrib-uglify": "~0.2.0",
"grunt-jekyll": "~0.3.6",
"grunt-express": "~0.3.6",
"express-dust": "~0.1.5",
"hbs": "~2.3.0"
"grunt-express": "~0.3.6"
},
"engine": ">= 0.10.1",
"repository": {
View
@@ -125,6 +125,7 @@ <h1>Performance test for Jazzcat</h1>
}
var scriptsMsg = "Scripts Used: " + scriptRange;
console.log(scriptsMsg);
$("body").append($("<p>" + scriptsMsg + "</p>"));
window.mobifyResults = create2dArray(scriptRange.length, runsPerTest);
@@ -140,6 +141,8 @@ <h1>Performance test for Jazzcat</h1>
});
var mobifyResultsMsg = "Mobify results: " + averagedMobifyResults;
var nativeResultsMsg = "Native results: " + averagedNativeResults;
console.log(mobifyResultsMsg);
console.log(nativeResultsMsg);
$("body").append($("<p>" + mobifyResultsMsg + "</p>"));
$("body").append($("<p>" + nativeResultsMsg + "</p>"));
});
View
@@ -4,23 +4,23 @@ var url = require('url');
var hbs = require('hbs');
var server = express();
var app = express();
server.set('views', __dirname + '/performance');
server.set('view engine', 'html');
server.engine('html', require('hbs').__express);
app.set('views', __dirname + '/performance');
app.set('view engine', 'html');
app.engine('html', require('hbs').__express);
hbs.registerPartial('bootstrap', fs.readFileSync(__dirname + '/tag/bootstrap.html', 'utf8'));
// global controller
server.get('/*',function(req,res,next){
app.get('/*',function(req,res,next){
res.header('Cache-Control' , 'max-age=0, no-cache, no-store');
next(); // http://expressjs.com/guide.html#passing-route control
});
// Used for test "capture captures the complete document"
// in tests/capture.html
server.get('/tests/fixtures/split.html', function(req, res){
app.get('/tests/fixtures/split.html', function(req, res){
var split = fs.readFileSync(__dirname + req.path, 'utf8').split('<!-- SPLIT -->')
res.writeHead(200, {'Content-Type': 'text/html'});
@@ -32,10 +32,11 @@ server.get('/tests/fixtures/split.html', function(req, res){
}, 5000);
});
server.get('/performance/jazzcat/', function(req, res, next) {
app.get('/performance/jazzcat/', function(req, res, next) {
res.render('jazzcat', {});
});
// Start loading scripts from disk to be used in mock requests
var resourcesUrl = '/mobifyjs/performance/resources/samplescripts/';
var files = fs.readdirSync(__dirname + resourcesUrl).filter(function(folder){
@@ -54,8 +55,11 @@ for (file in files) {
scriptsObj[resourcesUrl + fileName] = fileData;
}
}
// end script load
server.get('/performance/jazzcat/runner/:numScripts', function(req, res, next) {
// Jazzcat runner with varying # of scripts
app.get('/performance/jazzcat/runner/:numScripts', function(req, res, next) {
var numScripts = parseInt(req.params.numScripts);
var scripts = [];
for (var i=0; i<numScripts; i++) {
@@ -72,7 +76,7 @@ server.get('/performance/jazzcat/runner/:numScripts', function(req, res, next) {
// Mock Jazzcat jsonp call
server.get('/jsonp/Jazzcat.combo.load/:scripts', function(req, res, next) {
app.get('/jsonp/Jazzcat.combo.load/:scripts', function(req, res, next) {
var scripts = JSON.parse(req.params.scripts);
var scriptData = scripts.map(function(script){
var pathname = url.parse(script).pathname;
@@ -89,7 +93,7 @@ server.get('/jsonp/Jazzcat.combo.load/:scripts', function(req, res, next) {
});
// Mock Jazzcat js call
server.get('/js/Jazzcat.combo.load/:scripts', function(req, res, next) {
app.get('/js/Jazzcat.combo.load/:scripts', function(req, res, next) {
var scripts = JSON.parse(req.params.scripts);
var scriptData = scripts.map(function(script){
var pathname = url.parse(script).pathname;
@@ -102,6 +106,11 @@ server.get('/js/Jazzcat.combo.load/:scripts', function(req, res, next) {
})
});
if (!global.runningGrunt) server.listen(3000);
// When running server.js stand-alone (for running on Heroku)
if (!global.runningGrunt) {
// Grunt does this automatically.
app.use("/", express.static(__dirname));
app.listen(3000);
}
module.exports = server;
module.exports = app;

0 comments on commit cf35668

Please sign in to comment.