-
Notifications
You must be signed in to change notification settings - Fork 67
/
test.js
50 lines (42 loc) · 1.3 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 temporary = tempy.directory();
await binBuild.file(path.resolve(__dirname, '../vendor/source/optipng.tar.gz'), [
`./configure --with-system-zlib --prefix="${temporary}" --bindir="${temporary}"`,
'make install'
]);
t.true(fs.existsSync(path.join(temporary, '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 temporary = tempy.directory();
const sourcePath = path.join(__dirname, 'fixtures/test.png');
const destinationPath = path.join(temporary, 'test.png');
const arguments_ = [
'-strip',
'all',
'-clobber',
'-out',
destinationPath,
sourcePath
];
await execa(optipng, arguments_);
const result = await compareSize(sourcePath, destinationPath);
t.true(result[destinationPath] < result[sourcePath]);
});