hostr/test/unit/image-resize.spec.js

36 lines
1,015 B
JavaScript
Raw Normal View History

2016-05-25 21:03:07 +01:00
import fs from 'mz/fs';
import { join } from 'path';
2015-07-09 23:01:43 +01:00
import assert from 'assert';
import tmp from 'tmp';
import resize from '../../lib/resize';
2016-05-25 21:03:07 +01:00
import sizeOf from 'image-size';
function testResize(path, done) {
const size = sizeOf(path);
resize(path, size.type, size, {width: 100, height: 100}).then((image) => {
const tmpFile = tmp.tmpNameSync() + '.' + size.type;
fs.writeFile(tmpFile, image).then(() => {
const newSize = sizeOf(fs.readFileSync(tmpFile));
assert(newSize.type === size.type);
done();
});
});
}
2015-07-09 23:01:43 +01:00
2016-05-24 21:33:09 +01:00
describe('Image resizing', () => {
2016-05-25 21:03:07 +01:00
it('should resize a jpg', (done) => {
const path = join(__dirname, '..', 'fixtures', 'utah-arches.jpg');
testResize(path, done);
2016-05-24 21:33:09 +01:00
});
2016-05-25 21:03:07 +01:00
it('should resize a png', (done) => {
const path = join(__dirname, '..', 'fixtures', 'app-icon.png');
testResize(path, done);
2016-05-24 21:33:09 +01:00
});
2015-07-09 23:01:43 +01:00
2016-05-25 21:03:07 +01:00
it('should resize a gif', (done) => {
const path = join(__dirname, '..', 'fixtures', 'kim.gif');
testResize(path, done);
2015-07-09 23:01:43 +01:00
});
});