<commit_before>import EventEmitter from 'events'
import test from 'tape-promise/tape'
import { spy, stub } from 'sinon'

import plugin from '../src'

const files = [
  {
    path: 'foo',
    data: 'bar',
    map: null
  }
]

test('plugin: export', (t) => {
  t.equal(
    typeof plugin,
    'function',
    'must be a function'
  )

  t.end()
})

test('plugin: props', async (t) => {
  const name = 'testName'
  const pluginFn = stub().returns(files)
  const reporter = new EventEmitter()
  const beforeProps = { files, reporter }

  await plugin(name, pluginFn)(beforeProps)

  t.ok(
    pluginFn.calledOnce,
    'plugin function should be called once'
  )

  const afterProps = pluginFn.firstCall.args[0]

  t.deepEqual(
    afterProps.files,
    files,
    '`files` should be passed through'
  )

  t.deepEqual(
    afterProps.reporter,
    reporter,
    '`reporter` should be passed through'
  )

  t.equal(
    typeof afterProps.logMessage,
    'function',
    '`logMessage` should be a function'
  )

  t.equal(
    typeof afterProps.logFile,
    'function',
    '`logFile` should be a function'
  )
})

test('plugin: done', async (t) => {
  const name = 'testName'
  const pluginFn = stub().returns(files)
  const eventStartSpy = spy()
  const eventDoneSpy = spy()
  const reporter = new EventEmitter()
  const props = { files, reporter }

  reporter.on('start', eventStartSpy)
  reporter.on('done', eventDoneSpy)
<commit_msg>👾 plugin: test that result is extended with returned props<commit_after>import EventEmitter from 'events'
import test from 'tape-promise/tape'
import { spy, stub } from 'sinon'

import plugin from '../src'

const files = [
  {
    path: 'foo',
    data: 'bar',
    map: null
  }
]

test('plugin: export', (t) => {
  t.equal(
    typeof plugin,
    'function',
    'must be a function'
  )

  t.end()
})

test('plugin: props', async (t) => {
  const name = 'testName'
  const pluginFn = stub().returns({ bar: true })
  const reporter = new EventEmitter()
  const beforeProps = { foo: true, reporter }

  const result = await plugin(name, pluginFn)(beforeProps)

  t.ok(
    pluginFn.calledOnce,
    'plugin function should be called once'
  )

  const afterProps = pluginFn.firstCall.args[0]

  t.ok(
    afterProps.foo,
    'props should be passed through'
  )

  t.deepEqual(
    afterProps.reporter,
    reporter,
    '`reporter` should be passed through'
  )

  t.equal(
    typeof afterProps.logMessage,
    'function',
    '`logMessage` should be a function'
  )

  t.equal(
    typeof afterProps.logFile,
    'function',
    '`logFile` should be a function'
  )

  t.deepEqual(
    result,
    {
      foo: true,
      bar: true,
      reporter
    },
    'should extend result with returned props'
  )
})

test('plugin: done', async (t) => {
  const name = 'testName'
  const pluginFn = stub().returns(files)
  const eventStartSpy = spy()
  const eventDoneSpy = spy()
  const reporter = new EventEmitter()
  const props = { files, reporter }

  reporter.on('start', eventStartSpy)
  reporter.on('done', eventDoneSpy)

{'fraction_non_alphanumeric': 0.12986588158325155, 'fraction_numerical': 0.0006542361792607131, 'mean_word_length': 3.0664893617021276, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5603620', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1032, 'n_words': 288}