<commit_before>expect = require('chai').expect
ChildProcess = require './ChildProcess'
EventEmitter = require('events').EventEmitter

class Meteor extends EventEmitter

  childProcess: null
  buffer:
    stdout:""
    stderr:""


  constructor:(@rc)->
    expect(@rc.port).to.be.a 'number'


    unless @rc.packages
      log.error "no packages to test have been specified"


  run: =>
    log.info("spawning meteor")
    expect(@childProcess).to.be.null
    #meteor --settings $METEOR_TEST_SETTINGS_PATH test-packages packages/lavaina-base --driver-package test-in-console -p $PORT
    args = [
      "-p"
      @rc.port
      "test-packages"
      @rc.packages
      "--driver-package"
      "test-in-console"
    ]
    if @rc.settings_path?
      args.push "--settings"
      args.push @rc.settings_path

    options = {
      cwd:@rc.app_path,
      detached:false
    }

    @childProcess = new ChildProcess()
    @childProcess.spawn("meteor",args,options)
    
    @childProcess.child.stdout.on "data", (data) =>
      @buffer.stdout += data
      @hasErrorText @buffer.stdout
      @hasReadyText @buffer.stdout

    @childProcess.child.stderr.on "data", (data) =>
      @buffer.stderr += data
      @hasErrorText @buffer.stderr



  hasErrorText: ( buffer )=>
    log.debug buffer.lastIndexOf( @rc.meteor_error_text )
    if buffer.lastIndexOf( @rc.meteor_error_text ) isnt -1
      @emit "error"


  hasReadyText: ( buffer )=>
    log.debug "hasReadyText"
    if buffer.lastIndexOf( @rc.meteor_ready_text ) isnt -1
      @emit "ready"

  kill:->
    @childProcess?.child?.kill()


module.exports = Meteor
<commit_msg>Listen to each stdout message separately<commit_after>expect = require('chai').expect
ChildProcess = require './ChildProcess'
EventEmitter = require('events').EventEmitter

class Meteor extends EventEmitter

  childProcess: null
  buffer:
    stdout:""
    stderr:""


  constructor:(@rc)->
    expect(@rc.port).to.be.a 'number'


    unless @rc.packages
      log.error "no packages to test have been specified"


  run: =>
    log.info("spawning meteor")
    expect(@childProcess).to.be.null
    #meteor --settings $METEOR_TEST_SETTINGS_PATH test-packages packages/lavaina-base --driver-package test-in-console -p $PORT
    args = [
      "-p"
      @rc.port
      "test-packages"
      @rc.packages
      "--driver-package"
      "test-in-console"
    ]
    if @rc.settings_path?
      args.push "--settings"
      args.push @rc.settings_path

    options = {
      cwd:@rc.app_path,
      detached:false
    }

    @childProcess = new ChildProcess()
    @childProcess.spawn("meteor",args,options)

    @childProcess.child.stdout.on "data", (data) =>
      @buffer.stdout += data
      @hasErrorText data
      @hasReadyText data

    @childProcess.child.stderr.on "data", (data) =>
      @buffer.stderr += data
      @hasErrorText data



  hasErrorText: ( buffer )=>
    if buffer.lastIndexOf( @rc.meteor_error_text ) isnt -1 or buffer.lastIndexOf( @rc.meteor_crashing_text ) isnt -1
      @emit "error"


  hasReadyText: ( buffer )=>
    if buffer.lastIndexOf( @rc.meteor_ready_text ) isnt -1
      @emit "ready"

  kill:->
    @childProcess?.child?.kill()


module.exports = Meteor

{'fraction_non_alphanumeric': 0.13223397635345363, 'fraction_numerical': 0.0015556938394523958, 'mean_word_length': 2.818289786223278, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7084534', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1040, 'n_words': 215}