Skip to content

Commit 90fd304

Browse files
author
Thomas Scholtes
committed
Merge pull request josephg#1 from Dignifiedquire/integration_test
Use grunt-karma and grunt-simple-mocha for running all tests.
2 parents 39f509c + f5d295a commit 90fd304

30 files changed

+182
-199
lines changed

.travis.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
before_script:
2-
- "npm install"
3-
- "npm install -g grunt-cli"
41
language: node_js
52
node_js:
63
- 0.10
4+
5+
services:
6+
- redis-server
7+
8+
before_script:
9+
- export DISPLAY=:99.0
10+
- sh -e /etc/init.d/xvfb start
11+
- npm install -g grunt-cli
12+
13+
script:
14+
- grunt test

Gruntfile.js

-28
This file was deleted.

README.md

+7-11
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ A [list of changes from 0.6 is here](https://github.com/share/ShareJS/wiki/Chang
1818
> The API and the code are unstable, and there are known bugs. Test
1919
> coverage has dropped from 90% in ShareJS 0.6 to around 50% and documentation
2020
> of the new APIs is largely nonexistant.
21-
>
21+
>
2222
> The documentation below is also full of lies. If you want to play with the
2323
> new version of ShareJS anyway, look at the examples in prototype/.
24-
>
24+
>
2525
> I understand that if you're using racer & derby, you will use this code
2626
> anyway despite my warnings. If you run into issues, please file issues so I can fix them.
2727
@@ -111,7 +111,7 @@ There are two ways to run a sharejs server:
111111
3. If you are just mucking around, run:
112112
113113
# sharejs-exampleserver
114-
114+
115115
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.
116116

117117
> 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,
202202
Testing
203203
-------
204204

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

212209
All tests are located under the `test` directory. Browser tests are contained in
213-
`test/browser`. If you add browser tests, you also have to add them to the
214-
script `test/browser/index.coffee` that runs the tests in the browser.
210+
`test/browser` and node tests are located in `test/server`.

gruntfile.coffee

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
module.exports = (grunt) ->
2+
grunt.initConfig
3+
karma:
4+
options:
5+
configFile: 'karma.conf.coffee'
6+
runnerPort: 9999
7+
port: 9998
8+
ci:
9+
singleRun: true
10+
reporters: ['dots']
11+
dev:
12+
background: true
13+
14+
simplemocha:
15+
options:
16+
ui: 'bdd',
17+
reporter: 'dot',
18+
ignoreLeaks: false
19+
server:
20+
src: ['test/server/*.coffee']
21+
watch:
22+
karma:
23+
files: [
24+
'lib/**/*.js'
25+
'test/browser/*.coffee'
26+
'test/helpers/*.coffee'
27+
]
28+
tasks: ['karma:dev:run']
29+
mocha:
30+
files: [
31+
'lib/**/*.js'
32+
'test/server/*.coffee'
33+
'test/helpers/*.coffee'
34+
]
35+
36+
# Load NPM Tasks
37+
grunt.loadNpmTasks 'grunt-karma'
38+
grunt.loadNpmTasks 'grunt-simple-mocha'
39+
grunt.loadNpmTasks 'grunt-contrib-watch'
40+
41+
# Register Tasks
42+
grunt.registerTask 'test:browser', ['server', 'karma:ci']
43+
grunt.registerTask 'test:server', ['simplemocha:server']
44+
grunt.registerTask 'test', ['test:server', 'test:browser']
45+
46+
grunt.registerTask 'server', 'Start a server to test clients', ->
47+
done = this.async()
48+
server = require('./test/helpers/server')({log: false})
49+
server.listen(3000)
50+
.on('listening', done)
51+
.on 'error', (err) ->
52+
if (err.code is 'EADDRINUSE')
53+
grunt.fatal('Port 3000 is already in use by another process.')
54+
else
55+
grunt.fatal(err);
56+
57+
# Default Task
58+
grunt.registerTask 'default', ['server', 'karma:dev:start', 'watch']
59+
60+

karma.conf.coffee

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Karma configuration
2+
3+
module.exports = (config) ->
4+
config.set
5+
6+
# base path, that will be used to resolve files and exclude
7+
basePath: ''
8+
9+
# frameworks to use
10+
frameworks: ['mocha', 'browserify']
11+
12+
# list of files / patterns to load in the browser
13+
files: [
14+
'test/browser/*.coffee'
15+
]
16+
17+
preprocessors:
18+
'**/*.coffee': ['coffee']
19+
'test/browser/*': ['browserify']
20+
21+
# Configure browserify
22+
browserify:
23+
extension: ['.coffee'] # This is for future compatibility.
24+
transform: ['coffeeify']
25+
watch: true # Watches dependencies only (Karma watches the tests)
26+
27+
# enable / disable watching file and executing tests whenever any file changes
28+
autoWatch: false
29+
30+
# Browsers
31+
browsers: if process.env.TRAVIS then ['Firefox'] else ['Chrome']

package.json

+18-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"semver": "~2",
2222
"express": "~3",
2323
"hat": "*",
24-
"sinon": "~1.7.3",
2524
"async": "~0.2"
2625
},
2726
"devDependencies": {
@@ -31,13 +30,27 @@
3130
"browserify": "~2.34",
3231
"optimist": ">= 0.2.4",
3332
"browserchannel": "*",
34-
"grunt": "~0.4",
35-
"mocha": "*",
33+
"grunt": "~0.4.1",
34+
"mocha": "~1.13.0",
3635
"chai": "*",
37-
"sinon": "1.7.3",
36+
"sinon": "1.7.1",
3837
"phantom-proxy": "~0.1.792",
3938
"redis": "~0.8.6",
40-
"uglify-js": "~2"
39+
"uglify-js": "~2",
40+
"karma-script-launcher": "~0.1.0",
41+
"karma-chrome-launcher": "~0.1.0",
42+
"karma-firefox-launcher": "~0.1.0",
43+
"karma-coffee-preprocessor": "~0.1.0",
44+
"karma-phantomjs-launcher": "~0.1.0",
45+
"karma-browserify": "0.0.5",
46+
"grunt-simple-mocha": "~0.4.0",
47+
"karma-html2js-preprocessor": "~0.1.0",
48+
"karma-jasmine": "~0.1.3",
49+
"karma-requirejs": "~0.1.0",
50+
"karma": "~0.10.2",
51+
"grunt-karma": "~0.6.2",
52+
"karma-mocha": "~0.1.0",
53+
"grunt-contrib-watch": "~0.5.3"
4154
},
4255
"engine": "node >= 0.10",
4356
"main": "lib/index.js",

