-
Notifications
You must be signed in to change notification settings - Fork 95
/
test.js
50 lines (42 loc) · 1.32 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
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import {execa} from 'execa';
import {temporaryDirectory} from 'tempy';
import binCheck from 'bin-check';
import binBuild from 'bin-build';
import compareSize from 'compare-size';
import pngquant from './index.js';
test('rebuild the pngquant binaries', async t => {
// Skip the test on Windows
if (process.platform === 'win32') {
t.pass();
return;
}
const temporary = temporaryDirectory();
const source = fileURLToPath(new URL('vendor/source/pngquant.tar.gz', import.meta.url));
await binBuild.file(source, [
'rm ./INSTALL',
`./configure --prefix="${temporary}"`,
`make install BINPREFIX="${temporary}"`,
]);
t.true(fs.existsSync(path.join(temporary, 'pngquant')));
});
test('verify binary', async t => {
t.true(await binCheck(pngquant, ['--version']));
});
test('minify a png', async t => {
const temporary = temporaryDirectory();
const source = fileURLToPath(new URL('fixtures/test.png', import.meta.url));
const destination = path.join(temporary, 'test.png');
const arguments_ = [
'-o',
destination,
source,
];
await execa(pngquant, arguments_);
const result = await compareSize(source, destination);
t.true(result[destination] < result[source]);
});