<commit_before>import should from 'should'
import rump from '../src'
import {EventEmitter} from 'events'
import {resolve} from 'path'
import {spy} from 'sinon'

describe('rump', () => {
  beforeEach(() => {
    delete rump.taskPrefix
    rump.configure()
    rump.removeAllListeners('update:main')
  })

  it('', () => {
    rump.should.be.an.instanceof(EventEmitter)
  })

  it('.autoload', () => {
    const module1 = resolve('node_modules/rump-a/index.js'),
          module2 = resolve('node_modules/rump-b/index.js'),
          module3 = resolve('node_modules/rumpc/index.js')
    should(require.cache[module1]).not.be.ok()
    should(require.cache[module2]).not.be.ok()
    should(require.cache[module3]).not.be.ok()
    rump.autoload()
    should(require.cache[module1]).be.ok()
    should(require.cache[module2]).be.ok()
    should(require.cache[module3]).not.be.ok()
    require('rumpc')
    should(require.cache[module3]).be.ok()
  })

  it('.configure', () => {
    const callback = spy(),
          defaultConfig = {...rump.configs.main}
    rump.on('update:main', callback)
    rump.configure.should.be.a.Function()
    rump.configure({environment: 'production'})
    callback.should.be.calledOnce()
    rump.configs.main.should.not.eql(defaultConfig)
    rump.configure()
    callback.should.be.calledTwice()
    rump.configs.main.should.eql(defaultConfig)
  })

  it('.reconfigure', () => {
    const callback = spy(),<commit_msg>Cover situation where rump module is unavailable<commit_after>import should from 'should'
import thenify from 'thenify'
import trashWithCallback from 'trash'
import rump from '../src'
import {EventEmitter} from 'events'
import {exists} from 'mz/fs'
import {resolve} from 'path'
import {spy} from 'sinon'

const trash = thenify(trashWithCallback)

describe('rump', () => {
  beforeEach(() => {
    delete rump.taskPrefix
    rump.configure()
    rump.removeAllListeners('update:main')
  })

  it('', () => {
    rump.should.be.an.instanceof(EventEmitter)
  })

  it('.autoload', async() => {
    const module1 = resolve('node_modules/rump-a/index.js'),
          module2 = resolve('node_modules/rump-b/index.js'),
          module3 = resolve('node_modules/rumpc/index.js')
    should(require.cache[module1]).not.be.ok()
    should(require.cache[module2]).not.be.ok()
    should(require.cache[module3]).not.be.ok()
    if(await exists('node_modules/rump-b')) {
      await trash(['node_modules/rump-b'])
    }
    rump.autoload()
    should(require.cache[module1]).be.ok()
    should(require.cache[module2]).not.be.ok()
    should(require.cache[module3]).not.be.ok()
    require('rumpc')
    should(require.cache[module3]).be.ok()
  })

  it('.configure', () => {
    const callback = spy(),
          defaultConfig = {...rump.configs.main}
    rump.on('update:main', callback)
    rump.configure.should.be.a.Function()
    rump.configure({environment: 'production'})
    callback.should.be.calledOnce()
    rump.configs.main.should.not.eql(defaultConfig)
    rump.configure()
    callback.should.be.calledTwice()
    rump.configs.main.should.eql(defaultConfig)
  })

  it('.reconfigure', () => {
    const callback = spy(),
{'fraction_non_alphanumeric': 0.17782691092861655, 'fraction_numerical': 0.006317119393556538, 'mean_word_length': 3.616618075801749, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '7267385', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1078, 'n_words': 155}