forked from Gobie/gulp-imagemin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
46 lines (36 loc) · 1.2 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
import fs from 'fs';
import path from 'path';
import gutil from 'gulp-util';
import imageminPngquant from 'imagemin-pngquant';
import pify from 'pify';
import getStream from 'get-stream';
import test from 'ava';
import m from './';
const fsP = pify(fs);
const createFixture = async plugins => {
const buf = await fsP.readFile('fixture.png');
const stream = m(plugins);
stream.end(new gutil.File({
path: path.join(__dirname, 'fixture.png'),
contents: buf
}));
return {buf, stream};
};
test('minify images', async t => {
const {buf, stream} = await createFixture();
const file = await getStream.array(stream);
t.true(file[0].contents.length < buf.length);
});
test('use custom plugins', async t => {
const {stream} = await createFixture([imageminPngquant()]);
const compareStream = (await createFixture()).stream;
const file = await getStream.array(stream);
const compareFile = await getStream.array(compareStream);
t.true(file[0].contents.length < compareFile[0].contents.length);
});
test('skip unsupported images', async t => {
const stream = m();
stream.end(new gutil.File({path: path.join(__dirname, 'fixture.bmp')}));
const file = await getStream.array(stream);
t.is(file[0].contents, null);
});