• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import * as assert from 'node:assert';
2import { ParserStream } from '../lib/index.js';
3import { generateParsingTests } from 'parse5-test-utils/utils/generate-parsing-tests.js';
4import { parseChunked } from './utils/parse-chunked.js';
5import { finished } from 'parse5-test-utils/utils/common.js';
6
7generateParsingTests(
8    'ParserStream',
9    'ParserStream',
10    {
11        expectErrors: [
12            //TODO(GH-448): Foreign content behaviour was updated in the HTML spec.
13            //The old test suite still tests the old behaviour.
14            '269.foreign-fragment',
15            '270.foreign-fragment',
16            '307.foreign-fragment',
17            '309.foreign-fragment',
18            '316.foreign-fragment',
19            '317.foreign-fragment',
20        ],
21    },
22    (test, opts) => parseChunked(test, opts)
23);
24
25describe('ParserStream', () => {
26    it('Fix empty stream parsing with ParserStream (GH-196)', async () => {
27        const parser = new ParserStream();
28
29        parser.end();
30
31        await finished(parser);
32
33        assert.ok(parser.document.childNodes.length > 0);
34    });
35
36    it('Should not accept binary input (GH-269)', () => {
37        const stream = new ParserStream();
38        const buf = Buffer.from('test');
39
40        assert.throws(() => stream.write(buf), TypeError);
41    });
42});
43