Updated tests to use finish consistently

Refactored tests to use async queue methods
Added alpha method #374
master
Rowan Wookey 9 years ago
parent e98c5d4efe
commit bb17cf14cf
  1. 5
      lib/args.js
  2. 10
      test/78.js
  3. 42
      test/alpha.js
  4. 20
      test/append.js
  5. 1
      test/geometry.js
  6. 24
      test/index.js
  7. 3
      test/streamerr.js

@ -33,6 +33,11 @@ module.exports = function (proto) {
return this.out("-affine", matrix); return this.out("-affine", matrix);
} }
proto.alpha = function alpha (type) {
if (!this._options.imageMagick) return new Error('Method -alpha is not supported by GraphicsMagick');
return this.out('-alpha', type);
}
/** /**
* Appends images to the list of "source" images. * Appends images to the list of "source" images.
* *

@ -1,15 +1,15 @@
var assert = require('assert') var assert = require('assert')
module.exports = function (_, dir, next, gm) { module.exports = function (_, dir, finish, gm) {
if (!gm.integration) return next(); if (!gm.integration) return finish();
var magick = _._options.imageMagick; var magick = _._options.imageMagick;
var name = magick ? '78-IM' : '78'; var name = magick ? '78-IM' : '78';
var out = dir + '/' + name; var out = dir + '/' + name;
_.resize(600, 450, '!').write(out + '.png', function (err) { _.resize(600, 450, '!').write(out + '.png', function (err) {
if (err) return next(err); if (err) return finish(err);
var img = gm(out + '.png'); var img = gm(out + '.png');
if (magick) if (magick)
@ -19,8 +19,8 @@ module.exports = function (_, dir, next, gm) {
.crop(70, 70, 100, 100) .crop(70, 70, 100, 100)
.resize(50, 50) .resize(50, 50)
.write(out + '-2.jpg', function (err) { .write(out + '-2.jpg', function (err) {
if (err) return next(err); if (err) return finish(err);
next(); finish();
}) })
}); });

@ -0,0 +1,42 @@
var assert = require('assert');
var async = require('async');
module.exports = function (_, dir, finish, gm, im) {
if (!gm.integration) return finish();
var alphaTypes = [
"Activate",
"On",
"Deactivate",
"Off",
"Set",
"Opaque",
"Transparent",
"Extract",
"Copy",
"Shape",
"Remove",
"Background"
];
// alpha not supported by GM so only test IM
if (!im) {
assert.throws(function() {
gm(dir + '/edge.png')
.alpha( alphaTypes.pop() ).write(dir+'/alpha_fail.png');
});
finish();
} else {
async.eachSeries(alphaTypes,function(alphaType,cb) {
var m = gm(dir + '/edge.png').options({imageMagick: im}).alpha( alphaType );
var args = m.args();
assert.equal('convert', args[0]);
assert.equal('-alpha', args[2]);
assert.equal(alphaType, args[3]);
m.write( dir + '/alpha_' + alphaType + '.png', cb);
},finish);
}
}

@ -1,6 +1,6 @@
var assert = require('assert') var assert = require('assert')
module.exports = function (_, dir, next, gm) { module.exports = function (_, dir, finish, gm) {
var out = require('path').resolve(dir + '/append.jpg'); var out = require('path').resolve(dir + '/append.jpg');
try { try {
@ -23,22 +23,22 @@ module.exports = function (_, dir, next, gm) {
assert.equal('-',args[7]); assert.equal('-',args[7]);
if (!gm.integration) { if (!gm.integration) {
return horizontal(dir, next, gm); return horizontal(dir, finish, gm);
} }
m.write(out, function (err) { m.write(out, function (err) {
if (err) return next(err); if (err) return finish(err);
gm(out).size(function (err, size) { gm(out).size(function (err, size) {
if (err) return next(err); if (err) return finish(err);
assert.equal(460, size.width); assert.equal(460, size.width);
assert.equal(435, size.height); assert.equal(435, size.height);
horizontal(dir, next, gm); horizontal(dir, finish, gm);
}) })
}); });
} }
function horizontal (dir, next, gm) { function horizontal (dir, finish, gm) {
var out = require('path').resolve(dir + '/appendHorizontal.jpg'); var out = require('path').resolve(dir + '/appendHorizontal.jpg');
var m = gm(dir + '/original.jpg') var m = gm(dir + '/original.jpg')
@ -52,18 +52,18 @@ function horizontal (dir, next, gm) {
assert.equal('-',args[4]); assert.equal('-',args[4]);
if (!gm.integration) { if (!gm.integration) {
return next(); return finish();
} }
m m
.write(out, function (err) { .write(out, function (err) {
if (err) return next(err); if (err) return finish(err);
gm(out).size(function (err, size) { gm(out).size(function (err, size) {
if (err) return next(err); if (err) return finish(err);
assert.equal(697, size.width); assert.equal(697, size.width);
assert.equal(155, size.height); assert.equal(155, size.height);
next(); finish();
}) })
}); });

@ -12,6 +12,5 @@ module.exports = function (gm, dir, finish, GM) {
assert.equal('-geometry', args[2]); assert.equal('-geometry', args[2]);
assert.equal('x100', args[3]); // Keep-aspect-ratio command assert.equal('x100', args[3]); // Keep-aspect-ratio command
if (!GM.integration)
return finish(); return finish();
} }

@ -13,7 +13,6 @@ gm.integration = !! ~process.argv.indexOf('--integration');
if (gm.integration) only.shift(); if (gm.integration) only.shift();
var files = fs.readdirSync(__dirname).filter(filter); var files = fs.readdirSync(__dirname).filter(filter);
var pending, total = pending = files.length * 2;
function filter (file) { function filter (file) {
if (!/\.js$/.test(file)) return false; if (!/\.js$/.test(file)) return false;
@ -38,18 +37,9 @@ function finish (filename) {
throw err; throw err;
} }
--pending;
process.stdout.write('\033[2K'); process.stdout.write('\033[2K');
process.stdout.write('\033[0G'); process.stdout.write('\033[0G');
process.stdout.write('pending ' + pending); process.stdout.write('pending ' + (q.length()+q.running()));
if (pending) return;
process.stdout.write('\033[?25h');
process.stdout.write('\033[2K');
process.stdout.write('\033[0G');
var leaks = gleak.detect();
assert.equal(0, leaks.length, "global leaks detected: " + leaks);
console.error("\n\u001B[32mAll tests passed\u001B[0m");
} }
} }
@ -63,7 +53,17 @@ var q = async.queue(function (task, callback) {
finish(filename)(err); finish(filename)(err);
callback(); callback();
}, gm, im); }, gm, im);
}, 5); }, 10);
q.drain = function(){
process.stdout.write('\033[?25h');
process.stdout.write('\033[2K');
process.stdout.write('\033[0G');
var leaks = gleak.detect();
assert.equal(0, leaks.length, "global leaks detected: " + leaks);
console.error("\n\u001B[32mAll tests passed\u001B[0m");
};
files = files.map(function (file) { files = files.map(function (file) {
return __dirname + '/' + file return __dirname + '/' + file

@ -15,7 +15,6 @@ module.exports = function (_, dir, finish, gm) {
assert.ok(err, "Expecting error on this buffer"); assert.ok(err, "Expecting error on this buffer");
}); });
if (!gm.integration) return finish();
return finish();
} }

Loading…
Cancel
Save