<commit_before>import path from 'path';
import {execFileSync} from 'child_process';
import dirCompare from 'dir-compare';
import assert from 'assert';

const sites = {
	'./test/sites/site-with-one-page-and-no-layout': 0,
	'./test/sites/site-with-one-page-and-a-hidden-directory': 0,
	'./test/sites/site-with-many-pages': 0,
	'./test/sites/site-with-invalid-pug-file': 1,
	'./test/sites/site-with-one-page-and-a-script': 0
};

describe ('bin', () => {
	Object.keys(sites).forEach(site => {
		describeSite(site, sites[site]);
	});
});

function describeSite (site, expectedCode) {
	describe(site, () => {
		let actualCode;
		let comparison;
		let actualDir = path.join(site, 'actual').split(path.sep).join('/');
		let expectedDir = path.join(site, 'expected').split(path.sep).join('/');
		let srcDir = path.join(site, 'src').split(path.sep).join('/');

		before(() => {
			try {
				execFileSync('node', ['./bin/nocms.js', 'compile', '--in-dir', srcDir, '--out-dir', actualDir], {stdio: [0,1,2]});
				actualCode = 0;
			} catch (err) {
				actualCode = err.status;
			}
		});

		before(() => {
			let options = {
				compareContent: true
			};

			comparison = dirCompare.compareSync(actualDir, expectedDir, options);
		});

		it ('should exit with expected code', () => {
			assert.equal(actualCode, expectedCode);
		});

		it ('should write expected resources to the output directory', () => {
			if (!comparison.same && actualCode === 0) {
				let err = new Error(`site did not compile as expected
${JSON.stringify(comparison.diffSet.filter(diff => diff.state !== 'equal'), null, 4)}
`);
				err.comparison = comparison;

				throw err;
			}
		});
	});
}<commit_msg>output expected code in test<commit_after>import path from 'path';
import {execFileSync} from 'child_process';
import dirCompare from 'dir-compare';
import assert from 'assert';

const sites = {
	'./test/sites/site-with-one-page-and-no-layout': 0,
	'./test/sites/site-with-one-page-and-a-hidden-directory': 0,
	'./test/sites/site-with-many-pages': 0,
	'./test/sites/site-with-invalid-pug-file': 1,
	'./test/sites/site-with-one-page-and-a-script': 0
};

describe ('bin', () => {
	Object.keys(sites).forEach(site => {
		describeSite(site, sites[site]);
	});
});

function describeSite (site, expectedCode) {
	describe(site, () => {
		let actualCode;
		let comparison;
		let actualDir = path.join(site, 'actual').split(path.sep).join('/');
		let expectedDir = path.join(site, 'expected').split(path.sep).join('/');
		let srcDir = path.join(site, 'src').split(path.sep).join('/');

		before(() => {
			try {
				execFileSync('node', ['./bin/nocms.js', 'compile', '--in-dir', srcDir, '--out-dir', actualDir], {stdio: [0,1,2]});
				actualCode = 0;
			} catch (err) {
				actualCode = err.status;
			}
		});

		before(() => {
			let options = {
				compareContent: true
			};

			comparison = dirCompare.compareSync(actualDir, expectedDir, options);
		});

		it (`should exit with expected code ${expectedCode}`, () => {
			assert.equal(actualCode, expectedCode);
		});

		it ('should write expected resources to the output directory', () => {
			if (!comparison.same && actualCode === 0) {
				let err = new Error(`site did not compile as expected
${JSON.stringify(comparison.diffSet.filter(diff => diff.state !== 'equal'), null, 4)}
`);
				err.comparison = comparison;

				throw err;
			}
		});
	});
}
{'fraction_non_alphanumeric': 0.20106920106920106, 'fraction_numerical': 0.006534006534006534, 'mean_word_length': 3.7170868347338937, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '3551744', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1135, 'n_words': 243}