Skip to content
Permalink
Browse files

feat(api tasks): create and expose api tasks test:client and test:ser…

…ver, change existing test task to run both
  • Loading branch information
jyounce committed Sep 27, 2015
1 parent 3fb6a78 commit 18db4deaf418e721ba864ff9e0f250025350357b
Showing with 602 additions and 333 deletions.
  1. +8 −4 README.md
  2. +14 −6 config/config-angular.coffee
  3. +0 −8 config/config-build.coffee
  4. +5 −2 config/config-dist-and-src.coffee
  5. +26 −4 config/config-env.coffee
  6. +14 −2 config/config-globs.coffee
  7. +10 −5 config/config-options.coffee
  8. +10 −6 config/config-rb.coffee
  9. +7 −3 config/config-test.coffee
  10. +2 −1 helpers/bower.coffee
  11. +7 −2 helpers/tasks.coffee
  12. +74 −27 init/rapid.coffee
  13. +73 −63 init/tasks.coffee
  14. +1 −0 package.json
  15. 0 src/server/test/.gitkeep
  16. +3 −5 tasks/build/build-angular-modules.coffee
  17. +10 −12 tasks/build/build-files.coffee
  18. +0 −37 tasks/common.coffee
  19. +34 −0 tasks/common/common-client.coffee
  20. +23 −0 tasks/common/common-server.coffee
  21. +22 −0 tasks/common/common-test-client.coffee
  22. +14 −0 tasks/common/common-test-server.coffee
  23. +19 −0 tasks/common/common.coffee
  24. +8 −4 tasks/compile/coffee.coffee
  25. +8 −4 tasks/compile/es6.coffee
  26. +0 −2 tasks/compile/less.coffee
  27. +0 −2 tasks/compile/sass.coffee
  28. +7 −0 tasks/config/set-env-config.coffee
  29. +28 −0 tasks/config/update-angular-mocks-config.coffee
  30. +0 −32 tasks/config/update-config.coffee
  31. +0 −1 tasks/copy/copy-bower_components.coffee
  32. +0 −2 tasks/copy/copy-css.coffee
  33. +0 −2 tasks/copy/copy-html.coffee
  34. +0 −2 tasks/copy/copy-images.coffee
  35. +8 −4 tasks/copy/copy-js.coffee
  36. +1 −3 tasks/copy/copy-libs.coffee
  37. +1 −3 tasks/copy/copy-server-config.coffee
  38. +1 −3 tasks/copy/copy-server-node_modules.coffee
  39. +8 −10 tasks/extra/compile-extra-coffee.coffee
  40. +8 −10 tasks/extra/compile-extra-es6.coffee
  41. +7 −5 tasks/extra/compile-extra-less.coffee
  42. +7 −5 tasks/extra/compile-extra-sass.coffee
  43. +7 −5 tasks/extra/copy-extra-files.coffee
  44. +0 −1 tasks/format/absolute-css-urls.coffee
  45. +0 −1 tasks/manage/bower.coffee
  46. +0 −2 tasks/minify/template-cache.coffee
  47. +9 −4 tasks/server/find-open-port.coffee
  48. +0 −2 tasks/server/nodemon.coffee
  49. +0 −2 tasks/server/spawn-server.coffee
  50. +15 −6 tasks/server/start-server.coffee
  51. +1 −1 tasks/test/{build-test-files.coffee → client/build-client-test-files.coffee}
  52. 0 tasks/test/{ → client}/build-inject-angular-mocks.coffee
  53. +3 −3 tasks/test/{clean-test-dist.coffee → client/clean-client-test-dist.coffee}
  54. +1 −1 tasks/test/{clean-rb-test-src.coffee → client/clean-rb-client-test-src.coffee}
  55. 0 tasks/test/{ → client}/copy-angular-mocks.coffee
  56. +1 −1 tasks/test/{copy-tests.coffee → client/copy-client-tests.coffee}
  57. +2 −2 tasks/test/{run-tests.coffee → client/run-client-tests.coffee}
  58. +0 −20 tasks/test/common-test.coffee
  59. +25 −0 tasks/test/server/clean-server-test-dist.coffee
  60. +45 −0 tasks/test/server/copy-server-tests.coffee
  61. +23 −0 tasks/test/server/run-server-tests.coffee
  62. +2 −1 tasks/watch/watch.coffee
