-
Notifications
You must be signed in to change notification settings - Fork 67
/
test.js
50 lines (42 loc) · 1.18 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
'use strict';
const fs = require('fs');
const path = require('path');
const test = require('ava');
const execa = require('execa');
const tempy = require('tempy');
const binCheck = require('bin-check');
const binBuild = require('bin-build');
const compareSize = require('compare-size');
const optipng = require('..');
test('rebuild the optipng binaries', async t => {
// Skip the test on Windows
if (process.platform === 'win32') {
t.pass();
return;
}
const tmp = tempy.directory();
await binBuild.file(path.resolve(__dirname, '../vendor/source/optipng.tar.gz'), [
`./configure --with-system-zlib --prefix="${tmp}" --bindir="${tmp}"`,
'make install'
]);
t.true(fs.existsSync(path.join(tmp, 'optipng')));
});
test('return path to binary and verify that it is working', async t => {
t.true(await binCheck(optipng, ['--version']));
});
test('minify a PNG', async t => {
const tmp = tempy.directory();
const src = path.join(__dirname, 'fixtures/test.png');
const dest = path.join(tmp, 'test.png');
const args = [
'-strip',
'all',
'-clobber',
'-out',
dest,
src
];
await execa(optipng, args);
const res = await compareSize(src, dest);
t.true(res[dest] < res[src]);
});