<commit_before>'use strict';

const http = require('http');
const PassThrough = require('stream').PassThrough;
const metrics = require('metrics');
const histogram = new metrics.Histogram.createUniformHistogram();
const html = `
    <html>
    <head>
        <meta charset="utf-8">
        <title>Test Page</title>
    </head>
    <body>
        <h2>Fragment 1:</h2>
        <fragment primary src="http://localhost:8081"/>
        <h2>Fragment 2:</h2>
        <fragment async src="http://localhost:8081"/>
    </body>
    </html>
`;
const parseTemplate = require('../lib/parse-template')(['fragment']);
const template = Promise.resolve(html).then(parseTemplate).then(cacheTemplate);
const requests = new WeakMap();
const Tailor = require('../');
const tailor = new Tailor({
    fetchTemplate : () => template.then(unwrapCachedTemplate)
});

function unwrapCachedTemplate (chunks) {
    const stream = new PassThrough({objectMode: true});
    chunks.forEach((chunk) => stream.write(chunk));
    stream.end();
    return stream;
}

function cacheTemplate (stream) {
    return new Promise((resolve, reject) => {
        const chunks = [];
        stream.on('data', (data) => chunks.push(data));
        stream.on('end', () => resolve(chunks));
        stream.on('error', (error) => {
            reject(error);
        });
    });
}
<commit_msg>Update bechmark test<commit_after>'use strict';

const http = require('http');
const metrics = require('metrics');
const histogram = new metrics.Histogram.createUniformHistogram();
const html = `
    <html>
    <head>
        <meta charset="utf-8">
        <title>Test Page</title>
    </head>
    <body>
        <h2>Fragment 1:</h2>
        <fragment primary src="http://localhost:8081"></fragment>
        <h2>Fragment 2:</h2>
        <fragment async src="http://localhost:8081"/></fragment>
    </body>
    </html>
`;
const parseTemplate = require('../lib/parse-template')(['fragment'], []);
const requests = new WeakMap();
const Tailor = require('../');
const tailor = new Tailor({
    fetchTemplate : () => Promise.resolve(html).then(parseTemplate)
});

{'fraction_non_alphanumeric': 0.17952380952380953, 'fraction_numerical': 0.014285714285714285, 'mean_word_length': 3.377083333333333, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 42, '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': '3695235', 'n_tokens_mistral': 643, 'n_tokens_neox': 623, 'n_words': 138}