Coverage work found a 3rd real bug: isMacOS() compared os.name against the legacy 'Mac OS' string, but ua-parser-js v2 reports 'macOS' — so it was dead, and Mac users saw "Ctrl + k" instead of "⌘ + k" in the editor toolbar, search, and settings shortcut hints. Now accepts both 'macOS' and 'Mac OS'. Suites (via subagent, verified): via-servers (10 — power/popularity server selection), bad-words (9), syntaxHighlight tokenize (14), plugins/utils getEmoticonSearchStr (5), imageCompression formatFileSize/isCompressible (5), user-agent (6, now asserting the fixed behavior). Full suite now 501 tests, all passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { formatFileSize, isCompressible } from './imageCompression';
|
|
|
|
test('formatFileSize formats bytes below 1KB as B', () => {
|
|
assert.equal(formatFileSize(0), '0 B');
|
|
assert.equal(formatFileSize(1), '1 B');
|
|
assert.equal(formatFileSize(512), '512 B');
|
|
assert.equal(formatFileSize(1023), '1023 B');
|
|
});
|
|
|
|
test('formatFileSize formats values in the KB range', () => {
|
|
assert.equal(formatFileSize(1024), '1.0 KB');
|
|
assert.equal(formatFileSize(1536), '1.5 KB');
|
|
// 1024 * 1024 - 1 is still under the MB boundary
|
|
assert.equal(formatFileSize(1024 * 1024 - 1), '1024.0 KB');
|
|
});
|
|
|
|
test('formatFileSize formats values in the MB range', () => {
|
|
assert.equal(formatFileSize(1024 * 1024), '1.0 MB');
|
|
assert.equal(formatFileSize(1024 * 1024 * 1.5), '1.5 MB');
|
|
assert.equal(formatFileSize(1024 * 1024 * 10), '10.0 MB');
|
|
});
|
|
|
|
test('isCompressible accepts raster image types', () => {
|
|
assert.equal(isCompressible({ type: 'image/png' } as Blob), true);
|
|
assert.equal(isCompressible({ type: 'image/jpeg' } as Blob), true);
|
|
assert.equal(isCompressible({ type: 'image/gif' } as Blob), true);
|
|
assert.equal(isCompressible({ type: 'image/webp' } as Blob), true);
|
|
});
|
|
|
|
test('isCompressible rejects svg, empty type, and non-images', () => {
|
|
assert.equal(isCompressible({ type: 'image/svg+xml' } as Blob), false);
|
|
assert.equal(isCompressible({ type: '' } as Blob), false);
|
|
assert.equal(isCompressible({ type: 'application/pdf' } as Blob), false);
|
|
assert.equal(isCompressible({ type: 'text/plain' } as Blob), false);
|
|
assert.equal(isCompressible({ type: 'video/mp4' } as Blob), false);
|
|
});
|