<commit_before>'use strict';
const PassThrough = require('stream').PassThrough;
const assert = require('assert');
const parseTemplate = require('../../lib/parse-template');
const StringifierStream = require('../../lib/streams/stringifier-stream');

function getTemplate(template, specialTags, pipeBeforeTags) {
    specialTags = specialTags || ['fragment'];
    pipeBeforeTags = pipeBeforeTags || [];
    return parseTemplate(specialTags, pipeBeforeTags)(template);
}

describe('Stringifier Stream', () => {

    it('should stream the content from a fragment tag', () => {
        let st = new PassThrough();
        const templatePromise = getTemplate('<fragment title="mock"></fragment>');
        return templatePromise.then(nodes => {
            let data = '';
            const stream = new StringifierStream((tag) => {
                if (tag && tag.name) {
                    assert.deepEqual(tag.attributes, { title: 'mock' });
                    return st;
                }
                return '';
            });
            stream.on('data', (chunk) => {
                data += chunk;
            });
            stream.on('end', () => {
                assert.equal(data, '<html><head></head><body>mock</body></html>');
                done();
            });
            stream.end(nodes);
            st.end('mock');
        });
    });

    it('shoudl consume stream asynchronously', (done) => {<commit_msg>fix typo<commit_after>'use strict';
const PassThrough = require('stream').PassThrough;
const assert = require('assert');
const parseTemplate = require('../../lib/parse-template');
const StringifierStream = require('../../lib/streams/stringifier-stream');

function getTemplate(template, specialTags, pipeBeforeTags) {
    specialTags = specialTags || ['fragment'];
    pipeBeforeTags = pipeBeforeTags || [];
    return parseTemplate(specialTags, pipeBeforeTags)(template);
}

describe('Stringifier Stream', () => {

    it('should stream the content from a fragment tag', () => {
        let st = new PassThrough();
        const templatePromise = getTemplate('<fragment title="mock"></fragment>');
        return templatePromise.then(nodes => {
            let data = '';
            const stream = new StringifierStream((tag) => {
                if (tag && tag.name) {
                    assert.deepEqual(tag.attributes, { title: 'mock' });
                    return st;
                }
                return '';
            });
            stream.on('data', (chunk) => {
                data += chunk;
            });
            stream.on('end', () => {
                assert.equal(data, '<html><head></head><body>mock</body></html>');
                done();
            });
            stream.end(nodes);
            st.end('mock');
        });
    });

    it('should consume stream asynchronously', (done) => {
{'fraction_non_alphanumeric': 0.16112084063047286, 'fraction_numerical': 0.0, 'mean_word_length': 2.1315789473684212, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '111159', 'n_tokens_mistral': 731, 'n_tokens_neox': 700, 'n_words': 153}