Skip to content

Commit

Permalink
Bump AVA version and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevva committed Apr 29, 2016
1 parent f5caafd commit fe10660
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 54 deletions.
File renamed without changes
File renamed without changes
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"node": ">=4"
},
"scripts": {
"test": "node test/test.js"
"test": "ava"
},
"files": [
"index.js"
Expand All @@ -46,8 +46,8 @@
"jpeg-recompress-bin": "^3.0.1"
},
"devDependencies": {
"ava": "^0.0.4",
"buffer-equal": "^0.0.1",
"is-progressive": "^1.0.1"
"ava": "*",
"is-progressive": "^1.0.1",
"pify": "^2.3.0"
}
}
37 changes: 37 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import fs from 'fs';
import path from 'path';
import isJpg from 'is-jpg';
import isProgressive from 'is-progressive';
import pify from 'pify';
import test from 'ava';
import m from './';

const fsP = pify(fs);

test('optimize a JPG', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixture.jpg'));
const data = await m()(buf);

t.true(data.length < buf.length);
t.true(isJpg(data));
t.true(isProgressive.buffer(data));
});

test('support jpeg-recompress options', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixture.jpg'));
const data = await m({progressive: false})(buf);

t.false(isProgressive.buffer(data));
});

test('skip optimizing a non-JPG file', async t => {
const buf = await fsP.readFile(__filename);
const data = await m()(buf);

t.deepEqual(data, buf);
});

test('throw error when a JPG is corrupt', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixture-corrupt.jpg'));
t.throws(m()(buf), /Corrupt JPEG data/);
});
50 changes: 0 additions & 50 deletions test/test.js

This file was deleted.

0 comments on commit fe10660

Please sign in to comment.