-
Notifications
You must be signed in to change notification settings - Fork 8
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
54 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
"description": "Imagemin plugin for jpegoptim", | ||
"license": "MIT", | ||
"repository": "imagemin/imagemin-jpegoptim", | ||
"type": "module", | ||
"exports": "./index.js", | ||
"author": { | ||
"name": "Kevin Mårtensson", | ||
"email": "[email protected]", | ||
|
@@ -21,7 +23,7 @@ | |
} | ||
], | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
|
@@ -39,13 +41,13 @@ | |
"optimize" | ||
], | ||
"dependencies": { | ||
"execa": "^4.0.0", | ||
"is-jpg": "^2.0.0", | ||
"jpegoptim-bin": "^6.0.0" | ||
"execa": "^6.0.0", | ||
"is-jpg": "^3.0.0", | ||
"jpegoptim-bin": "^7.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^3.8.0", | ||
"ava": "^3.15.0", | ||
"is-progressive": "^3.0.0", | ||
"xo": "^0.30.0" | ||
"xo": "^0.47.0" | ||
} | ||
} |
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,42 +1,38 @@ | ||
const {promisify} = require('util'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const isJpg = require('is-jpg'); | ||
const isProgressive = require('is-progressive'); | ||
const test = require('ava'); | ||
const m = require('.'); | ||
|
||
const readFile = promisify(fs.readFile); | ||
import {promises as fs} from 'node:fs'; | ||
import isJpg from 'is-jpg'; | ||
import isProgressive from 'is-progressive'; | ||
import test from 'ava'; | ||
import imageminJpegoptim from './index.js'; | ||
|
||
test('optimize a JPG', async t => { | ||
const buffer = await readFile(path.join(__dirname, 'fixtures/test.jpg')); | ||
const data = await m()(buffer); | ||
const buffer = await fs.readFile(new URL('fixtures/test.jpg', import.meta.url)); | ||
const data = await imageminJpegoptim()(buffer); | ||
t.true(data.length < buffer.length); | ||
t.true(isJpg(data)); | ||
}); | ||
|
||
test('throw error when a JPG is corrupt', async t => { | ||
const buffer = await readFile(path.join(__dirname, 'fixtures/test-corrupt.jpg')); | ||
const buffer = await fs.readFile(new URL('fixtures/test-corrupt.jpg', import.meta.url)); | ||
await t.throwsAsync(async () => { | ||
await m()(buffer); | ||
await imageminJpegoptim()(buffer); | ||
}, {message: /JFIF/}); | ||
}); | ||
|
||
test('throw error when a large JPG is corrupt', async t => { | ||
const buffer = await readFile(path.join(__dirname, 'fixtures/test-corrupt-large.jpg')); | ||
const buffer = await fs.readFile(new URL('fixtures/test-corrupt-large.jpg', import.meta.url)); | ||
await t.throwsAsync(async () => { | ||
await m()(buffer); | ||
await imageminJpegoptim()(buffer); | ||
}, {message: /EPIPE|ERROR/}); | ||
}); | ||
|
||
test('progressive option', async t => { | ||
const buffer = await readFile(path.join(__dirname, 'fixtures/test.jpg')); | ||
const data = await m({progressive: true})(buffer); | ||
const buffer = await fs.readFile(new URL('fixtures/test.jpg', import.meta.url)); | ||
const data = await imageminJpegoptim({progressive: true})(buffer); | ||
t.true(isProgressive.buffer(data)); | ||
}); | ||
|
||
test('throw on wrong input', async t => { | ||
await t.throwsAsync(async () => { | ||
await m()('foo'); | ||
await imageminJpegoptim()('foo'); | ||
}, {message: 'Expected a Buffer, got string'}); | ||
}); |