From cc7904157d48814467b152a10778144f784f6bb6 Mon Sep 17 00:00:00 2001 From: 1000ch Date: Sun, 24 May 2020 17:35:45 +0900 Subject: [PATCH 1/2] Require Node.js 10 --- .travis.yml | 3 +-- package.json | 8 ++++---- test.js | 14 +++++++------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8a74f2e..a18175d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ os: - windows language: node_js node_js: + - '14' - '12' - '10' - - '8' - - '6' diff --git a/package.json b/package.json index 9cdef83..479dd3c 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ } ], "engines": { - "node": ">=6" + "node": ">=10" }, "scripts": { "test": "xo && ava" @@ -44,9 +44,9 @@ "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" + "pify": "^5.0.0", + "xo": "^0.30.0" } } diff --git a/test.js b/test.js index f4650da..559f557 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,9 @@ -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 fs = require('fs'); +const path = require('path'); +const isWebP = require('is-webp'); +const pify = require('pify'); +const test = require('ava'); +const imageminWebp = require('.'); const fsP = pify(fs); @@ -24,5 +24,5 @@ test('skip optimizing unsupported files', async t => { 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/); + await t.throwsAsync(() => imageminWebp()(buf), {message: /BITSTREAM_ERROR/}); }); From 7c802810c7a67ea4ce8c018fed739209b5db31d9 Mon Sep 17 00:00:00 2001 From: 1000ch Date: Sun, 24 May 2020 17:42:55 +0900 Subject: [PATCH 2/2] Use util.promisify --- package.json | 1 - test.js | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 479dd3c..35aa7f3 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "devDependencies": { "ava": "^3.8.0", "is-webp": "^1.0.0", - "pify": "^5.0.0", "xo": "^0.30.0" } } diff --git a/test.js b/test.js index 559f557..3b08695 100644 --- a/test.js +++ b/test.js @@ -1,14 +1,14 @@ +const {promisify} = require('util'); const fs = require('fs'); const path = require('path'); const isWebP = require('is-webp'); -const pify = require('pify'); 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); @@ -16,13 +16,13 @@ test('convert an image into a WebP', async t => { }); 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')); + const buf = await readFile(path.join(__dirname, 'fixtures/test-corrupt.webp')); await t.throwsAsync(() => imageminWebp()(buf), {message: /BITSTREAM_ERROR/}); });