Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocha tests #80

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -7,4 +7,10 @@
, "url" : "http://github.com/rsms/node-imagemagick.git" }
, "engine" : ["node >=0.6"]
, "main" : "imagemagick"
, "devDependencies": {
"mocha": ">= 1.8"
}
, "scripts": {
"test": "./node_modules/mocha/bin/mocha --reporter spec"
}
}
35 changes: 0 additions & 35 deletions test-crop.js

This file was deleted.

52 changes: 0 additions & 52 deletions test.js

This file was deleted.

File renamed without changes
53 changes: 53 additions & 0 deletions test/test-crop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
var fs = require('fs'),
im = require('../imagemagick'),
assert = require('assert');

var path = __dirname+'/fixtures/blue-bottle-coffee.jpg';

describe('crop()', function() {

it('(simple) should crop the image and not return an error', function (done) {
var opt;
var outFile = 'cropped.jpg';
im.crop(opt = {
srcPath: path,
dstPath: outFile,
width: 200,
height: 90,
quality: 1
}, function (err, stdout, stderr){
assert.ifError(err);
assert(fs.existsSync(outFile), "Output file exists");
assert(
fs.statSync(outFile).size >= 23,
"Output has a length of at least 23 bytes"
);
// console.log('crop(',opt,') ->', stdout, stderr);
done();
});
});

it('with "gravity: North" should crop the image and not return an error', function (done) {
var opt;
var outFile = 'cropped2.jpg';
im.crop(opt = {
srcPath: path,
dstPath: outFile,
width: 200,
height: 90,
gravity: "North",
quality: 1
}, function (err, stdout, stderr){
assert.ifError(err);
assert(fs.existsSync(outFile), "Output file exists");
assert(
fs.statSync(outFile).size >= 23,
"Output has a length of at least 23 bytes"
);
// console.log('crop(',opt,') ->', stdout, stderr);
done();
});
});

});

33 changes: 33 additions & 0 deletions test/test-identify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var fs = require('fs'),
im = require('../imagemagick'),
assert = require('assert');

var path = __dirname+'/fixtures/blue-bottle-coffee.jpg';
var imdata = fs.readFileSync(path, 'binary');


describe('identify()', function() {

it('should return info when called with image path', function(done) {
im.identify(path, function (err, features){
assert.ifError(err);
assert.strictEqual(features.format, 'JPEG');
assert.strictEqual(features.geometry, '640x480');
// console.log('identify(path) ->', features);
done();
});
});

it('should return info when called with object: {data: <raw image data>}', function(done) {
im.identify({data:imdata}, function (err, features){
if (err) return console.error(err.stack || err);
assert.ifError(err);
assert.strictEqual(features.format, 'JPEG');
assert.strictEqual(features.geometry, '640x480');
//console.log('identify({data:imdata}) ->', features);
done();
});
});

});

30 changes: 30 additions & 0 deletions test/test-readMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var fs = require('fs'),
im = require('../imagemagick'),
assert = require('assert');

var path = __dirname+'/fixtures/blue-bottle-coffee.jpg';
var imdata = fs.readFileSync(path, 'binary');


describe('readMetadata()', function() {

it('should return info when called with image path', function(done) {
im.readMetadata(path, function (err, metadata){
assert.ifError(err);
assert(metadata);
// console.log('readMetadata(path) ->', metadata);
done();
});
});

it('should return info when called with object: {data: <raw image data>}', function(done) {
im.readMetadata({data:imdata}, function (err, metadata){
assert.ifError(err);
assert(metadata);
// console.log('readMetadata({data:imdata} ->', metadata);
done();
});
});

});

43 changes: 43 additions & 0 deletions test/test-resize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var fs = require('fs'),
im = require('../imagemagick'),
assert = require('assert');

var path = __dirname+'/fixtures/blue-bottle-coffee.jpg';
var imdata = fs.readFileSync(path, 'binary');


describe('resize()', function() {

it('should resize the image (by file name) and not return an error', function (done) {
var outFile = 'test-resized.jpg';
im.resize({
srcPath: path,
dstPath: outFile,
width: 256
}, function (err, stdout, stderr){
assert.ifError(err);
// console.log('resize(...) wrote "test-resized.jpg"');
im.identify(['-format', '%b', outFile], function (err, r){
assert.ifError(err);
assert(r, "Identify should report the file size");
// console.log("identify(['-format', '%b', 'test-resized.jpg']) ->", r);
done();
});
});
});

it('should resize the image (using raw data) and not return an error', function (done) {
var outFile = 'test-resized-io.jpg';
im.resize({
srcData: imdata,
width: 256
}, function (err, stdout, stderr){
assert.ifError(err);
fs.writeFileSync(outFile, stdout, 'binary');
// console.log('resize(...) wrote "test-resized-io.jpg" ('+stdout.length+' Bytes)');
done();
});
});

});