sharp by wasm
This commit is contained in:
@@ -2,7 +2,7 @@ import assert from 'node:assert/strict';
|
||||
import { mkdtempSync, existsSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
import sharp from 'sharp';
|
||||
import { optimizeImage } from 'wasm-image-optimization';
|
||||
import LibDashStore from '../src/index.js';
|
||||
import { BetterSqlite3Provider } from '../src/providers/sqlite3/index.js';
|
||||
|
||||
@@ -72,16 +72,9 @@ async function runTests() {
|
||||
|
||||
const manifestId = delivery.id;
|
||||
const testContent = Buffer.from('Hello SQLite Storage Engine! PDF or text content test.');
|
||||
const testThumb = await sharp({
|
||||
create: {
|
||||
width: 64,
|
||||
height: 64,
|
||||
channels: 4,
|
||||
background: { r: 255, g: 0, b: 0, alpha: 1 },
|
||||
},
|
||||
})
|
||||
.avif()
|
||||
.toBuffer();
|
||||
const thumbSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64"><rect width="64" height="64" fill="rgb(255,0,0)"/></svg>`;
|
||||
const testThumbRes = await optimizeImage({ image: thumbSvg, format: 'avif' });
|
||||
const testThumb = Buffer.from(testThumbRes.data);
|
||||
|
||||
const attachment = await store.manifestattachment.add(googleAuthId, manifestId, {
|
||||
name: 'test-doc.txt',
|
||||
@@ -202,16 +195,9 @@ async function runTests() {
|
||||
|
||||
console.log('Article track_stock tests passed!');
|
||||
|
||||
const sampleImage = await sharp({
|
||||
create: {
|
||||
width: 300,
|
||||
height: 200,
|
||||
channels: 4,
|
||||
background: { r: 0, g: 128, b: 255, alpha: 1 },
|
||||
},
|
||||
})
|
||||
.png()
|
||||
.toBuffer();
|
||||
const sampleSvg = `<svg xmlns="http://www.w3.org/2000/svg" width="300" height="200"><rect width="300" height="200" fill="rgb(0,128,255)"/></svg>`;
|
||||
const sampleImageRes = await optimizeImage({ image: sampleSvg, format: 'png' });
|
||||
const sampleImage = Buffer.from(sampleImageRes.data);
|
||||
|
||||
const picResult = await store.article.addImage(googleAuthId, article.sku, sampleImage);
|
||||
const fullHash = picResult.fullHash;
|
||||
@@ -223,10 +209,10 @@ async function runTests() {
|
||||
assert.equal(smallThumbRow.smallthumbw, 32);
|
||||
assert.equal(smallThumbRow.smallthumbh, 21);
|
||||
assert(Buffer.isBuffer(smallThumbRow.smallthumbbinary), 'Small thumb AVIF must be stored in the pic row');
|
||||
const smallThumbMetadata = await sharp(smallThumbRow.smallthumbbinary).metadata();
|
||||
assert.equal(smallThumbMetadata.format, 'heif');
|
||||
assert.equal(smallThumbMetadata.width, 32);
|
||||
assert.equal(smallThumbMetadata.height, 21);
|
||||
const smallThumbMetadata = await optimizeImage({ image: smallThumbRow.smallthumbbinary, format: 'none' });
|
||||
assert.equal(smallThumbMetadata.originalFormat, 'avif');
|
||||
assert.equal(smallThumbMetadata.originalWidth, 32);
|
||||
assert.equal(smallThumbMetadata.originalHeight, 21);
|
||||
|
||||
const brand = await store.brand.create(googleAuthId, { name: 'Small Thumb Test Brand' });
|
||||
await store.brand.addImage(googleAuthId, brand.id, sampleImage);
|
||||
|
||||
Reference in New Issue
Block a user