<commit_before>let puppeteer = require('puppeteer'),
    assert    = require('assert'),
    Hawkejs   = require('../../index.js'),
    http      = require('http'),
    fs        = require('fs');

let navigations = 0,
    coverages = [];

global.do_coverage = !!global.__coverage__;
global.page = null;

let hserverside_rx = /hserverside-\d+/g,
    hrendered_rx = /he-rendered="\d+?"/i;

global.createHawkejsInstance = function createHawkejsInstance() {

	let hawkejs = new Hawkejs();

	// Disable the exposed static variables being loaded via separate js file
	hawkejs.exposed_path = null;

	return hawkejs;
};

/**
 * Normalize attributes that are randomly generated
 */
global.assertEqualHtml = function assertEqualHtml(actual, expected, message) {

	actual = despace(actual);
	expected = despace(expected);

	// Normalize he-rendered attributes
	actual = actual.replace(hrendered_rx, 'he-rendered="1"');
	expected = expected.replace(hrendered_rx, 'he-rendered="1"');

	actual = actual.replace(hserverside_rx, 'hserverside-0');
	expected = expected.replace(hserverside_rx, 'hserverside-0');

	return assert.strictEqual(actual, expected, message);
};

global.fetchCoverage = async function fetchCoverage() {

	if (!page) {
		return;
	}

	let temp = await page.evaluate(function getCoverage() {
		return window.__coverage__;
	});

	if (temp) {
		coverages.push(temp);
	}

	return coverages;
};

global.setLocation = async function setLocation(path) {

	let url;

	if (!page) {
		await loadBrowser();
	}

	if (navigations && do_coverage) {
		await fetchCoverage();
	}

	navigations++;

	if (path.indexOf('http') == -1) {
		url = 'http://127.0.0.1:' + port + path;
	} else {
		url = path;
	}

	await page.goto(url);
};

global.clickPage = function clickPage(selector, options) {
	return page.click(selector, options);
};

global.evalPage = function evalPage(fnc, ...args) {
	return page.evaluate(fnc, ...args);
};

global.despace = function despace(text) {
	return text.trim().replace(/\n/g, ' ').replace(/\s\s+/g, ' ');
};

global.respondWithRender = function respondWithRender(templates, renderer, responder) {
	renderer.renderHTML(templates).done(function afterRender(err, html) {

		if (err != null) {
			throw err;
		}
<commit_msg>Fix despace method in unit tests not working on windows<commit_after>let puppeteer = require('puppeteer'),
    assert    = require('assert'),
    Hawkejs   = require('../../index.js'),
    http      = require('http'),
    fs        = require('fs');

let navigations = 0,
    coverages = [];

global.do_coverage = !!global.__coverage__;
global.page = null;

let hserverside_rx = /hserverside-\d+/g,
    hrendered_rx = /he-rendered="\d+?"/i;

global.createHawkejsInstance = function createHawkejsInstance() {

	let hawkejs = new Hawkejs();

	// Disable the exposed static variables being loaded via separate js file
	hawkejs.exposed_path = null;

	return hawkejs;
};

/**
 * Normalize attributes that are randomly generated
 */
global.assertEqualHtml = function assertEqualHtml(actual, expected, message) {

	actual = despace(actual);
	expected = despace(expected);

	// Normalize he-rendered attributes
	actual = actual.replace(hrendered_rx, 'he-rendered="1"');
	expected = expected.replace(hrendered_rx, 'he-rendered="1"');

	actual = actual.replace(hserverside_rx, 'hserverside-0');
	expected = expected.replace(hserverside_rx, 'hserverside-0');

	return assert.strictEqual(actual, expected, message);
};

global.fetchCoverage = async function fetchCoverage() {

	if (!page) {
		return;
	}

	let temp = await page.evaluate(function getCoverage() {
		return window.__coverage__;
	});

	if (temp) {
		coverages.push(temp);
	}

	return coverages;
};

global.setLocation = async function setLocation(path) {

	let url;

	if (!page) {
		await loadBrowser();
	}

	if (navigations && do_coverage) {
		await fetchCoverage();
	}

	navigations++;

	if (path.indexOf('http') == -1) {
		url = 'http://127.0.0.1:' + port + path;
	} else {
		url = path;
	}

	await page.goto(url);
};

global.clickPage = function clickPage(selector, options) {
	return page.click(selector, options);
};

global.evalPage = function evalPage(fnc, ...args) {
	return page.evaluate(fnc, ...args);
};

global.despace = function despace(text) {
	return text.trim().replace(/\r\n/g, ' ').replace(/\n/g, ' ').replace(/\s\s+/g, ' ');
};

global.respondWithRender = function respondWithRender(templates, renderer, responder) {
	renderer.renderHTML(templates).done(function afterRender(err, html) {

		if (err != null) {
			throw err;
		}

{'fraction_non_alphanumeric': 0.15401588702559577, 'fraction_numerical': 0.00529567519858782, 'mean_word_length': 4.098987626546681, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5653662', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1514, 'n_words': 330}