blob: 95754be194d1d8d8ad7c7e327210e91f0f49582e [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2const fs = require('fs');
3const path = require('path');
4const test = require('ava');
5const execa = require('execa');
6const tempy = require('tempy');
7const binCheck = require('bin-check');
8const binBuild = require('bin-build');
9const compareSize = require('compare-size');
10const jpegtran = require('..');
11
12test('rebuild the jpegtran binaries', async t => {
13 const tmp = tempy.directory();
14 const cfg = [
15 './configure --disable-shared',
16 `--prefix="${tmp}" --bindir="${tmp}"`
17 ].join(' ');
18
19 await binBuild.url('https://downloads.sourceforge.net/project/libjpeg-turbo/1.5.1/libjpeg-turbo-1.5.1.tar.gz', [
20 cfg,
21 'make install'
22 ]);
23
24 t.true(fs.existsSync(path.join(tmp, 'jpegtran')));
25});
26
27test('return path to binary and verify that it is working', async t => {
28 t.true(await binCheck(jpegtran, ['-version']));
29});
30
31test('minify a JPG', async t => {
32 const tmp = tempy.directory();
33 const src = path.join(__dirname, 'fixtures/test.jpg');
34 const dest = path.join(tmp, 'test.jpg');
35 const args = [
36 '-outfile',
37 dest,
38 src
39 ];
40
41 await execa(jpegtran, args);
42 const res = await compareSize(src, dest);
43
44 t.true(res[dest] < res[src]);
45});