Skip to content
Permalink
Browse files

feat(api tasks): create and expose api tasks dev:test and dev:test:se…

…rver
  • Loading branch information
jyounce committed Oct 5, 2015
1 parent 702ae85 commit b84bea06402c1c658ae4af69de91cc43ab1eb10a
@@ -18,6 +18,37 @@ module.exports = (gulp, config) ->
cb
) -> defer.resolve()

# test default - client and server
# ================================
gulp.task config.rb.tasks['test'], ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
config.rb.tasks['test:client']
config.rb.tasks['test:server']
cb
) -> defer.resolve()

# test default - client
# =====================
gulp.task config.rb.tasks['test:client'], ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
"#{config.rb.prefix.task}common-client"
"#{config.rb.prefix.task}build-spa"
"#{config.rb.prefix.task}common-test-client"
"#{config.rb.prefix.task}run-client-tests"
cb
) -> defer.resolve() unless task.wasCalledFrom config.rb.tasks['test']

# test default - server
# =====================
gulp.task config.rb.tasks['test:server'], ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
"#{config.rb.prefix.task}common-server"
"#{config.rb.prefix.task}start-server"
"#{config.rb.prefix.task}common-test-server"
"#{config.rb.prefix.task}stop-server"
cb
) -> defer.resolve() unless task.wasCalledFrom config.rb.tasks['test']

# dev
# ===
gulp.task config.rb.tasks.dev, ["#{config.rb.prefix.task}common"], (cb) ->
@@ -31,6 +62,35 @@ module.exports = (gulp, config) ->
cb
) -> defer.resolve()

# test dev - client and server
# ============================
gulp.task config.rb.tasks['dev:test'], ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
"#{config.rb.prefix.task}common-client"
"#{config.rb.prefix.task}build-spa"
"#{config.rb.prefix.task}common-test-client"
"#{config.rb.prefix.task}run-client-tests:dev"
"#{config.rb.prefix.task}common-server"
"#{config.rb.prefix.task}copy-server-tests"
"#{config.rb.prefix.task}start-server:dev"
"#{config.rb.prefix.task}browser-sync"
"#{config.rb.prefix.task}run-server-tests:dev"
"#{config.rb.prefix.task}watch"
cb
) -> defer.resolve()

# test dev - client
# =================
gulp.task config.rb.tasks['dev:test:client'], ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
"#{config.rb.prefix.task}common-client"
"#{config.rb.prefix.task}build-spa"
"#{config.rb.prefix.task}common-test-client"
"#{config.rb.prefix.task}run-client-tests:dev"
"#{config.rb.prefix.task}watch"
cb
) -> defer.resolve()

# test dev - server
# =================
gulp.task config.rb.tasks['dev:test:server'], ["#{config.rb.prefix.task}common"], (cb) ->
@@ -39,10 +99,10 @@ module.exports = (gulp, config) ->
"#{config.rb.prefix.task}copy-server-tests"
"#{config.rb.prefix.task}start-server:dev"
"#{config.rb.prefix.task}browser-sync"
"#{config.rb.prefix.task}run-server-tests:dev"
"#{config.rb.prefix.task}watch"
"#{config.rb.prefix.task}run-server-tests"
cb
) -> defer.resolve() unless task.wasCalledFrom config.rb.tasks['dev:test']
) -> defer.resolve()

# prod
# ====
@@ -66,36 +126,6 @@ module.exports = (gulp, config) ->
cb
) -> defer.resolve()

# test default - client and server
# ================================
gulp.task config.rb.tasks['test'], ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
config.rb.tasks['test:client']
config.rb.tasks['test:server']
cb
) -> defer.resolve()

# test default - client
# =====================
gulp.task config.rb.tasks['test:client'], ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
"#{config.rb.prefix.task}common-client"
"#{config.rb.prefix.task}build-spa"
"#{config.rb.prefix.task}common-test-client"
cb
) -> defer.resolve() unless task.wasCalledFrom config.rb.tasks['test']

# test default - server
# =====================
gulp.task config.rb.tasks['test:server'], ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
"#{config.rb.prefix.task}common-server"
"#{config.rb.prefix.task}start-server"
"#{config.rb.prefix.task}common-test-server"
"#{config.rb.prefix.task}stop-server"
cb
) -> defer.resolve() unless task.wasCalledFrom config.rb.tasks['test']

