23 lines
789 B
JavaScript
23 lines
789 B
JavaScript
'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, '[图片]');
|
|
}); |