Files
DndGamePlayer/app/main/project/scenePreviewThumbnail.test.ts
T
Ivan Fontosh 8f8eef53c9 feat(project): optimize image imports and converter
- Optimize imported scene preview images (smart WebP/JPEG/PNG, preserve alpha, keep pixel size)

- Update converter to re-encode existing image assets with same algorithm

- Improve import/export progress overlay and reduce presentation slide stutter

Made-with: Cursor
2026-04-23 17:59:57 +08:00

36 lines
1.1 KiB
TypeScript

import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';
import sharp from 'sharp';
import { generateScenePreviewThumbnailBytes, SCENE_PREVIEW_THUMB_MAX_PX } from './scenePreviewThumbnail';
void test('generateScenePreviewThumbnailBytes: image scales to max edge', async () => {
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dnd-thumb-test-'));
const src = path.join(tmp, 'wide.png');
await sharp({
create: {
width: 800,
height: 400,
channels: 3,
background: { r: 200, g: 40, b: 40 },
},
})
.png()
.toFile(src);
const buf = await generateScenePreviewThumbnailBytes(src, 'image');
assert.ok(buf !== null);
assert.ok(buf.length > 0);
const meta = await sharp(buf).metadata();
assert.equal(typeof meta.width, 'number');
assert.equal(typeof meta.height, 'number');
assert.ok(meta.width > 0 && meta.height > 0);
assert.ok(Math.max(meta.width, meta.height) <= SCENE_PREVIEW_THUMB_MAX_PX);
await fs.rm(tmp, { recursive: true, force: true });
});