Skip to content

Commit

Permalink
Various tweaks (#8)
Browse files Browse the repository at this point in the history
Use ava instead of mocha, meta tweaks.
  • Loading branch information
Shogo Sensui committed Mar 31, 2017
1 parent 401b5b8 commit 9661829
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 42 deletions.
2 changes: 1 addition & 1 deletion license
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) imagemin
Copyright (c) Imagemin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
11 changes: 6 additions & 5 deletions package.json
Expand Up @@ -33,14 +33,15 @@
},
"scripts": {
"postinstall": "node lib/install.js",
"test": "xo && mocha"
"test": "xo && ava"
},
"files": [
"cli.js",
"index.js",
"lib"
],
"keywords": [
"imagemin",
"compress",
"image",
"img",
Expand All @@ -51,16 +52,16 @@
"zopflipng"
],
"dependencies": {
"bin-build": "^2.0.0",
"bin-build": "^2.2.0",
"bin-wrapper": "^3.0.0",
"logalot": "^2.0.0"
},
"devDependencies": {
"ava": "*",
"bin-check": "^4.0.1",
"compare-size": "^3.0.0",
"mkdirp": "^0.5.0",
"mocha": "^3.2.0",
"rimraf": "^2.3.2",
"execa": "^0.6.3",
"tempy": "^0.1.0",
"xo": "*"
}
}
8 changes: 5 additions & 3 deletions readme.md
@@ -1,6 +1,8 @@
# zopflipng-bin [![Build Status](https://travis-ci.org/imagemin/zopflipng-bin.svg?branch=master)](https://travis-ci.org/imagemin/zopflipng-bin)

> zopfli Compression Algorithm is a new zlib (gzip, deflate) compatible compressor that takes more time (~100x slower), but compresses around 5% better than zlib and better than any other zlib-compatible compressor
> [zopfli](https://github.com/google/zopfli) Compression Algorithm is a new zlib (gzip, deflate) compatible compressor that takes more time (~100x slower), but compresses around 5% better than zlib and better than any other zlib-compatible compressor
You probably want [`imagemin-zopfli`](https://github.com/imagemin/imagemin-zopfli) instead.


## Install
Expand All @@ -13,7 +15,7 @@ $ npm install --save zopflipng-bin
## Usage

```js
const execFile = require('child_process').execFile;
const {execFile} = require('child_process');
const zopflipng = require('zopflipng-bin');

execFile(zopflipng, ['-m', '--lossy_8bit', 'input.png', 'outout.png'], () => {
Expand All @@ -35,4 +37,4 @@ $ zopflipng --help

## License

MIT © [imagemin](https://github.com/imagemin)
MIT © [Imagemin](https://github.com/imagemin)
48 changes: 15 additions & 33 deletions test/test.js
@@ -1,47 +1,33 @@
/* eslint-env mocha */
/* eslint-disable promise/no-promise-in-callback, promise/no-callback-in-promise */
'use strict';
const assert = require('assert');
const execFile = require('child_process').execFile;
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 mkdirp = require('mkdirp');
const rimraf = require('rimraf');

const tmp = path.join(__dirname, 'tmp');

beforeEach(cb => {
mkdirp(tmp, cb);
});

afterEach(cb => {
rimraf(tmp, {disableGlob: true}, cb);
});

it('rebuild the zopflipng binaries', function (cb) {
this.timeout(50000);
test.cb('rebuild the zopflipng binaries', t => {
const tmp = tempy.directory();

new BinBuild()
.src('https://github.com/google/zopfli/archive/a29e46ba9f268ab273903558dcb7ac13b9fe8e29.zip')
.cmd(`mkdir -p ${tmp}`)
.cmd(`make zopflipng && mv ./zopflipng ${path.join(tmp, 'zopflipng')}`)
.run(err => {
assert(!err);
assert(fs.statSync(path.join(tmp, 'zopflipng')).isFile());
cb();
t.ifError(err);
t.true(fs.existsSync(path.join(tmp, 'zopflipng')));
t.end();
});
});

it('return path to binary and verify that it is working', () => {
return binCheck(require('../'), ['--help']).then(works => {
assert(works);
});
test('return path to binary and verify that it is working', async t => {
t.true(await binCheck(require('../'), ['--help']));
});

it('minify a PNG', cb => {
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 = [
Expand All @@ -50,12 +36,8 @@ it('minify a PNG', cb => {
dest
];

execFile(require('../'), args, err => {
assert(!err);
await execa(require('../'), args);
const res = await compareSize(src, dest);

compareSize(src, dest).then(res => {
assert(res[dest] < res[src]);
cb();
}).catch(cb);
});
t.true(res[dest] < res[src]);
});

0 comments on commit 9661829

Please sign in to comment.