Skip to content

Commit

Permalink
Add watch task.
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Oct 15, 2013
1 parent 8f40d63 commit eb00959
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
18 changes: 7 additions & 11 deletions README.md
Expand Up @@ -18,10 +18,10 @@ A [list of changes from 0.6 is here](https://github.com/share/ShareJS/wiki/Chang
> The API and the code are unstable, and there are known bugs. Test
> coverage has dropped from 90% in ShareJS 0.6 to around 50% and documentation
> of the new APIs is largely nonexistant.
>
>
> The documentation below is also full of lies. If you want to play with the
> new version of ShareJS anyway, look at the examples in prototype/.
>
>
> I understand that if you're using racer & derby, you will use this code
> anyway despite my warnings. If you run into issues, please file issues so I can fix them.
Expand Down Expand Up @@ -111,7 +111,7 @@ There are two ways to run a sharejs server:
3. If you are just mucking around, run:

# sharejs-exampleserver

This will run a simple server on port 8000, and host all the example code there. Run it and check out http://localhost:8000/ . The example server stores everything in ram, so don't get too attached to your data.

> If you're running sharejs from source, you can launch the example server by running `bin/exampleserver`.
Expand Down Expand Up @@ -202,13 +202,9 @@ See [`the wiki`](https://github.com/josephg/ShareJS/wiki) for API documentation,
Testing
-------

Server-side and client unit tests are run with `grunt test`. For in-browser
tests fire up `grunt test:server` and go to `http://localhost:3000`. You can
also run the browser tests in [PhantomJS](http://phantomjs.org/) using `grunt
test:phantom`. Passing the debug option (`-d`) to the phantom tests shows
the communication between client and server. You can run single tests using
[mocha](http://visionmedia.github.io/mocha/).
Running `grunt` starts a watch task for development.

Using `grunt test` all tests are just executed once.

All tests are located under the `test` directory. Browser tests are contained in
`test/browser`. If you add browser tests, you also have to add them to the
script `test/browser/index.coffee` that runs the tests in the browser.
`test/browser` and node tests are located in `test/server`.
39 changes: 29 additions & 10 deletions gruntfile.coffee
@@ -1,41 +1,60 @@
module.exports = (grunt) ->
grunt.initConfig
karma:
browser:
options:
configFile: 'karma.conf.coffee'
autoWatch: false
runnerPort: 9999
port: 9998
ci:
singleRun: true
reporters: ['dots']
dev:
background: true

simplemocha:
options:
ui: 'bdd',
reporter: 'dot',
ignoreLeaks: false
server:
src: ['test/server/*.coffee']
watch:
karma:
files: [
'lib/**/*.js'
'test/browser/*.coffee'
'test/helpers/*.coffee'
]
tasks: ['karma:dev:run']
mocha:
files: [
'lib/**/*.js'
'test/server/*.coffee'
'test/helpers/*.coffee'
]

# Load NPM Tasks
grunt.loadNpmTasks 'grunt-karma'
grunt.loadNpmTasks 'grunt-simple-mocha'

grunt.loadNpmTasks 'grunt-contrib-watch'

# Register Tasks
grunt.registerTask 'test-browser', ['test:server', 'karma:browser']
grunt.registerTask 'test-server', ['simplemocha:server']
grunt.registerTask 'test:browser', ['server', 'karma:ci']
grunt.registerTask 'test:server', ['simplemocha:server']
grunt.registerTask 'test', ['test:browser', 'test:server']

grunt.registerTask 'test:server', 'Start a server to test clients', ->
grunt.registerTask 'server', 'Start a server to test clients', ->
done = this.async()
server = require('./test/helpers/server')({log: false})
server.listen(3000)
.on 'listening', ->
grunt.log.writeln 'To test clients go to http://localhost:3000'
done()
.on('listening', done)
.on 'error', (err) ->
if (err.code is 'EADDRINUSE')
grunt.fatal('Port 3000 is already in use by another process.')
else
grunt.fatal(err);

# Default Task
grunt.registerTask 'default', ['test-server', 'test-browser']
grunt.registerTask 'default', ['server', 'karma:dev:start', 'watch']


3 changes: 1 addition & 2 deletions karma.conf.coffee
Expand Up @@ -25,7 +25,7 @@ module.exports = (config) ->
watch: true # Watches dependencies only (Karma watches the tests)

# enable / disable watching file and executing tests whenever any file changes
autoWatch: true
autoWatch: false

# Browsers
browsers: if process.env.TRAVIS then ['Firefox'] else ['Chrome']
Expand All @@ -35,4 +35,3 @@ module.exports = (config) ->
'/channel': 'http://localhost:3000/channel'
'/fixtures': 'http://localhost:3000/fixtures'


3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -49,7 +49,8 @@
"karma-requirejs": "~0.1.0",
"karma": "~0.10.2",
"grunt-karma": "~0.6.2",
"karma-mocha": "~0.1.0"
"karma-mocha": "~0.1.0",
"grunt-contrib-watch": "~0.5.3"
},
"engine": "node >= 0.10",
"main": "lib/index.js",
Expand Down

0 comments on commit eb00959

Please sign in to comment.