• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1const ParserStream = require('../../lib');
2const { makeChunks } = require('../../../../test/utils/common');
3
4module.exports = function parseChunked(html, opts, minChunkSize, maxChunkSize) {
5    const parserStream = new ParserStream(opts);
6    const chunks = makeChunks(html, minChunkSize, maxChunkSize);
7
8    // NOTE: set small waterline for testing purposes
9    parserStream.parser.tokenizer.preprocessor.bufferWaterline = 8;
10
11    for (let i = 0; i < chunks.length - 1; i++) {
12        if (typeof chunks[i] !== 'string') {
13            throw new TypeError();
14        }
15        parserStream.write(chunks[i]);
16    }
17
18    parserStream.end(chunks[chunks.length - 1]);
19
20    return {
21        node: parserStream.document,
22        chunks: chunks
23    };
24};
25