Skip to content

Commit

Permalink
fix(testing): do not run tests if there are no test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jyounce committed Jul 16, 2015
1 parent 805e598 commit 227ec95
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
7 changes: 6 additions & 1 deletion tasks/build/build-test-files.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ module.exports = (gulp, config) ->
# Global Objects
# ==============
DevFiles = {}
TestFiles = client: scripts: [], styles: []
TestFiles = client:
scriptsTestCount: 0
stylesTestCount: 0
scripts: []
styles: []

# Build Task
# ==========
Expand Down Expand Up @@ -42,6 +46,7 @@ module.exports = (gulp, config) ->
gulp.src src, buffer: false
.on 'data', (file) ->
_path = pathHelp.format(file.path).replace "#{appDir}/", ''
TestFiles.client["#{type}TestCount"]++
TestFiles.client[type].push _path
.on 'end', ->
defer.resolve()
Expand Down
42 changes: 35 additions & 7 deletions tasks/test/run-tests.coffee
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
module.exports = (gulp, config) ->
q = require 'q'
Server = require('karma').Server
q = require 'q'
path = require 'path'
Server = require('karma').Server
moduleHelp = require "#{config.req.helpers}/module"
promiseHelp = require "#{config.req.helpers}/promise"

# karma options
# =============
opts =
configFile: "#{config.req.tasks}/test/test-config.coffee"
karmaConfig =
autoWatch: false
basePath: config.app.dir
browsers: config.test.browsers # see config-test.coffee
frameworks: ['jasmine', 'jasmine-matchers']
port: config.ports.test
reporters: ['dots']
singleRun: true

# helpers
# =======
getTests = (jsonEnvFile) ->
jsonEnvFile = path.join config.templates.files.dest.dir, jsonEnvFile
moduleHelp.cache.delete jsonEnvFile
tests = require(jsonEnvFile).client
tests

# register task
# =============
gulp.task "#{config.rb.prefix.task}run-tests", ->
defer = q.defer()
server = new Server opts, (exitCode) ->
console.log "Karma has exited with #{exitCode}."
defer = q.defer()
tests = getTests 'test-files.json'

# No Test Scripts
if not tests.scriptsTestCount
console.log 'no test scripts to run'.yellow
return promiseHelp.get defer
else
karmaConfig.files = tests.scripts

# Rus Tests
server = new Server(karmaConfig, (exitCode) ->
console.log "karma has exited with #{exitCode}".yellow
defer.resolve()
process.exit exitCode
)
server.start()
defer.promise

Expand Down
25 changes: 0 additions & 25 deletions tasks/test/test-config.coffee

This file was deleted.

0 comments on commit 227ec95

Please sign in to comment.