-
Notifications
You must be signed in to change notification settings - Fork 15
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
1 parent
cf856b5
commit 074d308
Showing
12 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import test from 'ava'; | ||
import { imageDataPolyfill, importWasmModule, getFixturesImage } from './utils.js'; | ||
|
||
import decode, { init as initDecode } from '@jsquash/avif/decode.js'; | ||
import encode, { init as initEncode } from '@jsquash/avif/encode.js'; | ||
|
||
imageDataPolyfill(); | ||
|
||
test('can successfully decode image', async t => { | ||
const [testImage, decodeWasmModule] = await Promise.all([ | ||
getFixturesImage('test.avif'), | ||
importWasmModule('node_modules/@jsquash/avif/codec/dec/avif_dec.wasm'), | ||
]); | ||
initDecode(decodeWasmModule); | ||
const data = await decode(testImage); | ||
t.is(data.width, 50); | ||
t.is(data.height, 50); | ||
t.is(data.data.length, 4 * 50 * 50); | ||
}); | ||
|
||
test('can successfully encode image', async t => { | ||
const encodeWasmModule = await importWasmModule('node_modules/@jsquash/avif/codec/enc/avif_enc.wasm'); | ||
await initEncode(encodeWasmModule); | ||
const data = await encode(new ImageData(new Uint8ClampedArray(4 * 50 * 50), 50, 50)); | ||
t.assert(data instanceof ArrayBuffer); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import test from 'ava'; | ||
import { imageDataPolyfill, importWasmModule, getFixturesImage } from './utils.js'; | ||
|
||
import decode, { init as initDecode } from '@jsquash/jpeg/decode.js'; | ||
import encode, { init as initEncode } from '@jsquash/jpeg/encode.js'; | ||
|
||
imageDataPolyfill(); | ||
|
||
test('can successfully decode image', async t => { | ||
const [testImage, decodeWasmModule] = await Promise.all([ | ||
getFixturesImage('test.jpeg'), | ||
importWasmModule('node_modules/@jsquash/jpeg/codec/dec/mozjpeg_dec.wasm'), | ||
]); | ||
initDecode(decodeWasmModule); | ||
const data = await decode(testImage); | ||
t.is(data.width, 50); | ||
t.is(data.height, 50); | ||
t.is(data.data.length, 4 * 50 * 50); | ||
}); | ||
|
||
test('can successfully encode image', async t => { | ||
const encodeWasmModule = await importWasmModule('node_modules/@jsquash/jpeg/codec/enc/mozjpeg_enc.wasm'); | ||
await initEncode(encodeWasmModule); | ||
const data = await encode(new ImageData(new Uint8ClampedArray(4 * 50 * 50), 50, 50)); | ||
t.assert(data instanceof ArrayBuffer); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import test from 'ava'; | ||
import { imageDataPolyfill, importWasmModule, getFixturesImage } from './utils.js'; | ||
|
||
import decode, { init as initDecode } from '@jsquash/jxl/decode.js'; | ||
import encode, { init as initEncode } from '@jsquash/jxl/encode.js'; | ||
|
||
imageDataPolyfill(); | ||
|
||
test('can successfully decode image', async t => { | ||
const [testImage, decodeWasmModule] = await Promise.all([ | ||
getFixturesImage('test.jxl'), | ||
importWasmModule('node_modules/@jsquash/jxl/codec/dec/jxl_dec.wasm'), | ||
]); | ||
initDecode(decodeWasmModule); | ||
const data = await decode(testImage); | ||
t.is(data.width, 50); | ||
t.is(data.height, 50); | ||
t.is(data.data.length, 4 * 50 * 50); | ||
}); | ||
|
||
test('can successfully encode image', async t => { | ||
const encodeWasmModule = await importWasmModule('node_modules/@jsquash/jxl/codec/enc/jxl_enc.wasm'); | ||
await initEncode(encodeWasmModule); | ||
const data = await encode(new ImageData(new Uint8ClampedArray(4 * 50 * 50), 50, 50)); | ||
t.assert(data instanceof ArrayBuffer); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import test from 'ava'; | ||
import { imageDataPolyfill, importWasmModule, getFixturesImage } from './utils.js'; | ||
|
||
import decode, { init as initDecode } from '@jsquash/png/decode.js'; | ||
import encode, { init as initEncode } from '@jsquash/png/encode.js'; | ||
|
||
imageDataPolyfill(); | ||
|
||
test('can successfully decode image', async t => { | ||
const [testImage, decodeWasmModule] = await Promise.all([ | ||
getFixturesImage('test.png'), | ||
importWasmModule('node_modules/@jsquash/png/codec/squoosh_png_bg.wasm'), | ||
]); | ||
initDecode(decodeWasmModule); | ||
const data = await decode(testImage); | ||
t.is(data.width, 50); | ||
t.is(data.height, 50); | ||
t.is(data.data.length, 4 * 50 * 50); | ||
}); | ||
|
||
test('can successfully encode image', async t => { | ||
const encodeWasmModule = await importWasmModule('node_modules/@jsquash/png/codec/squoosh_png_bg.wasm'); | ||
await initEncode(encodeWasmModule); | ||
const data = await encode(new ImageData(new Uint8ClampedArray(4 * 50 * 50), 50, 50)); | ||
// @TODO Next breaking change, make PNG encode return an ArrayBuffer to match other packages | ||
t.assert(!(data instanceof ArrayBuffer)); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
|
||
export function imageDataPolyfill() { | ||
if (typeof ImageData === 'undefined') { | ||
globalThis.ImageData = class ImageData { | ||
constructor(data, width, height) { | ||
this.data = data; | ||
this.width = width; | ||
this.height = height; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
export async function importWasmModule(path) { | ||
const fileBuffer = await fs.readFile(path); | ||
return WebAssembly.compile(fileBuffer); | ||
} | ||
|
||
export function getFixturesImage(imagePath) { | ||
const filePath = path.resolve(`fixtures/${imagePath}`); | ||
return fs.readFile(filePath); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import test from 'ava'; | ||
import { imageDataPolyfill, importWasmModule, getFixturesImage } from './utils.js'; | ||
|
||
import decode, { init as initDecode } from '@jsquash/webp/decode.js'; | ||
import encode, { init as initEncode } from '@jsquash/webp/encode.js'; | ||
|
||
imageDataPolyfill(); | ||
|
||
test('can successfully decode image', async t => { | ||
const [testImage, decodeWasmModule] = await Promise.all([ | ||
getFixturesImage('test.webp'), | ||
importWasmModule('node_modules/@jsquash/webp/codec/dec/webp_dec.wasm'), | ||
]); | ||
initDecode(decodeWasmModule); | ||
const data = await decode(testImage); | ||
t.is(data.width, 50); | ||
t.is(data.height, 50); | ||
t.is(data.data.length, 4 * 50 * 50); | ||
}); | ||
|
||
test('can successfully encode image', async t => { | ||
const encodeWasmModule = await importWasmModule('node_modules/@jsquash/webp/codec/enc/webp_enc.wasm'); | ||
await initEncode(encodeWasmModule); | ||
const data = await encode(new ImageData(new Uint8ClampedArray(4 * 50 * 50), 50, 50)); | ||
t.assert(data instanceof ArrayBuffer); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "integration-tests", | ||
"scripts": { | ||
"test": "ava node/*.test.js" | ||
}, | ||
"devDependencies": { | ||
"ava": "^5.3.1", | ||
"@jsquash/avif": "file:../packages/avif/dist", | ||
"@jsquash/jpeg": "file:../packages/jpeg/dist", | ||
"@jsquash/jxl": "file:../packages/jxl/dist", | ||
"@jsquash/oxipng": "file:../packages/oxipng/dist", | ||
"@jsquash/png": "file:../packages/png/dist", | ||
"@jsquash/resize": "file:../packages/resize/dist", | ||
"@jsquash/webp": "file:../packages/webp/dist" | ||
}, | ||
"private": true, | ||
"type": "module" | ||
} |