forked from imagemin/imagemin-pngquant
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
39 lines (31 loc) · 936 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import fs from 'fs';
import path from 'path';
import isPng from 'is-png';
import pify from 'pify';
import test from 'ava';
import m from './';
const fsP = pify(fs);
test('optimize a PNG', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixture.png'));
const data = await m()(buf);
t.true(data.length < buf.length);
t.true(isPng(data));
});
test('support pngquant options', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixture.png'));
const data = await m({
speed: 10,
quality: 100
})(buf);
t.true(data.length > 30000);
t.true(isPng(data));
});
test('skip optimizing a non-PNG file', async t => {
const buf = await fsP.readFile(__filename);
const data = await m()(buf);
t.is(data.length, buf.length);
});
test('throw on corrupt image', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixture-corrupt.png'));
t.throws(m()(buf), /PNG file corrupted/);
});