Permalink
Browse files

Merge pull request #1 from Dignifiedquire/integration_test

Use grunt-karma and grunt-simple-mocha for running all tests.
  • Loading branch information...
2 parents 39f509c + f5d295a commit 90fd304cb7764ef6fb638a4dd3cfe49c91f12fd9 @geigerzaehler geigerzaehler committed Oct 18, 2013
View
@@ -1,6 +1,14 @@
-before_script:
- - "npm install"
- - "npm install -g grunt-cli"
language: node_js
node_js:
- 0.10
+
+services:
+ - redis-server
+
+before_script:
+ - export DISPLAY=:99.0
+ - sh -e /etc/init.d/xvfb start
+ - npm install -g grunt-cli
+
+script:
+ - grunt test
View
@@ -1,28 +0,0 @@
-module.exports = function(grunt) {
- grunt.loadTasks('tasks');
-
- grunt.registerTask('test:specs', function() {
- grunt.util.spawn({
- cmd: 'node_modules/.bin/mocha',
- opts: { stdio: 'inherit' }
- }, this.async());
- })
-
- grunt.registerTask('test', ['test:specs']);
-
- grunt.registerTask('test:server', 'Start a server to test clients', function(){
- var done = this.async();
- server = require('./test/helpers/server')();
- server.listen(3000)
- .on('listening', function() {
- grunt.log.writeln('To test clients go to http://localhost:3000');
- })
- .on('error', function(err) {
- if (err.code === 'EADDRINUSE') {
- grunt.fatal('Port 3000 is already in use by another process.');
- } else {
- grunt.fatal(err);
- }
- });
- });
-};
View
@@ -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.
@@ -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`.
@@ -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`.
View
@@ -0,0 +1,60 @@
+module.exports = (grunt) ->
+ grunt.initConfig
+ karma:
+ options:
+ configFile: 'karma.conf.coffee'
+ 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', ['server', 'karma:ci']
+ grunt.registerTask 'test:server', ['simplemocha:server']
+ grunt.registerTask 'test', ['test:server', 'test:browser']
+
+ grunt.registerTask 'server', 'Start a server to test clients', ->
+ done = this.async()
+ server = require('./test/helpers/server')({log: false})
+ server.listen(3000)
+ .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', ['server', 'karma:dev:start', 'watch']
+
+
View
@@ -0,0 +1,31 @@
+# Karma configuration
+
+module.exports = (config) ->
+ config.set
+
+ # base path, that will be used to resolve files and exclude
+ basePath: ''
+
+ # frameworks to use
+ frameworks: ['mocha', 'browserify']
+
+ # list of files / patterns to load in the browser
+ files: [
+ 'test/browser/*.coffee'
+ ]
+
+ preprocessors:
+ '**/*.coffee': ['coffee']
+ 'test/browser/*': ['browserify']
+
+ # Configure browserify
+ browserify:
+ extension: ['.coffee'] # This is for future compatibility.
+ transform: ['coffeeify']
+ watch: true # Watches dependencies only (Karma watches the tests)
+
+ # enable / disable watching file and executing tests whenever any file changes
+ autoWatch: false
+
+ # Browsers
+ browsers: if process.env.TRAVIS then ['Firefox'] else ['Chrome']
View
@@ -21,7 +21,6 @@
"semver": "~2",
"express": "~3",
"hat": "*",
- "sinon": "~1.7.3",
"async": "~0.2"
},
"devDependencies": {
@@ -31,13 +30,27 @@
"browserify": "~2.34",
"optimist": ">= 0.2.4",
"browserchannel": "*",
- "grunt": "~0.4",
- "mocha": "*",
+ "grunt": "~0.4.1",
+ "mocha": "~1.13.0",
"chai": "*",
- "sinon": "1.7.3",
+ "sinon": "1.7.1",
"phantom-proxy": "~0.1.792",
"redis": "~0.8.6",
- "uglify-js": "~2"
+ "uglify-js": "~2",
+ "karma-script-launcher": "~0.1.0",
+ "karma-chrome-launcher": "~0.1.0",
+ "karma-firefox-launcher": "~0.1.0",
+ "karma-coffee-preprocessor": "~0.1.0",
+ "karma-phantomjs-launcher": "~0.1.0",
+ "karma-browserify": "0.0.5",
+ "grunt-simple-mocha": "~0.4.0",
+ "karma-html2js-preprocessor": "~0.1.0",
+ "karma-jasmine": "~0.1.3",
+ "karma-requirejs": "~0.1.0",
+ "karma": "~0.10.2",
+ "grunt-karma": "~0.6.2",
+ "karma-mocha": "~0.1.0",
+ "grunt-contrib-watch": "~0.5.3"
},
"engine": "node >= 0.10",
"main": "lib/index.js",
View
@@ -1,49 +0,0 @@
-path = require('path')
-
-module.exports = (grunt)->
-
- grunt.registerTask 'test:phantom', 'Run browser tests in phantom', ->
-
- server = require('../test/helpers/server')(log: !!grunt.cli.options.debug)
- .disable('log')
- .listen(3456)
-
- done = this.async()
-
- phantomProxy = require('phantom-proxy')
- url = 'http://127.0.0.1:3456'
- phantomProxy.create (proxy)->
-
- fail = (msg)->
- proxy.end ->
- grunt.fail.fatal(msg)
- done()
-
- page = proxy.page
- page.open url, (status)->
- if status != true
- fail "Could not connect to #{url}"
-
- page.on 'error', (error, trace)->
- if trace && trace.length
- grunt.log.error(error.red + ' at ')
- trace.forEach (line)->
- file = line.file.replace(/^file:/,'')
- message = grunt.util._('%s:%d %s')
- .sprintf(path.relative('.',file), line.line, line.function)
- grunt.log.error(message.red)
- else
- grunt.log.error(error.red)
- fail('Errors on site')
-
- page.on 'callback', (args)->
- page.emit(args...)
-
- page.on 'console', console.log.bind(console.log)
- page.on 'write', process.stdout.write.bind(process.stdout)
- page.on 'finished', (failures)->
- if failures > 0
- fail("#{failures} test(s) failed")
- else
- proxy.end(done)
-
@@ -1,14 +1,14 @@
assert = require 'assert'
+createSocket = require '../helpers/socket.coffee'
-describe 'Connection', ->
- {Connection} = require('share')
- {BCSocket} = require('bcsocket')
+describe 'Connection', ->
+ share = require('../../lib/client')
+ Connection = share.Connection
describe 'connecting', ->
-
it 'connects socket', (done)->
- socket = new BCSocket
+ socket = createSocket()
socket.close()
connection = new Connection(socket)
connection.on 'connecting', ->
@@ -17,25 +17,25 @@ describe 'Connection', ->
socket.open()
it 'connects to sharejs', (done)->
- socket = new BCSocket
+ socket = createSocket()
connection = new Connection(socket)
connection.on 'connected', ->
socket.close()
done()
-
+
describe '#get', ->
before ->
- socket = new BCSocket
+ socket = createSocket()
@connection = new Connection(socket)
after ->
@connection.socket.close()
delete @connection
it 'returns a document', ->
- Doc = require('share').Doc
+ Doc = share.Doc
doc = @connection.get('cars', 'porsche')
assert.equal doc.constructor, Doc
View
@@ -1,17 +1,16 @@
assert = require 'assert'
ottypes = require 'ottypes'
sinon = require 'sinon'
+createSocket = require '../helpers/socket.coffee'
describe 'Doc', ->
+ {Connection} = require('../../lib/client')
- {Connection} = require('share')
- {BCSocket} = require('bcsocket')
-
- fixtures = require('../helpers/fixtures')()
+ fixtures = require('../helpers/fixtures.coffee')()
before ->
- @connection = @alice = new Connection(new BCSocket)
- @bob = new Connection(new BCSocket)
+ @connection = @alice = new Connection(createSocket())
+ @bob = new Connection(createSocket())
@alice.on 'error', (e)-> throw e
@bob.on 'error', (e)-> throw e
View
@@ -1,17 +0,0 @@
-mocha.setup('bdd')
-
-phantom = require '../helpers/phantom'
-
-require './connection'
-require './subscribed'
-require './doc'
-
-if phantom.available
- console.log = phantom('console')
- console.error = phantom('console')
- Mocha.process.stdout.write = phantom('write')
- mocha.reporter('spec')
-
-
-mocha.run().on 'end', ->
- phantom('finished', this.failures)
View
@@ -1,13 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>ShareJS Client Tests</title>
- <link rel="stylesheet" href="/mocha.css">
-</head>
-
-<body>
- <div id="mocha"></div>
- <script src="/mocha.js"></script>
- <script src="/tests.js"></script>
-</body>
-</html>
Oops, something went wrong.

0 comments on commit 90fd304

Please sign in to comment.