<commit_before>should = require 'should'
path = require 'path'
fs = require 'fs'
test_path = path.join(__dirname, 'fixtures/compile')
require('./helpers')(should)

Roots = require '../lib'

class Watcher
  constructor: (@root) ->
    @output = path.join(@root, 'public')

  compile_change_compare: (src, output, comp, cb) ->
    initalStamp = null
    first_compile = => initalStamp = @stat_file(output)

    @compile_and_change_file src, first_compile, (err) =>
      if err then return cb(err)
      initalStamp.should.be[comp](@stat_file(output))
      cb()

  compile_and_change_file: (file, first_compile, cb) ->
    count = 0
    new Roots(@root).watch()
      .on('error', cb)
      .on 'done', ->
        if ++count is 1 then return first_compile()
        cb()

    setTimeout =>
      p = path.join(@root, file)
      fs.appendFileSync(p, ' ')
      fs.writeFileSync(p, fs.readFileSync(p, 'utf8').trim())
    , 800 # paul miller, if you ever see this, wtf

  stat_file: (file) -><commit_msg>attempted fix for watcher tests on travis<commit_after>should = require 'should'
path = require 'path'
fs = require 'fs'
test_path = path.join(__dirname, 'fixtures/compile')
require('./helpers')(should)

Roots = require '../lib'

class Watcher
  constructor: (@root) ->
    @output = path.join(@root, 'public')

  compile_change_compare: (src, output, comp, cb) ->
    initalStamp = null
    first_compile = => initalStamp = @stat_file(output)

    @compile_and_change_file src, first_compile, (err) =>
      if err then return cb(err)
      initalStamp.should.be[comp](@stat_file(output))
      cb()

  compile_and_change_file: (file, first_compile, cb) ->
    count = 0
    new Roots(@root).watch()
      .on('error', cb)
      .on 'done', ->
        if ++count is 1 then return first_compile()
        cb()

    setTimeout =>
      p = path.join(@root, file)
      fs.appendFileSync(p, ' ')
      fs.writeFileSync(p, fs.readFileSync(p, 'utf8').trim())
    , 1000

  stat_file: (file) ->
{'fraction_non_alphanumeric': 0.15226130653266332, 'fraction_numerical': 0.006532663316582915, 'mean_word_length': 3.1827731092436973, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7025157', 'n_tokens_mistral': 692, 'n_tokens_neox': 673, 'n_words': 164}