 # to require modules for testing
 gulp.task 'build-test', ['clean'], ->
   testHeader = """
-# not done under karma webpack tests
+# no module.path under karma webpack tests
+# but we handle the paths in the webpack conf
 if module.paths
   module.paths.unshift process.cwd() + "/lib"
 

# lint clean and build everything
gulp.task 'build', ['lint', 'clean', 'build-lib', 'build-test']

# helper to run coverage generation with given options
runCoverage = (opts) ->
  gulp.src(['test/helpers/**/*.js', 'test/spec/**/*.js'], read: false)
    .pipe($.coverage.instrument
      pattern: ['lib/**/*.js', '!node_modules']
      debugDirectory: 'debug')
    .pipe($.mocha reporter: 'dot').on('error', (e) -> @emit 'end') # test errors dropped
    .pipe($.coverage.gather())
    .pipe($.coverage.format opts)

runTest = (opts) ->
  gulp.src(['test/helpers/**/*.js', 'test/spec/**/*.js'], read: false)
    .pipe($.mocha opts).on('error', (e) -> @emit 'end') # test errors dropped

# test and create coverage
gulp.task 'coverage', ['build'], ->

  runCoverage(reporter: 'lcov')
    .pipe($.coveralls())

# run tests but only show progress
gulp.task 'test-quiet', ['build'], ->
  runTest gulp.src(testFiles), reporter: 'dot'

# run and display all tests
gulp.task 'test', ['build'], ->
  runTest gulp.src(testFiles), reporter: 'spec'

# run tests from phantomjs with karma
gulp.task 'karma', ['test-quiet'], (done) ->
  karma.start
    configFile: require('path').join __dirname, './karma.conf.js'
    singleRun: true
  , done

# uses chrome and firefox
gulp.task 'karma-gui', ['test-quiet'], (done) ->
  karma.start
    configFile: require('path').join __dirname, './karma.conf.js'
