<commit_before>import {assert} from 'chai';
import sinon from 'sinon';
import any from '@travi/any';
import fs from 'fs';
import path from 'path';
import getAssets from '../../../../lib/server/view/asset-manager';

suite('asset manager', () => {
  let sandbox;

  setup(() => {
    sandbox = sinon.sandbox.create();

    sandbox.stub(fs, 'readFile');
  });

  teardown(() => sandbox.restore());

  test('that the asset list is returned based on the webpack assets file', () => {
    const jsFiles = [];
    const cssFiles = [];
    const assetsFile = any.listOf(any.word)
      .map(key => {
        const jsFile = any.string();
        const cssFile = any.string();
        jsFiles.push(jsFile);
        cssFiles.push(cssFile);
        return {[key]: {js: jsFile, css: cssFile}};
      })
      .reduce((acc, entry) => ({...acc, ...entry}), {});
    fs.readFile
      .withArgs(path.resolve(__dirname, '../../../../webpack-assets.json'), 'utf-8')
      .yields(null, JSON.stringify(assetsFile));

    return getAssets().then(assets => {
      jsFiles.forEach(file => assert.include(assets.js, file));
      cssFiles.forEach(file => assert.include(assets.css, file));
    });
  });

  test('that an error loading the assets file results in rejection', () => {
    const msg = 'from test';
    const error = new Error(msg);
    fs.readFile.yields(error);<commit_msg>test(stability): prevented random match failures due to special characters<commit_after>import {assert} from 'chai';
import sinon from 'sinon';
import any from '@travi/any';
import fs from 'fs';
import path from 'path';
import getAssets from '../../../../lib/server/view/asset-manager';

suite('asset manager', () => {
  let sandbox;

  setup(() => {
    sandbox = sinon.sandbox.create();

    sandbox.stub(fs, 'readFile');
  });

  teardown(() => sandbox.restore());

  test('that the asset list is returned based on the webpack assets file', () => {
    const jsFiles = [];
    const cssFiles = [];
    const assetsFile = any.listOf(any.word)
      .map(key => {
        const jsFile = any.word();
        const cssFile = any.word();
        jsFiles.push(jsFile);
        cssFiles.push(cssFile);
        return {[key]: {js: jsFile, css: cssFile}};
      })
      .reduce((acc, entry) => ({...acc, ...entry}), {});
    fs.readFile
      .withArgs(path.resolve(__dirname, '../../../../webpack-assets.json'), 'utf-8')
      .yields(null, JSON.stringify(assetsFile));

    return getAssets().then(assets => {
      jsFiles.forEach(file => assert.include(assets.js, file));
      cssFiles.forEach(file => assert.include(assets.css, file));
    });
  });

  test('that an error loading the assets file results in rejection', () => {
    const msg = 'from test';
    const error = new Error(msg);
    fs.readFile.yields(error);
{'fraction_non_alphanumeric': 0.18550412630068175, 'fraction_numerical': 0.0007176175098672408, 'mean_word_length': 2.9322990126939352, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4544678', 'n_tokens_mistral': 875, 'n_tokens_neox': 862, 'n_words': 219}