-
Notifications
You must be signed in to change notification settings - Fork 57
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
53 additions
and
92 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 mozjpeg", | ||
"license": "MIT", | ||
"repository": "imagemin/imagemin-mozjpeg", | ||
"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" | ||
|
@@ -41,13 +43,13 @@ | |
"optimize" | ||
], | ||
"dependencies": { | ||
"execa": "^4.0.0", | ||
"is-jpg": "^2.0.0", | ||
"mozjpeg": "^7.0.0" | ||
"execa": "^6.0.0", | ||
"is-jpg": "^3.0.0", | ||
"mozjpeg": "^8.0.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,39 +1,35 @@ | ||
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 imageminMozjpeg from './index.js'; | ||
|
||
test('optimize a JPG', async t => { | ||
const buf = await readFile(path.join(__dirname, 'fixture.jpg')); | ||
const data = await m()(buf); | ||
const buffer = await fs.readFile(new URL('fixture.jpg', import.meta.url)); | ||
const data = await imageminMozjpeg()(buffer); | ||
|
||
t.true(data.length < buf.length); | ||
t.true(data.length < buffer.length); | ||
t.true(isJpg(data)); | ||
t.true(isProgressive.buffer(data)); | ||
}); | ||
|
||
test('support mozjpeg options', async t => { | ||
const buf = await readFile(path.join(__dirname, 'fixture.jpg')); | ||
const data = await m({progressive: false})(buf); | ||
const buffer = await fs.readFile(new URL('fixture.jpg', import.meta.url)); | ||
const data = await imageminMozjpeg({progressive: false})(buffer); | ||
|
||
t.false(isProgressive.buffer(data)); | ||
}); | ||
|
||
test('skip optimizing a non-JPG file', async t => { | ||
const buf = await readFile(__filename); | ||
const data = await m()(buf); | ||
const buffer = await fs.readFile(new URL(import.meta.url)); | ||
const data = await imageminMozjpeg()(buffer); | ||
|
||
t.deepEqual(data, buf); | ||
t.deepEqual(data, buffer); | ||
}); | ||
|
||
test('throw error when a JPG is corrupt', async t => { | ||
const buf = await readFile(path.join(__dirname, 'fixture-corrupt.jpg')); | ||
const buffer = await fs.readFile(new URL('fixture-corrupt.jpg', import.meta.url)); | ||
await t.throwsAsync(async () => { | ||
await m()(buf); | ||
await imageminMozjpeg()(buffer); | ||
}, {message: /Corrupt JPEG data/}); | ||
}); |