Remove gm dependency and update tests.

This commit is contained in:
Jonathan Cremin 2016-05-24 21:33:09 +01:00
parent b1ceba7664
commit 75a46212da
8 changed files with 61 additions and 37 deletions

BIN
test/fixtures/app-icon.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

BIN
test/fixtures/kim.gif vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View file

@ -3,14 +3,33 @@ import path from 'path';
import assert from 'assert';
import tmp from 'tmp';
import resize from '../../lib/resize';
import imageType from 'image-type';
const file = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'utah-arches.jpg'));
describe('Image resizing', function() {
it('should resize an image', function*() {
describe('Image resizing', () => {
it('should resize a jpg', function* resizeImage() {
const file = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'utah-arches.jpg'));
const imageBuffer = yield resize(file, {height: 100, width: 100});
const tmpFile = tmp.tmpNameSync();
fs.writeFileSync(tmpFile + '.jpg', imageBuffer);
assert(tmpFile);
const tmpFile = tmp.tmpNameSync() + '.jpg';
fs.writeFileSync(tmpFile, imageBuffer);
const type = imageType(fs.readFileSync(tmpFile));
assert(type.ext === 'jpg');
});
it('should resize a png', function* resizeImage() {
const file = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'app-icon.png'));
const imageBuffer = yield resize(file, {height: 100, width: 100});
const tmpFile = tmp.tmpNameSync() + '.png';
fs.writeFileSync(tmpFile, imageBuffer);
const type = imageType(fs.readFileSync(tmpFile));
assert(type.ext === 'png');
});
it('should resize a gif', function* resizeImage() {
const file = fs.readFileSync(path.join(__dirname, '..', 'fixtures', 'kim.gif'));
const imageBuffer = yield resize(file, {height: 100, width: 100});
const tmpFile = tmp.tmpNameSync() + '.gif';
fs.writeFileSync(tmpFile, imageBuffer);
const type = imageType(fs.readFileSync(tmpFile));
assert(type.ext === 'gif');
});
});

View file

@ -1,5 +1,5 @@
import assert from 'assert';
import gm from 'gm';
import sizeOf from 'image-size';
import { agent } from 'supertest';
import app from '../../app';
@ -46,9 +46,7 @@ describe('hostr-web file', function() {
.expect(200)
.expect('Content-type', 'image/jpeg')
.expect(function(response) {
gm(response.body).size((err, size) => {
assert(size.width === 150);
});
assert(sizeOf(response.body).width === 150);
})
.end(done);
});
@ -61,9 +59,7 @@ describe('hostr-web file', function() {
.expect(200)
.expect('Content-type', 'image/jpeg')
.expect(function(response) {
gm(response.body).size((err, size) => {
assert(size.width === 970);
});
assert(sizeOf(response.body).width === 970);
})
.end(done);
});