tasks/test_phantom.coffee

-49
This file was deleted.

test/browser/connection.coffee

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
assert = require 'assert'
2+
createSocket = require '../helpers/socket.coffee'
23

3-
describe 'Connection', ->
44

5-
{Connection} = require('share')
6-
{BCSocket} = require('bcsocket')
5+
describe 'Connection', ->
6+
share = require('../../lib/client')
7+
Connection = share.Connection
78

89
describe 'connecting', ->
9-
1010
it 'connects socket', (done)->
11-
socket = new BCSocket
11+
socket = createSocket()
1212
socket.close()
1313
connection = new Connection(socket)
1414
connection.on 'connecting', ->
@@ -17,25 +17,25 @@ describe 'Connection', ->
1717
socket.open()
1818

1919
it 'connects to sharejs', (done)->
20-
socket = new BCSocket
20+
socket = createSocket()
2121
connection = new Connection(socket)
2222
connection.on 'connected', ->
2323
socket.close()
2424
done()
25-
25+
2626

2727
describe '#get', ->
2828

2929
before ->
30-
socket = new BCSocket
30+
socket = createSocket()
3131
@connection = new Connection(socket)
3232

3333
after ->
3434
@connection.socket.close()
3535
delete @connection
3636

3737
it 'returns a document', ->
38-
Doc = require('share').Doc
38+
Doc = share.Doc
3939
doc = @connection.get('cars', 'porsche')
4040
assert.equal doc.constructor, Doc
4141

test/browser/doc.coffee

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
assert = require 'assert'
22
ottypes = require 'ottypes'
33
sinon = require 'sinon'
4+
createSocket = require '../helpers/socket.coffee'
45

56
describe 'Doc', ->
7+
{Connection} = require('../../lib/client')
68

7-
{Connection} = require('share')
8-
{BCSocket} = require('bcsocket')
9-
10-
fixtures = require('../helpers/fixtures')()
9+
fixtures = require('../helpers/fixtures.coffee')()
1110

1211
before ->
13-
@connection = @alice = new Connection(new BCSocket)
14-
@bob = new Connection(new BCSocket)
12+
@connection = @alice = new Connection(createSocket())
13+
@bob = new Connection(createSocket())
1514

1615
@alice.on 'error', (e)-> throw e
1716
@bob.on 'error', (e)-> throw e

test/browser/index.coffee

-17
This file was deleted.

test/browser/index.html

-13
This file was deleted.

0 commit comments

Comments
 (0)