Files
reader/server/test/chapter-quality.test.ts
T
hectorqin 7bff77eaf8 feat(reader): deliver P0-P2 reading tools and ecosystem integrations
Add reliable reading progress, verified backup and restore, reading tools, offline downloads, source quality checks, personal credential status, OPDS serving and verified WebDAV backup uploads.
2026-09-24 07:47:32 +08:00

13 lines
766 B
TypeScript

import { test } from 'node:test';
import assert from 'node:assert/strict';
import { chapterQuality, requireChapterContent } from '../src/publications/chapter-quality.ts';
test('quality counts visible Unicode characters, ignores markup and rejects empty chapters', () => {
assert.equal(chapterQuality(' 中文 😀 \n', 'text/plain').characters, 3);
assert.equal(chapterQuality('<p>中&nbsp;文 &amp; 😀</p><script>evil()</script>', 'text/html').characters, 4);
for (const body of [' ', '\u200b\u2060', '<p>&nbsp;</p>', '<script>evil()</script>']) {
assert.throws(() => requireChapterContent(body, 'text/html'), { code: 'EMPTY_CHAPTER' });
}
assert.equal(requireChapterContent('<img src="data:image/png;base64,abcd" />', 'text/html').images, 1);
});