<commit_before>/* eslint-dev mocha */
const fs = require('fs-extra')

const { configure } = require('../lib/binding')
const { Fixture } = require('./helper')

describe('configuration', function () {
  let fixture, badPath

  beforeEach(async function () {
    fixture = new Fixture()
    await fixture.before()

    badPath = fixture.fixturePath('bad', 'path.log')
  })

  afterEach(async function () {
    await fixture.after(this.currentTest)
  })

  it('validates its arguments', async function () {
    await assert.isRejected(configure(), /requires an option object/)
  })

  it('configures the main thread logger', async function () {
    await configure({ mainLog: fixture.mainLogFile })

    const contents = await fs.readFile(fixture.mainLogFile)
    assert.match(contents, /FileLogger opened/)
  })

  it('configures the worker thread logger', async function () {
    await configure({ workerLog: fixture.workerLogFile })

    const contents = await fs.readFile(fixture.workerLogFile)
    assert.match(contents, /FileLogger opened/)
  })

  it('fails if the main log file cannot be written', async function () {
    await assert.isRejected(configure({ mainLog: badPath }), /No such file or directory/)
  })

  it('fails if the worker log file cannot be written', async function () {
    await assert.isRejected(configure({ workerLog: badPath }), /No such file or directory/)
  })
<commit_msg>Adjust worker configuration tests to its asynchronicity<commit_after>/* eslint-dev mocha */
const fs = require('fs-extra')

const { configure } = require('../lib/binding')
const { Fixture } = require('./helper')

describe('configuration', function () {
  let fixture, badPath

  beforeEach(async function () {
    fixture = new Fixture()
    await fixture.before()

    badPath = fixture.fixturePath('bad', 'path.log')
  })

  afterEach(async function () {
    await fixture.after(this.currentTest)
  })

  it('validates its arguments', async function () {
    await assert.isRejected(configure(), /requires an option object/)
  })

  it('configures the main thread logger', async function () {
    await configure({ mainLog: fixture.mainLogFile })

    const contents = await fs.readFile(fixture.mainLogFile)
    assert.match(contents, /FileLogger opened/)
  })

  it('fails if the main log file cannot be written', async function () {
    await assert.isRejected(configure({ mainLog: badPath }), /No such file or directory/)
  })

  describe('for the worker thread', function () {
    // There's currently no way to *stop* the worker thread, so we can't reliably test it in the stopped state.

    describe("after it's started", function () {
      it('configures the logger', async function () {
        await fixture.watch([], { poll: false }, () => {})

        await configure({ workerLog: fixture.workerLogFile })

        const contents = await fs.readFile(fixture.workerLogFile)
        assert.match(contents, /FileLogger opened/)
      })

      it('fails if the worker log file cannot be written', async function () {
        await fixture.watch([], { poll: false }, () => {})

        await assert.isRejected(configure({ workerLog: badPath }), /No such file or directory/)
      })
    })
  })

{'fraction_non_alphanumeric': 0.13248129675810474, 'fraction_numerical': 0.0, 'mean_word_length': 3.5582386363636362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7119786', 'n_tokens_mistral': 912, 'n_tokens_neox': 898, 'n_words': 280}