forked from imagemin/imagemin-optipng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
65 lines (52 loc) · 1.87 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const fs = require('fs');
const path = require('path');
const isPng = require('is-png');
const test = require('ava');
const optipng = require('.');
const fixture = fs.readFileSync(path.join(__dirname, 'fixture.png'));
const fixtureBroken = fs.readFileSync(path.join(__dirname, 'fixture_broken.png'));
test('optimize a PNG', async t => {
const data = await optipng()(fixture);
t.true(data.length < fixture.length);
t.true(isPng(data));
});
test('throw on empty input', async t => {
await t.throwsAsync(optipng()(), {message: /Expected a buffer/});
});
test('bitDepthReduction option', async t => {
await t.notThrowsAsync(optipng({bitDepthReduction: true})(fixture));
});
test('colorTypeReduction option', async t => {
await t.notThrowsAsync(optipng({colorTypeReduction: true})(fixture));
});
test('paletteReduction option', async t => {
await t.notThrowsAsync(optipng({paletteReduction: true})(fixture));
});
test('errorRecovery default', async t => {
const data = await optipng()(fixtureBroken);
t.true(isPng(data));
});
test('errorRecovery explicit', async t => {
const data = await optipng({errorRecovery: true})(fixtureBroken);
t.true(isPng(data));
});
test('errorRecovery is set to false', async t => {
await t.throwsAsync(optipng({errorRecovery: false})(fixtureBroken));
});
test('interlaced is set to true', async t => {
const [data1, data2] = await Promise.all([
optipng({interlaced: true})(fixture),
optipng()(fixture)
]);
t.true(isPng(data1));
t.true(data1.length > data2.length);
});
test('interlaced is set to undefined and null', async t => {
const [data1, data2, data3] = await Promise.all([
optipng({interlaced: undefined})(fixture),
optipng({interlaced: null})(fixture),
optipng({interlaced: true})(fixture)
]);
t.true(isPng(data1) && isPng(data2));
t.true(data1.length === data2.length && data1.length < data3.length);
});