# test prod - client and server
# =============================
gulp.task config.rb.tasks['prod:test'], ["#{config.rb.prefix.task}common"], (cb) ->
@@ -112,6 +142,7 @@ module.exports = (gulp, config) ->
"#{config.rb.prefix.task}common-client"
"#{config.rb.prefix.task}minify-client"
"#{config.rb.prefix.task}common-test-client"
"#{config.rb.prefix.task}run-client-tests"
"#{config.rb.prefix.task}clean-client-test-dist"
cb
) -> defer.resolve() unless task.wasCalledFrom config.rb.tasks['prod:test']
@@ -16,7 +16,6 @@ module.exports = (gulp, config) ->
]
"#{config.rb.prefix.task}copy-client-tests"
"#{config.rb.prefix.task}build-client-test-files"
"#{config.rb.prefix.task}run-client-tests"
cb
)

@@ -1,9 +1,10 @@
module.exports = (gulp, config) ->
q = require 'q'
babel = require 'gulp-babel'
coffee = require 'gulp-coffee'
plumber = require 'gulp-plumber'
tasks = require("#{config.req.helpers}/tasks")()
module.exports = (gulp, config, watchFile={}) ->
q = require 'q'
babel = require 'gulp-babel'
coffee = require 'gulp-coffee'
plumber = require 'gulp-plumber'
tasks = require("#{config.req.helpers}/tasks")()
forWatchFile = !!watchFile.path

coffeeTask = (src, dest) ->
defer = q.defer()
@@ -30,6 +31,24 @@ module.exports = (gulp, config) ->
.on 'end', -> defer.resolve()
defer.promise

compileWatchFile = ->
ext = watchFile.extname.replace '.', ''
src = watchFile.path
dest = watchFile.rbDistDir
switch ext
when 'js' then jsTask src, dest
when 'es6' then es6Task src, dest
when 'coffee' then coffeeTask src, dest

runSingle = -> # synchronously
defer = q.defer()
tasks = [
-> compileWatchFile()
# -> runTest gulp, config, watchFile.rbDistPath
]
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise

