Skip to content

Commit

Permalink
tests; windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
aheckmann committed Sep 21, 2022
1 parent 01e4217 commit bc19461
Show file tree
Hide file tree
Showing 48 changed files with 211 additions and 236 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [windows-latest, ubuntu-latest]
node-version: [14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

Expand Down
4 changes: 2 additions & 2 deletions test/109.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const fs = require('fs');
const path = require('path');

module.exports = function (_, dir, finish, gm) {
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration) return finish();

const original = path.join(dir, 'original.jpg');
const buf = fs.readFileSync(original);
const m = gm(buf, 'original.jpg');
const m = gm(buf, 'original.jpg').options({ imageMagick });

m.identify(function (err, _) {
finish(err);
Expand Down
6 changes: 3 additions & 3 deletions test/118.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
const assert = require('assert')
const path = require('path');

module.exports = function (_, dir, finish, gm) {
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration) return finish();

var src = path.join(dir, 'originalSideways.jpg');
var dst = path.join(dir, 'originalSideways10x.jpg');

gm(src).resize(10).write(dst, function(err) {
gm(dst).size(function(err, size) {
gm(src).options({ imageMagick }).resize(10).write(dst, function(err) {
gm(dst).options({ imageMagick }).size(function(err, size) {
if (err) return finish(err);
assert.equal(10, size.width);
finish();
Expand Down
7 changes: 3 additions & 4 deletions test/393.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

module.exports = function (_, dir, finish, gm) {
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration) return finish();

var imagePath = path.join(__dirname, './fixtures', 'nyancat.gif');
var imagePath = path.join(__dirname, 'fixtures', 'nyancat.gif');
var inputStream = fs.createReadStream(imagePath);
gm(inputStream)
.identify({ bufferStream: true }, function(err, value) {
gm(inputStream).options({ imageMagick }).identify({ bufferStream: true }, function(err, value) {
if (err) return finish(err);
var size = value.size;
assert.equal(400, size.width);
Expand Down
28 changes: 12 additions & 16 deletions test/417.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,27 @@ const assert = require('assert')
const fs = require('fs');
const path = require('path');

module.exports = function (_, dir, finish, gm) {
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration)
return finish();

const originalPathName = path.join(dir, 'original.jpg');
const thumbPathName = path.join(dir, 'thumb.png');

gm(originalPathName)
.thumb(150, 40, thumbPathName, function thumb (err) {
gm(thumbPathName)
.size(function (err, size) {
if (err) return finish(err);
gm(originalPathName).options({ imageMagick }).thumb(150, 40, thumbPathName, function thumb (err) {
gm(thumbPathName).options({ imageMagick }).size(function (err, size) {
if (err) return finish(err);

assert.equal(142, size.width);
assert.equal(40, size.height);
assert.equal(142, size.width);
assert.equal(40, size.height);

gm(originalPathName)
.thumbExact(150, 40, thumbPathName, function thumb (err) {
gm(thumbPathName)
.size(function (err, size) {
assert.equal(150, size.width);
assert.equal(40, size.height);
finish(err);
});
gm(originalPathName).options({ imageMagick }).thumbExact(150, 40, thumbPathName, function thumb (err) {
gm(thumbPathName).options({ imageMagick }).size(function (err, size) {
assert.equal(150, size.width);
assert.equal(40, size.height);
finish(err);
});
});
});
});
}
17 changes: 11 additions & 6 deletions test/422.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const fs = require('fs');
const path = require('path');

module.exports = function (gm, dir, finish, GM) {
module.exports = function (gm, dir, finish, GM, imageMagick) {
// Same image
const originalPathName = path.join(dir, 'original.jpg');

GM.compare(originalPathName, originalPathName, function(err, same) {
gm.compare(originalPathName, originalPathName, function(err, same, diff) {
if (err) return finish(err);
if (!same) return finish(new Error('Compare should be the same!'));
if (!same) {
const msg = `Compare should be the same! "${same}" "${diff}"`;
return finish(new Error(msg));
}

// Compare almost similar images for which ImageMagick
// returns an exponent-style floating point number
Expand All @@ -16,7 +19,10 @@ module.exports = function (gm, dir, finish, GM) {

gm.compare(compare1PathName, compare2PathName, function(err, same, diff) {
if (err) return finish(err);
if (!same) return finish(new Error('Compare should be the same!'));
if (!same) {
const msg = `Compare should be the same! "${same}" "${diff}"`;
return finish(new Error(msg));
}

const noisePathName = path.join(dir, 'noise3.png');

Expand All @@ -26,15 +32,14 @@ module.exports = function (gm, dir, finish, GM) {

var options = {
highlightColor: '#fff',
highlightStyle: 'XOR',
file: path.join(dir, 'diff.png'),
tolerance: 0.001
};

const originalPathName = path.join(dir, 'original.jpg');

// Compare these images and write to a file.
GM.compare(originalPathName, noisePathName, options, function(err) {
gm.compare(originalPathName, noisePathName, options, function(err) {
if (err) return finish(err);

fs.access(options.file, fs.constants.F_OK, function(err) {
Expand Down
9 changes: 4 additions & 5 deletions test/429.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
const assert = require('assert');
const fs = require('fs');
const path = require('path');

module.exports = function (gm, dir, finish, GM) {
module.exports = function (gm, dir, finish, GM, imageMagick) {
if (!GM.integration) return finish();

const ico = path.join(__dirname, 'fixtures', 'test.ico');
const buffer = fs.readFileSync(ico);
const stream = fs.createReadStream(ico);

GM(ico).size(function (err, size) {
GM(ico).options({ imageMagick }).size(function (err) {
if (err) {
err.message = 'Failed using ico filename. ' + err.message;
return finish(err);
}

GM(buffer, 'img.ico').size(function (err, size) {
GM(buffer, 'img.ico').options({ imageMagick }).size(function (err) {
if (err) {
err.message = 'Failed using ico buffer. ' + err.message;
return finish(err);
}

GM(stream, 'img.ico').size({bufferStream: true}, function (err, size) {
GM(stream, 'img.ico').options({ imageMagick }).size({bufferStream: true}, function (err) {
if (err) {
err.message = 'Failed using ico stream. ' + err.message;
return finish(err);
Expand Down
5 changes: 2 additions & 3 deletions test/70.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var times = 16;
var loading = path.join(__dirname, 'fixtures', 'loading.gif');
var favicon = path.join(__dirname, 'fixtures', 'favicon.png');

module.exports = function (_, dir, finish, gm) {
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration) return finish();

var pending = times/2;
Expand All @@ -24,8 +24,7 @@ module.exports = function (_, dir, finish, gm) {

new Array(times).join('x').split('x').forEach(function (_, i) {
;[loading, favicon].forEach(function (img) {
gm(img)
.size(function edge (err, size) {
gm(img).options({imageMagick}).size(function (err, size) {
if (err) return done(err);

'width height'.split(' ').forEach(function (prop) {
Expand Down
10 changes: 5 additions & 5 deletions test/alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require('assert');
const Async = require('async');
const path = require('path');

module.exports = function (_, dir, finish, gm, im) {
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration) return finish();

var alphaTypes = [
Expand All @@ -19,11 +19,11 @@ module.exports = function (_, dir, finish, gm, im) {
"Background"
];

const edgePath = path.join(dir, 'edge.png');
const edgePath = path.join(dir, 'original.png');
const failPath = path.join(dir, 'alpha_fail.png');

// alpha not supported by GM so only test IM
if (!im) {
if (!imageMagick) {
assert.throws(function() {
gm(edgePath)
.alpha(alphaTypes.pop())
Expand All @@ -32,8 +32,8 @@ module.exports = function (_, dir, finish, gm, im) {
finish();
} else {

Async.eachSeries(alphaTypes, function(alphaType,cb) {
var m = gm(edgePath).options({imageMagick: im}).alpha( alphaType );
Async.eachSeries(alphaTypes, function(alphaType, cb) {
var m = gm(edgePath).options({imageMagick}).alpha( alphaType );
var args = m.args();
assert.equal('convert', args[0]);
assert.equal('-alpha', args[2]);
Expand Down
20 changes: 11 additions & 9 deletions test/append.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const assert = require('assert')
const path = require('path');

module.exports = function (_, dir, finish, gm) {
module.exports = function (_, dir, finish, gm, imageMagick) {
const out = path.resolve(dir, 'append.jpg');
const lostPath = path.join(dir, 'lost.png');
const originalPath = path.join(dir, 'original.jpg');
Expand All @@ -11,6 +11,7 @@ module.exports = function (_, dir, finish, gm) {
} catch (_) {}

var m = gm(lostPath)
.options({imageMagick})
.append(originalPath, originalPath)
.append()
.background('#222')
Expand All @@ -26,25 +27,27 @@ module.exports = function (_, dir, finish, gm) {
assert.equal('-',args[7]);

if (!gm.integration) {
return horizontal({ dir, finish, gm, originalPath, lostPath });
return horizontal({ dir, finish, gm, originalPath, lostPath, imageMagick });
}

m.write(out, function (err) {
if (err) return finish(err);
gm(out).size(function (err, size) {
gm(out)
.options({imageMagick})
.size(function (err, size) {
if (err) return finish(err);
assert.equal(460, size.width);
assert.equal(435, size.height);

horizontal({ dir, finish, gm, originalPath, lostPath });
horizontal({ dir, finish, gm, originalPath, lostPath, imageMagick });
})
});
}

function horizontal ({ dir, finish, gm, originalPath, lostPath }) {
function horizontal ({ dir, finish, gm, originalPath, lostPath, imageMagick }) {
var out = path.resolve(dir, 'appendHorizontal.jpg');

var m = gm(originalPath).append(lostPath, true);
var m = gm(originalPath).append(lostPath, true).options({imageMagick});

var args = m.args();
assert.equal('convert', args[0]);
Expand All @@ -57,10 +60,9 @@ function horizontal ({ dir, finish, gm, originalPath, lostPath }) {
return finish();
}

m
.write(out, function (err) {
m.write(out, function (err) {
if (err) return finish(err);
gm(out).size(function (err, size) {
gm(out).options({imageMagick}).size(function (err, size) {
if (err) return finish(err);
assert.equal(697, size.width);
assert.equal(155, size.height);
Expand Down
17 changes: 12 additions & 5 deletions test/autoOrient.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
const assert = require('assert');
const path = require('path');

module.exports = function (_, dir, finish, gm) {
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration)
return finish();

const sidewaysPath = path.join(dir, 'originalSideways.jpg');

gm(sidewaysPath).identify(function (err, o) {
gm(sidewaysPath)
.options({imageMagick})
.identify(function (err, o) {
if (err) return finish(err);

assert.equal('155x460', o.Geometry);
const geo = imageMagick ? '155x460+0+0' : '155x460';
assert.equal(geo, o.Geometry);

// this image is sideways, but may be auto-oriented by modern OS's
// try opening it in a browser to see its true orientation
gm(sidewaysPath)
.options({imageMagick})
.autoOrient()
.stream(function (err, stream) {
if (err) return finish(err);

gm(stream).identify(function (err, data) {
gm(stream)
.options({imageMagick})
.identify(function (err, data) {
if (err) return finish(err);

assert.equal('460x155', data.Geometry);
const geo2 = imageMagick ? '460x155+0+0' : '460x155';
assert.equal(geo2, data.Geometry);
finish(err);
})
})
Expand Down
12 changes: 7 additions & 5 deletions test/autoOrientAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require('assert');
const fs = require('fs');
const path = require('path');

module.exports = function (_, dir, finish, gm) {
module.exports = function (_, dir, finish, gm, imageMagick) {
if (!gm.integration) return finish();

var beforeValues = {
Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = function (_, dir, finish, gm) {
const newFilename = fileToAutoOrient + '.oriented.jpg';
const constant = fileToAutoOrient + '.correct.jpg';

gm(fileToAutoOrient).orientation(function (err, o) {
gm(fileToAutoOrient).options({imageMagick}).orientation(function (err, o) {
if (err) return finish(err);

assert.equal(beforeValues[filename][0], o);
Expand All @@ -74,18 +74,20 @@ module.exports = function (_, dir, finish, gm) {
// this image is sideways, but may be auto-oriented by modern OS's
// try opening it in a browser to see its true orientation
gm(fileToAutoOrient)
.options({ imageMagick })
.autoOrient()
.write(newFilename, function autoOrient (err) {
if (err) return finish(err);

// fs race condition
setTimeout(function () {
gm(newFilename).identify(function (err) {
gm(newFilename).options({ imageMagick }).identify(function (err) {
if (err) return finish(err);

assert.equal(afterValues[filename], this.data.Geometry, 'Bad-Geometry for ' + filename);
const afterValue = imageMagick ? `${afterValues[filename]}+0+0` : afterValues[filename];
assert.equal(afterValue, this.data.Geometry, `Bad-Geometry for ${filename}. Got "${this.data.Geometry}"`);

gm.compare(newFilename, constant, 0.1, function (err, equal) {
gm().options({imageMagick}).compare(newFilename, constant, 0.1, function (err, equal) {
if (err) return finish(err);
assert.ok(equal);
next();
Expand Down
Loading

0 comments on commit bc19461

Please sign in to comment.