Skip to content

Commit

Permalink
Require Node.js 10 (#30)
Browse files Browse the repository at this point in the history
* Require Node.js 10

* Use util.promisify
  • Loading branch information
1000ch authored May 24, 2020
1 parent 6bb71ff commit 707aeb3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ os:
- windows
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
- '6'
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
],
"engines": {
"node": ">=6"
"node": ">=10"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -44,9 +44,8 @@
"is-cwebp-readable": "^3.0.0"
},
"devDependencies": {
"ava": "^0.25.0",
"ava": "^3.8.0",
"is-webp": "^1.0.0",
"pify": "^4.0.0",
"xo": "^0.23.0"
"xo": "^0.30.0"
}
}
22 changes: 11 additions & 11 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import fs from 'fs';
import path from 'path';
import isWebP from 'is-webp';
import pify from 'pify';
import test from 'ava';
import imageminWebp from '.';
const {promisify} = require('util');
const fs = require('fs');
const path = require('path');
const isWebP = require('is-webp');
const test = require('ava');
const imageminWebp = require('.');

const fsP = pify(fs);
const readFile = promisify(fs.readFile);

test('convert an image into a WebP', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixtures/test.png'));
const buf = await readFile(path.join(__dirname, 'fixtures/test.png'));
const data = await imageminWebp()(buf);

t.true(data.length < buf.length);
t.true(isWebP(data));
});

test('skip optimizing unsupported files', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixtures/test-unsupported.bmp'));
const buf = await readFile(path.join(__dirname, 'fixtures/test-unsupported.bmp'));
const data = await imageminWebp()(buf);

t.deepEqual(data, buf);
});

test('throw error when an image is corrupt', async t => {
const buf = await fsP.readFile(path.join(__dirname, 'fixtures/test-corrupt.webp'));
await t.throws(imageminWebp()(buf), /BITSTREAM_ERROR/);
const buf = await readFile(path.join(__dirname, 'fixtures/test-corrupt.webp'));
await t.throwsAsync(() => imageminWebp()(buf), {message: /BITSTREAM_ERROR/});
});

0 comments on commit 707aeb3

Please sign in to comment.