update
This commit is contained in:
23
test/image-cap.test.js
Normal file
23
test/image-cap.test.js
Normal 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, '[图片]');
|
||||
});
|
||||
Reference in New Issue
Block a user