-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
51 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,25 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
- push | ||
- pull_request | ||
jobs: | ||
linux: | ||
runs-on: ubuntu-latest | ||
|
||
test: | ||
name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }} | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
node-version: [10.x, 12.x, 14.x] | ||
|
||
node-version: | ||
- 16 | ||
- 14 | ||
- 12 | ||
os: | ||
- ubuntu-latest | ||
- macos-latest | ||
- windows-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test | ||
env: | ||
CI: true | ||
|
||
macos: | ||
runs-on: macos-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [10.x, 12.x, 14.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test | ||
env: | ||
CI: true | ||
|
||
windows: | ||
runs-on: windows-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [10.x, 12.x, 14.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test | ||
env: | ||
CI: true | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
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 readFile = promisify(fs.readFile); | ||
import {promises as fs} from 'node:fs'; | ||
import isWebP from 'is-webp'; | ||
import test from 'ava'; | ||
import imageminWebp from './index.js'; | ||
|
||
test('convert an image into a WebP', async t => { | ||
const buf = await readFile(path.join(__dirname, 'fixtures/test.png')); | ||
const data = await imageminWebp()(buf); | ||
const buffer = await fs.readFile(new URL('fixtures/test.png', import.meta.url)); | ||
const data = await imageminWebp()(buffer); | ||
|
||
t.true(data.length < buf.length); | ||
t.true(data.length < buffer.length); | ||
t.true(isWebP(data)); | ||
}); | ||
|
||
test('skip optimizing unsupported files', async t => { | ||
const buf = await readFile(path.join(__dirname, 'fixtures/test-unsupported.bmp')); | ||
const data = await imageminWebp()(buf); | ||
const buffer = await fs.readFile(new URL('fixtures/test-unsupported.bmp', import.meta.url)); | ||
const data = await imageminWebp()(buffer); | ||
|
||
t.deepEqual(data, buf); | ||
t.deepEqual(data, buffer); | ||
}); | ||
|
||
test('throw error when an image is corrupt', async t => { | ||
const buf = await readFile(path.join(__dirname, 'fixtures/test-corrupt.webp')); | ||
await t.throwsAsync(() => imageminWebp()(buf), {message: /BITSTREAM_ERROR/}); | ||
const buffer = await fs.readFile(new URL('fixtures/test-corrupt.webp', import.meta.url)); | ||
await t.throwsAsync(() => imageminWebp()(buffer), {message: /BITSTREAM_ERROR/}); | ||
}); |