• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const assert = require('assert');
4const parse5 = require('parse5');
5const PlainTextConversionStream = require('../lib');
6const { generateTestsForEachTreeAdapter } = require('../../../test/utils/common');
7
8generateTestsForEachTreeAdapter(module.exports, (_test, treeAdapter) => {
9    _test['Plain text conversion stream'] = function() {
10        const converter = new PlainTextConversionStream({ treeAdapter: treeAdapter });
11
12        converter.write('Hey');
13        converter.write('\r\nyo');
14        converter.write('\u0000');
15        converter.end('<html><head><body>');
16
17        const result = parse5.serialize(converter.document, { treeAdapter: treeAdapter });
18
19        assert.strictEqual(
20            result,
21            '<html><head></head><body><pre>\nHey\nyo\uFFFD&lt;html&gt;&lt;head&gt;&lt;body&gt;</pre></body></html>'
22        );
23    };
24});
25
26exports['Regression - Plain text conversion stream - Should not accept binary input (GH-269)'] = () => {
27    const stream = new PlainTextConversionStream();
28    const buf = Buffer.from('test');
29
30    assert.throws(() => stream.write(buf), TypeError);
31};
32