runMulti = ->
defer = q.defer()
q.all([
@@ -41,5 +60,10 @@ module.exports = (gulp, config) ->

# register task
# =============
return runSingle() if forWatchFile

gulp.task "#{config.rb.prefix.task}copy-client-tests", ->
runMulti()
runMulti()



@@ -11,7 +11,7 @@ module.exports = (gulp, config) ->

# Global
# ======
TestResults = status: null, exitCode: null
TestResults = status: 'passed', total: 0, passed: 0, failed: 0

# helpers
# =======
@@ -30,6 +30,38 @@ module.exports = (gulp, config) ->
reporters: ['dots']
singleRun: true

formatScripts = (_scripts) ->
scripts = []
tests = config.glob.dist.app.client.test.js[0]
for script in _scripts
isTest = script.indexOf(config.dist.app.client.test.dir) isnt -1
continue if isTest
isAppScript = script.indexOf(config.dist.app.client.scripts.dir) isnt -1
watched = isAppScript
scripts.push { watched, pattern: script }
scripts.push { watched: true, pattern: tests }
scripts

updateTestResults = (results) ->
TestResults.status = if !!results.exitCode then 'failed' else 'passed'
TestResults.total = results.success + results.failed
TestResults.passed = results.success
TestResults.failed = results.failed
TestResults

hasTestsCheck = (cnt) ->
return true if cnt
console.log 'no test scripts to run'.yellow
false

startKarmaServer = (karmaConfig, defer) ->
server = new Server karmaConfig, (exitCode) ->
server.start()
server.on 'run_complete', (browsers, results) ->
updateTestResults results
defer.resolve()
server

# tasks
# =====
cleanResultsFile = (src) ->
@@ -42,20 +74,21 @@ module.exports = (gulp, config) ->
defer = q.defer()
tests = getTestsFile()
karmaConfig = getKarmaConfig()
testCnt = tests.scriptsTestCount
return promiseHelp.get defer unless hasTestsCheck testCnt
karmaConfig.files = tests.scripts
startKarmaServer karmaConfig, defer
defer.promise

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

server = new Server karmaConfig, (exitCode) ->
# console.log "karma has exited with #{exitCode}".yellow
TestResults.status = if not exitCode then 'passed' else 'failed'
TestResults.exitCode = exitCode
defer.resolve()

server.start()
runDevTests = ->
defer = q.defer()
tests = getTestsFile()
karmaConfig = getKarmaConfig()
testCnt = tests.scriptsTestCount
karmaConfig.files = formatScripts tests.scripts
karmaConfig.autoWatch = true
karmaConfig.singleRun = false
startKarmaServer karmaConfig, defer
defer.promise

writeResultsFile = (file) ->
@@ -70,7 +103,7 @@ module.exports = (gulp, config) ->
console.error msg.error
.exit 1

runTask = -> # synchronously
runDefaultTask = -> # synchronously
defer = q.defer()
tasks = [
-> cleanResultsFile resultsFile
@@ -81,10 +114,28 @@ module.exports = (gulp, config) ->
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise

runDevTask = -> # synchronously
defer = q.defer()
tasks = [
-> cleanResultsFile resultsFile
-> runDevTests()
]
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise

runTask = (isDev) ->
return promiseHelp.get() unless config.build.client
return promiseHelp.get() if config.exclude.angular.files
return runDevTask() if isDev
runDefaultTask()

# register task
# =============
gulp.task "#{config.rb.prefix.task}run-client-tests", ->
runTask()

gulp.task "#{config.rb.prefix.task}run-client-tests:dev", ->
runTask true



@@ -47,12 +47,28 @@ module.exports = (gulp, config, watchFilePath) ->
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise

runMultiDev = -> # synchronously
defer = q.defer()
tasks = [
-> cleanResultsFile resultsFile
-> runTests config.glob.dist.app.server.test.js
]
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise

runTask = (isDev) ->
return promiseHelp.get() unless config.build.server
return runMultiDev() if isDev
runMulti()

# register task
# =============
return runSingle watchFilePath if forWatchFile

gulp.task "#{config.rb.prefix.task}run-server-tests", ->
return promiseHelp.get() unless config.build.server
runMulti()
runTask()

gulp.task "#{config.rb.prefix.task}run-server-tests:dev", ->
runTask true


@@ -18,7 +18,9 @@ module.exports = (gulp, config, browserSync) ->
less: require "#{config.req.tasks}/compile/less"
sass: require "#{config.req.tasks}/compile/sass"
tCache: require "#{config.req.tasks}/minify/template-cache"
clientTest: require "#{config.req.tasks}/test/client/copy-client-tests"
serverTest: require "#{config.req.tasks}/test/server/copy-server-tests"

buildSpa: ->
return promiseHelp.get() unless config.build.client
gulp.start "#{config.rb.prefix.task}watch-build-spa"
@@ -76,7 +78,7 @@ module.exports = (gulp, config, browserSync) ->
addAndUnlinkTask = (taskName, file, opts) ->
return changeTask taskName, file if opts.taskOnly
tasks[taskName](gulp, config, file).then ->
return promiseHelp.get() if opts.loc is 'server' and opts.isTest
return promiseHelp.get() if opts.isTest
return tasks.browserSync() if opts.bsReload or opts.loc is 'server'
if taskName is 'clean' and opts.cleanCb
opts.cleanCb(file).then -> tasks.buildSpa()
@@ -148,17 +150,19 @@ module.exports = (gulp, config, browserSync) ->
-> spaWatch config.spa.src.path
]
serverWatches = [ # server watch: scripts
-> createWatch config.glob.src.app.server.scripts.coffee, 'coffee', lang:'coffee', srcType:'scripts', extDist:'js', loc:'server'
-> createWatch config.glob.src.app.server.scripts.es6, 'es6', lang:'es6', srcType:'scripts', extDist:'js', loc:'server'
-> createWatch config.glob.src.app.server.scripts.js, 'js', lang:'js', srcType:'scripts', loc:'server'
-> createWatch config.glob.src.app.server.scripts.es6, 'es6', lang:'es6', srcType:'scripts', extDist:'js', loc:'server'
-> createWatch config.glob.src.app.server.scripts.coffee, 'coffee', lang:'coffee', srcType:'scripts', extDist:'js', loc:'server'
]
clientTestWatches = [

-> createWatch config.glob.src.app.client.test.js, 'clientTest', lang:'js', srcType:'test', isTest:true, logTaskName:'client test'
-> createWatch config.glob.src.app.client.test.es6, 'clientTest', lang:'es6', srcType:'test', extDist:'js', isTest:true, logTaskName:'client test'
-> createWatch config.glob.src.app.client.test.coffee, 'clientTest', lang:'coffee', srcType:'test', extDist:'js', isTest:true, logTaskName:'client test'
]
serverTestWatches = [
-> createWatch config.glob.src.app.server.test.coffee, 'serverTest', lang:'coffee', srcType:'test', extDist:'js', loc:'server', isTest:true, logTaskName:'server test'
-> createWatch config.glob.src.app.server.test.es6, 'serverTest', lang:'es6', srcType:'test', extDist:'js', loc:'server', isTest:true, logTaskName:'server test'
-> createWatch config.glob.src.app.server.test.js, 'serverTest', lang:'js', srcType:'test', loc:'server', isTest:true, logTaskName:'server test'
-> createWatch config.glob.src.app.server.test.es6, 'serverTest', lang:'es6', srcType:'test', extDist:'js', loc:'server', isTest:true, logTaskName:'server test'
-> createWatch config.glob.src.app.server.test.coffee, 'serverTest', lang:'coffee', srcType:'test', extDist:'js', loc:'server', isTest:true, logTaskName:'server test'
]

# setup watch rules

0 comments on commit b84bea0

Please sign in to comment.
You can’t perform that action at this time.