-util = require 'util'
+sys = require 'sys'
 fs = require 'fs'
 path = require 'path'
 coffee = require 'coffee-script'


helpers = require './helpers'
{TerminalReporter} = require '../vendor/reporter'


# TODO: find a better way to do this.
# https://github.com/brunch/brunch/pull/111#issuecomment-2244266
TEMP = '/tmp/brunchtest'
SPECFILE = path.join TEMP, 'specs.js'


exports.run = (options, callback) ->

        getSpecFiles filepath

  getSpecFiles testdir

  # Run specs in fake browser.
  jsdom.env
    html: path.join brunchdir, 'index.html'
    scripts: [
      path.resolve options.buildPath, 'web/js/app.js'
      path.resolve __dirname, '../vendor/jasmine.js'
    ]
    src: specs
    done: (error, window) ->
      helpers.logError error if error?
      # If we're testing brunch itself, we don't need to view the output.
      # TODO: move this to TerminalReporter.
      stream = if global.jasmine then (->) else sys.print

      jasmineEnv = window.jasmine.getEnv()
      jasmineEnv.reporter = new TerminalReporter
        print: stream
        verbose: options.verbose
        color: yes
        onComplete: null
        stackFilter: null
      jasmineEnv.execute()
      callback?()
