Skip to content

Commit

Permalink
Fix code coverage
Browse files Browse the repository at this point in the history
Move custom server to grunt connect task with custom middleware allows
us to utilize the keepalive feature to fix code coverage generation
  • Loading branch information
jhchen committed Jul 16, 2014
1 parent 8dd73b9 commit 4fbf0f5
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/.build
/coverage
/.coverage
/dist
/lib
/node_modules
Expand Down
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.build
.coverage
.git
.travis.yml
_*
bower.json
*.log
coverage
examples
grunt
src
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ before_install:
- npm install -g grunt-cli
before_script:
- grunt lodash
- node scripts/server.js &
- grunt connect:server:keepalive &
branches:
only:
- master
Expand Down
14 changes: 5 additions & 9 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
child_process = require('child_process')

module.exports = (grunt) ->
require('load-grunt-tasks')(grunt)

Expand All @@ -8,23 +6,21 @@ module.exports = (grunt) ->
)

require('./grunt/build')(grunt)
require('./grunt/server')(grunt)
require('./grunt/test')(grunt)

grunt.registerTask('dev', 'All the tasks for Quill development', ->
done = this.async()
child_process.spawn('grunt', ['test:karma'], { stdio: 'inherit'})
child_process.spawn('grunt', ['server'], { stdio: 'inherit' })
)
grunt.registerTask('dev', ['connect:server', 'test:karma'])

grunt.registerTask('dist', ['clean', 'lodash', 'browserify', 'uglify', 'stylus', 'concat'])
grunt.registerTask('release', ['dist', 'shell:examples', 'copy', 'compress'])

grunt.registerTask('server', ['shell:server'])
grunt.registerTask('server', ['connect:server:keepalive'])

grunt.registerTask('test', ['karma:test'])

grunt.registerTask('test:karma', ['karma:karma'])
grunt.registerTask('test:unit', ['karma:test'])
grunt.registerTask('test:unit:remote', ['karma:remote-mac', 'karma:remote-windows', 'karma:remote-linux', 'karma:remote-mobile', 'karma:remote-legacy'])

grunt.registerTask('test:coverage', ['coffee:src', 'shell:instrument', 'karma:coverage', 'clean:coffee', 'clean:coverage'])
grunt.registerTask('test:coverage', ['coffee:src', 'shell:instrument', 'connect:server', 'karma:coverage', 'clean:coffee', 'clean:coverage'])

60 changes: 60 additions & 0 deletions grunt/server.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
_ = require('lodash')
coffeeify = require('coffeeify')
fs = require('fs')
harp = require('harp')
stylus = require('stylus')
watchify = require('watchify')


bundle = (w) ->
return w.bundle({ standalone: 'Quill' })

serve = (connect, req, res, next) ->
watchers = connect.watchers
switch req.url
when '/quill.js'
res.setHeader('Content-Type', 'application/javascript')
bundle(watchers['src']).pipe(res)
when '/test/quill.js'
res.setHeader('Content-Type', 'application/javascript')
bundle(watchers['test']).pipe(res)
when '/quill.snow.css'
res.setHeader('Content-Type', 'text/css')
fs.readFile('./src/themes/snow/snow.styl', (err, data) ->
s = stylus(data.toString())
s.include('./src/themes/snow')
s.define('url', stylus.url())
s.render((err, css) ->
res.write(css)
res.end()
)
)
else
next()


module.exports = (grunt) ->
grunt.config('connect',
options:
onCreateServer: (server, connect, options) ->
connect.watchers = _.reduce(['src', 'test'], (watchers, type) ->
w = watchify("./#{type}/quill.coffee", { extensions: ['.js', '.coffee'] })
watchers[type] = w
w.require('./.build/lodash.js', { expose: 'lodash' })
w.transform(coffeeify)
w.on('update', bundle.bind(this, w))
bundle(w) if options.keepalive
return watchers
, {})
middleware: (connect, options, middlewares) ->
middlewares.push(serve.bind(this, connect))
middlewares.push(harp.mount(__dirname + '/..'))
return middlewares
debug: true
server:
options:
port: 9000
coverage:
options:
port: 9001
)
3 changes: 2 additions & 1 deletion grunt/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ remoteBrowserGroups =
remoteConfigs =
browserDisconnectTimeout: 10000
browserDisconnectTolerance: 2
browserNoActivityTimeout: 30000
browserNoActivityTimeout: 60000
reporters: remoteReporters

remoteKarma = _.reduce(remoteBrowserGroups, (memo, browsers, group) ->
Expand All @@ -37,6 +37,7 @@ module.exports = (grunt) ->
local:
browsers: ['Chrome', 'Firefox', 'Safari']
coverage:
browserNoActivityTimeout: 30000
browsers: ['PhantomJS']
reporters: ['coverage']
))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
"devDependencies": {
"coffee-script": "~1.7.1",
"coffeeify": "~0.6.0",
"connect": "~3.0.1",
"grunt": "~0.4.3",
"grunt-browserify": "~2.1.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-coffee": "~0.10.1",
"grunt-contrib-compress": "~0.9.1",
"grunt-contrib-concat": "~0.4.0",
"grunt-contrib-connect": "~0.8.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-stylus": "~0.18.0",
"grunt-contrib-uglify": "~0.5.0",
Expand Down
47 changes: 0 additions & 47 deletions scripts/server.js

This file was deleted.

0 comments on commit 4fbf0f5

Please sign in to comment.