Browse Source

add helper function to execute test and only fire callback once

Fixes https://github.com/Automattic/node-canvas/issues/645
v1.x
Hussein Jafferjee 9 years ago
parent
commit
abee0947e5
  1. 21
      test/server.js

21
test/server.js

@ -37,6 +37,15 @@ function testFn(req){
return eval('(' + req.body.fn + ')');
}
function executeTestFn(ctx, fn, done) {
if(2 === fn.length) {
fn(ctx, done);
} else {
fn(ctx);
done();
}
}
function createCanvas(req, type){
var width = req.body.width
, height = req.body.height;
@ -56,9 +65,7 @@ app.post('/render', function(req, res, next){
});
}
2 == fn.length
? fn(ctx, done)
: fn(ctx), done();
executeTestFn(ctx, fn, done);
});
app.post('/pdf', function(req, res, next){
@ -73,9 +80,7 @@ app.post('/pdf', function(req, res, next){
res.end();
}
2 == fn.length
? fn(ctx, done)
: fn(ctx), done();
executeTestFn(ctx, fn, done);
});
app.post('/jpeg', function(req, res, next){
@ -94,9 +99,7 @@ app.post('/jpeg', function(req, res, next){
});
}
2 == fn.length
? fn(ctx, done)
: fn(ctx), done();
executeTestFn(ctx, fn, done);
});
var port = parseInt(process.argv[2] || '4000', 10);

Loading…
Cancel
Save