This commit is contained in:
2026-09-12 13:59:12 +08:00
commit 941ce4baab
71 changed files with 13037 additions and 0 deletions

23
test/image-cap.test.js Normal file
View File

@@ -0,0 +1,23 @@
'use strict';
const assert = require('node:assert');
const { capImage } = require('../lib/image-cap');
let passed = 0;
function check(name, fn) {
try { fn(); console.log(' ok -', name); passed++; }
catch (e) { console.error(' FAIL -', name, e.message); process.exitCode = 1; }
}
check('small buffer returned untouched', () => {
const buf = Buffer.alloc(1024); // 1 KB
const r = capImage(buf);
assert.strictEqual(r.buf, buf, 'small images should not be modified');
assert.strictEqual(r.preview, null);
});
check('oversized buffer triggers preview placeholder', () => {
const buf = Buffer.alloc(3 * 1024 * 1024); // 3 MB
const r = capImage(buf);
assert.ok(r.preview !== null, 'oversized images should produce preview');
assert.strictEqual(r.preview, '[图片]');
});