@@ -20,7 +20,7 @@ rapid-build currently supports the following technologies:
* frameworks
* [angular](https://angularjs.org/) (client)
* [karma](http://karma-runner.github.io/) (client testing)
* [jasmine](http://jasmine.github.io/) (client testing)
* [jasmine](http://jasmine.github.io/) (client and server testing)
* [express](http://expressjs.com/) (server)
* package managers
* [bower](http://bower.io/) (client)
@@ -106,13 +106,15 @@ gulp rapid-build:test:prod
# dist.client.bower.dir = (string) defaults to 'bower_components'
# dist.client.libs.dir = (string) defaults to 'libs' = 3rd party libraries that aren't bower components
# dist.server.dir = (string) defaults to 'server'
# dist.server.test.dir = (string) defaults to 'test'
# dist.server.fileName = (string) defaults to 'routes.js': this is the server's entry script
# src.dir = (string) defaults to 'src'
# src.client.dir = (string) defaults to 'client'
# src.client[images|scripts|styles|test|views].dir = (string) defaults to property name
# src.client.bower.dir = (string) defaults to 'bower_components'
# src.client.libs.dir = (string) defaults to 'libs' = 3rd party libraries that aren't bower components
# src.server.dir = (string) defaults to 'server'
# src.server.test.dir = (string) defaults to 'test'
# ports.server = (int) defaults to 3000, web server port
# ports.reload = (int) defaults to 3001, browsersync server port
# ports.reloadUI = (int) defaults to 3002, browsersync's user-interface server port
@@ -150,7 +152,7 @@ gulp rapid-build:test:prod
# exclude.from.minFile[scripts|styles] = (array of strings) = file paths: exclude script or style files from automatically being generated in the scripts.min.js or styles.min.css file
# exclude.from.spaFile[scripts|styles] = (array of strings) = file paths: exclude script or style files from automatically being generated in the spa.html file
# exclude.from.dist[client|server] = (array of strings) = file paths: exclude client or server files from the dist folder
# test.browsers = (array of browser names) = phantomjs will run by default, optional browser names are ['chrome', 'firefox', 'ie', 'safari']
# test.client.browsers = (array of browser names) = phantomjs will run by default, optional browser names are ['chrome', 'firefox', 'ie', 'safari']
# server.node_modules = (array of module names) = node_modules you would like to copy to the server dist, example: ['q']
# httpProxy = (array of objects) = object format: { context: array or string, options: object } for details see: https://www.npmjs.com/package/http-proxy-middleware
# browser.open = (boolean) defaults to true = open the browser once the build completes, applies to builds: default, dev and prod:server
@@ -205,8 +207,10 @@ gulp rapid-build:test:prod

#### Test Build:
1. run common tasks (see above)
2. copy test scripts to dist/client/
3. run tests in [PhantomJS](http://phantomjs.org/)
2. copy client test scripts to dist/client/
3. run client tests in [PhantomJS](http://phantomjs.org/)
4. copy server test scripts to dist/server/
5. run server tests using [jasmine](http://jasmine.github.io/)

## Develop Rapidly!
![Shake and Bake!](https://raw.githubusercontent.com/jyounce/rapid-build/master/docs/shake-and-bake.jpg "Shake n' Bake!")
@@ -67,12 +67,20 @@ module.exports = (config, options) ->
else if not angular.httpBackend.dev
removeRbMocksModule()

angular.updateHttpBackendStatus = ->
if config.env.is.test and angular.httpBackend.dev
httpBackendEnabled = true
else if config.env.is.prod and angular.httpBackend.prod
httpBackendEnabled = true
config.angular.httpBackend.enabled = !!httpBackendEnabled
angular.updateHttpBackendStatus = -> # called in update-angular-mocks-config
isDefaultOrDev = config.env.is.defaultOrDev
isProd = config.env.is.prod
isTest = config.env.is.testClient
isTestProd = isProd and isTest
httpBackendDev = angular.httpBackend.dev
httpBackendProd = angular.httpBackend.prod
# the rules
enabled = true if isDefaultOrDev and httpBackendDev
enabled = true if isProd and httpBackendProd
enabled = true if isTest and httpBackendDev and not isProd
enabled = true if isTest and httpBackendProd and isProd

config.angular.httpBackend.enabled = !!enabled

# add angular to config
# =====================
@@ -16,14 +16,6 @@ module.exports = (config, options) ->
console.error msg.error
.exit 1

# methods
# =======
build.getLocs = ->
locs = []
locs.push 'client' if build.client
locs.push 'server' if build.server
locs

# add build to config
# ===================
config.build = build
@@ -42,6 +42,7 @@ module.exports = (config, options) ->
o.clientStyles = options[loc].client.styles.dir
o.clientTest = options[loc].client.test.dir
o.clientViews = options[loc].client.views.dir
o.serverTest = options[loc].server.test.dir

clientDirName = if loc is 'dist' then o.clientDir or dir.client else null
serverDirName = if loc is 'dist' then o.serverDir or dir.server else null
@@ -70,6 +71,8 @@ module.exports = (config, options) ->
dirName: serverDirName
scripts:
dir: o.serverDir or dir.scripts
test:
dir: o.serverTest or dir.test
if loc is 'dist'
unless isApp
info.client.dirName = config.rb.prefix.distDir
@@ -128,12 +131,12 @@ module.exports = (config, options) ->
continue if k1 is 'dir'
for own k2, v2 of v1
continue if k2 is 'dir'
continue if k2 is 'server'
for own k3, v3 of v2
continue if k3 is 'dirName'
continue if k3 is 'dir'
continue if k2 is 'server' and k3 isnt 'test'
if k1 is 'app'
v3.dirName = options[loc].client[k3].dir or dir[k3]
v3.dirName = options[loc][k2][k3].dir or dir[k3]
else
v3.dirName = dir[k3]
addDirName 'dist'
@@ -21,7 +21,22 @@ module.exports = (config) ->
when 'prod'
env.is.prod = true
when 'test'
env.is.test = true
env.is.testClient = true
env.is.testServer = true
when 'test:prod'
env.is.prod = true
env.is.testClient = true
env.is.testServer = true
when 'test:client'
env.is.testClient = true
when 'test:client:prod'
env.is.prod = true
env.is.testClient = true
when 'test:server'
env.is.testServer = true
when 'test:server:prod'
env.is.prod = true
env.is.testServer = true

# init env
# ========
@@ -35,15 +50,22 @@ module.exports = (config) ->
defaultOrDev: true
dev: false
prod: false
test: false
testClient: false
testServer: false

# methods
# =======
env.set = (gulp) ->
switch gulp.seq[2] # called in 'rb-update-config' which is called first in 'rb-common'
env.set = (taskSeqs) -> # called in 'set-env-config' which is called first in 'common'
switch taskSeqs[2]
when config.rb.tasks.dev then config.env.name = 'dev'
when config.rb.tasks.prod then config.env.name = 'prod'
when config.rb.tasks.test then config.env.name = 'test'
when config.rb.tasks['test:prod'] then config.env.name = 'test:prod'
when config.rb.tasks['test:client'] then config.env.name = 'test:client'
when config.rb.tasks['test:server'] then config.env.name = 'test:server'
when config.rb.tasks['test:client:prod'] then config.env.name = 'test:client:prod'
when config.rb.tasks['test:server:prod'] then config.env.name = 'test:server:prod'

setIsEnv()

# add env to config
@@ -58,10 +58,11 @@ module.exports = (config) ->
addGlob = (loc, type, langs, includeBower, includeLibs) ->
for own k1, v1 of glob[loc]
for own k2, v2 of v1
continue if k2 is 'server' and type isnt 'scripts'
continue if k2 is 'server' and ['scripts','test'].indexOf(type) is -1
continue if k2 is 'server' and (includeBower or includeLibs)
v2[type] = {} if not isType.object v2[type]
langs.forEach (v3) ->
for v3 in langs
continue if k2 is 'server' and type is 'test' and v3 is 'css'
typeDir = pathHelp.format config[loc][k1][k2][type].dir
if includeBower or includeLibs
bowerDir = pathHelp.format config[loc][k1][k2]['bower'].dir
@@ -115,6 +116,17 @@ module.exports = (config) ->
excludeSpaSrc 'libs', 'all'
excludeSpaSrc 'views', 'html'

# exclude server tests
# ====================
excludeServerTests = ->
for appOrRb in ['app','rb']
exclude = path.join config.src[appOrRb].server.test.dir, '**'
exclude = "!#{exclude}"
for own k1, v1 of glob.src[appOrRb].server.scripts
v1.push exclude

excludeServerTests()

# cache bust
# ==========
addCacheBust = (type, lang) ->
@@ -19,11 +19,15 @@ module.exports = (config, options) ->
# dir
options[v1][v2] = {} unless isType.object options[v1][v2]
options[v1][v2].dir = null unless isType.string options[v1][v2].dir
return if v2 is 'server'
# types dir
['bower', 'images', 'libs', 'scripts', 'styles', 'test', 'views'].forEach (v3) ->
options[v1][v2][v3] = {} unless isType.object options[v1][v2][v3]
options[v1][v2][v3].dir = null unless isType.string options[v1][v2][v3].dir
if v2 is 'server'
['test'].forEach (v3) ->
options[v1][v2][v3] = {} unless isType.object options[v1][v2][v3]
options[v1][v2][v3].dir = null unless isType.string options[v1][v2][v3].dir
else
['bower', 'images', 'libs', 'scripts', 'styles', 'test', 'views'].forEach (v3) ->
options[v1][v2][v3] = {} unless isType.object options[v1][v2][v3]
options[v1][v2][v3].dir = null unless isType.string options[v1][v2][v3].dir

portOptions = -> # server ports
options.ports = {} unless isType.object options.ports
@@ -103,7 +107,8 @@ module.exports = (config, options) ->

testOptions = ->
options.test = {} unless isType.object options.test
options.test.browsers = null unless isType.array options.test.browsers
options.test.client = {} unless isType.object options.test.client
options.test.client.browsers = null unless isType.array options.test.client.browsers

serverDistOptions = -> # app server dist entry file
options.dist.server.fileName = null unless isType.string options.dist.server.fileName
@@ -13,12 +13,16 @@ module.exports = (config, rbDir) ->
# api tasks
# =========
rb.tasks = {}
rb.tasks.default = 'rapid-build'
rb.tasks.dev = "#{rb.tasks.default}:dev"
rb.tasks.prod = "#{rb.tasks.default}:prod"
rb.tasks['prod:server'] = "#{rb.tasks.default}:prod:server"
rb.tasks.test = "#{rb.tasks.default}:test"
rb.tasks['test:prod'] = "#{rb.tasks.default}:test:prod"
rb.tasks.default = 'rapid-build'
rb.tasks.dev = "#{rb.tasks.default}:dev"
rb.tasks.prod = "#{rb.tasks.default}:prod"
rb.tasks['prod:server'] = "#{rb.tasks.default}:prod:server"
rb.tasks.test = "#{rb.tasks.default}:test"
rb.tasks['test:prod'] = "#{rb.tasks.default}:test:prod"
rb.tasks['test:client'] = "#{rb.tasks.default}:test:client"
rb.tasks['test:server'] = "#{rb.tasks.default}:test:server"
rb.tasks['test:client:prod'] = "#{rb.tasks.default}:test:client:prod"
rb.tasks['test:server:prod'] = "#{rb.tasks.default}:test:server:prod"

# prefixes
# ========
@@ -4,14 +4,16 @@ module.exports = (config, options) ->

# init test
# =========
test = {}
test =
client: {}
dist: {}

# browsers
# ========
getBrowsers = ->
browsers = ['PhantomJS'] # default
browserOpts = ['Chrome', 'Firefox', 'IE', 'Safari'] # case sensitive
userBrowsers = options.test.browsers
userBrowsers = options.test.client.browsers
return browsers unless userBrowsers
return browsers unless userBrowsers.length
# format the browser names, they are case sensitive
@@ -26,7 +28,7 @@ module.exports = (config, options) ->
browsers.push match
browsers

test.browsers = getBrowsers()
test.client.browsers = getBrowsers()

# test files
# ==========
@@ -37,6 +39,8 @@ module.exports = (config, options) ->
client:
scripts: config.glob[loc][appOrRb].client.test.js
styles: config.glob[loc][appOrRb].client.test.css
server:
scripts: config.glob[loc][appOrRb].server.test.js
structure

test.dist = getTestFiles 'dist'
@@ -246,7 +246,8 @@ module.exports = (config) ->

src: (loc='rb', opts={}) ->
return if not me.has.bower loc
env = opts.env or config.env.name
env = opts.env
env = 'prod' if not env and config.env.is.prod
env = 'dev' if ['dev','prod'].indexOf(env) is -1
absPaths = []
relPaths = {}
@@ -1,4 +1,4 @@
module.exports = ->
module.exports = (gulp={}) ->
q = require 'q'

# private
@@ -28,4 +28,9 @@ module.exports = ->
tasks = getTasks config, tasksCb, type, lang, locs
defer = q.defer()
tasks.reduce(q.when, q()).done -> defer.resolve()
defer.promise
defer.promise

wasCalledFrom: (task) -> # return boolean
calledFromTask = gulp.seq.indexOf(task) isnt -1
# console.log "was called from task #{task} = #{calledFromTask}".yellow
calledFromTask

0 comments on commit 18db4de

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