<commit_before>/* eslint-env mocha */

'use strict';

const assert = require('assert');
const proxyquire = require('proxyquire');

let readFileMock;
let writeFileArgs;
let writeFileMock;
let writeFileSyncArgs;
const makeArt =
proxyquire
(
    '../make-art',
    {
        fs:
        {
            readFile(...args)
            {
                readFileMock.apply(this, args);
            },
            writeFile(...args)
            {
                writeFileArgs = args;
                if (writeFileMock)
                    writeFileMock();
            },
            writeFileSync(...args)
            {
                writeFileSyncArgs = args;
            },
        },
    },
);

afterEach
(
    () =>
    {
        readFileMock = writeFileArgs = writeFileMock = writeFileSyncArgs = undefined;
    },
);

describe
(
    'makeArt',
    () =>
    {
        it
        (
            'creates art.js',
            () =>
            {
                const expectedPath = 'test';
                makeArt(expectedPath);
                const [actualPath, actualData] = writeFileSyncArgs;
                assert.strictEqual(actualPath, expectedPath);
                assert.equal(typeof actualData, 'string');
            },
        );
        it
        (
            'fails for missing path',
            () =>
            {
                assert.throws(makeArt, isMissingPathError);
                assert(!writeFileSyncArgs);
            },
        );
    },
);

describe
(
    'makeArt.async',
    () =>
    {
        it
        (
            'creates art.js',
            done =>
            {
                const expectedPath = 'test';
                const expectedCallback = Function();
                readFileMock = (file, callback) => callback(null, 'DATA');
                writeFileMock =
                () =>
                {
                    const [actualPath, actualData, actualCallback] = writeFileArgs;
                    assert.strictEqual(actualPath, expectedPath);
                    assert.equal(typeof actualData, 'string');
                    assert.strictEqual(actualCallback, expectedCallback);
                    done();
                };
                makeArt.async(expectedPath, null, expectedCallback);<commit_msg>Update make-art.spec.js<commit_after>/* eslint-env mocha */

'use strict';

const assert = require('assert');
const proxyquire = require('proxyquire');
const { promisify } = require('util');

let readFileMock;
let writeFileArgs;
let writeFileMock;
let writeFileSyncArgs;
const makeArt =
proxyquire
(
    '../make-art',
    {
        fs:
        {
            readFile(...args)
            {
                readFileMock.apply(this, args);
            },
            writeFile(...args)
            {
                writeFileArgs = args;
                if (writeFileMock)
                    writeFileMock(...args);
            },
            writeFileSync(...args)
            {
                writeFileSyncArgs = args;
            },
        },
    },
);

afterEach
(
    () =>
    {
        readFileMock = writeFileArgs = writeFileMock = writeFileSyncArgs = undefined;
    },
);

describe
(
    'makeArt',
    () =>
    {
        it
        (
            'creates art.js',
            () =>
            {
                const expectedPath = 'test';
                makeArt(expectedPath);
                const [actualPath, actualData] = writeFileSyncArgs;
                assert.strictEqual(actualPath, expectedPath);
                assert.equal(typeof actualData, 'string');
            },
        );
        it
        (
            'fails for missing path',
            () =>
            {
                assert.throws(makeArt, isMissingPathError);
                assert(!writeFileSyncArgs);
            },
        );
    },
);

describe
(
    'makeArt.async',
    () =>
    {
        it
        (
            'creates art.js with 2 arguments',
            async () =>
            {
                const expectedPath = 'test';
                readFileMock = (file, callback) => callback(null);
                writeFileMock = (file, data, callback) => callback(null);
                await promisify(makeArt.async)(expectedPath);
                const [actualPath, actualData] = writeFileArgs;
                assert.strictEqual(actualPath, expectedPath);
                assert.equal(typeof actualData, 'string');
            },
        );
        it
        (
            'creates art.js with 3 arguments',
            async () =>
            {
                const expectedPath = 'test';
                readFileMock = (file, callback) => callback(null);
                writeFileMock = (file, data, callback) => callback(null);
                await promisify(makeArt.async)(expectedPath, null);
                const [actualPath, actualData] = writeFileArgs;
                assert.strictEqual(actualPath, expectedPath);
                assert.equal(typeof actualData, 'string');
{'fraction_non_alphanumeric': 0.1130820399113082, 'fraction_numerical': 0.00040314452731304173, 'mean_word_length': 1.3132867132867132, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '6162545', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1250, 'n_words': 236}