1import * as assert from 'node:assert'; 2import { serialize } from 'parse5'; 3import { PlainTextConversionStream } from '../lib/index.js'; 4import { generateTestsForEachTreeAdapter } from 'parse5-test-utils/utils/common.js'; 5 6generateTestsForEachTreeAdapter('plain-test-conversion-stream', (treeAdapter) => { 7 it('Plain text conversion stream', () => { 8 const converter = new PlainTextConversionStream({ treeAdapter }); 9 10 converter.write('Hey'); 11 converter.write('\r\nyo'); 12 converter.write('\u0000'); 13 converter.end('<html><head><body>'); 14 15 const result = serialize(converter.document, { treeAdapter }); 16 17 assert.strictEqual( 18 result, 19 '<html><head></head><body><pre>\nHey\nyo\uFFFD<html><head><body></pre></body></html>' 20 ); 21 }); 22}); 23 24describe('plain-text-conversion-stream', () => { 25 it('Should not accept binary input (GH-269)', () => { 26 const stream = new PlainTextConversionStream(); 27 const buf = Buffer.from('test'); 28 29 assert.throws(() => stream.write(buf), TypeError); 30 }); 31}); 32