Skip to content

Commit

Permalink
Use grunt-karma and grunt-simple-mocha for running all tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Oct 14, 2013
1 parent 04b2e45 commit ed5916d
Show file tree
Hide file tree
Showing 26 changed files with 159 additions and 149 deletions.
39 changes: 29 additions & 10 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
module.exports = function(grunt) {
grunt.loadTasks('tasks');
grunt.initConfig({
karma: {
browser: {
configFile: 'karma.conf.js'
}
},
simplemocha: {
options: {
ui: 'bdd',
reporter: 'spec',
ignoreLeaks: false
},
server: {
src: ['test/server/*.coffee']
}
}
});

grunt.registerTask('test:specs', function() {
grunt.util.spawn({
cmd: 'node_modules/.bin/mocha',
opts: { stdio: 'inherit' }
}, this.async());
})
// Load NPM Tasks
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-simple-mocha');

grunt.registerTask('test', ['test:specs']);

// Register Tasks
grunt.registerTask('test-browser', ['test:server', 'karma:browser']);
grunt.registerTask('test-server', ['simplemocha:server']);

grunt.registerTask('test:server', 'Start a server to test clients', function(){
var done = this.async();
server = require('./test/helpers/server')();
//var done = this.async();
server = require('./test/helpers/server')({log: false});
server.listen(3000)
.on('listening', function() {
grunt.log.writeln('To test clients go to http://localhost:3000');
Expand All @@ -25,4 +41,7 @@ module.exports = function(grunt) {
}
});
});

// Default Task
grunt.registerTask('default', ['test-server', 'test-browser']);
};
78 changes: 78 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Karma configuration
// Generated on Mon Oct 14 2013 14:42:34 GMT+0200 (CEST)

module.exports = function(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)
},

// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


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


// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],

proxies: {
'/channel': 'http://localhost:3000/channel',
'/fixtures': 'http://localhost:3000/fixtures'
},

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,23 @@
"grunt": "~0.4",
"mocha": "*",
"chai": "*",
"sinon": "1.7.3",
"sinon": "~1.7.3",
"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-html2js-preprocessor": "~0.1.0",
"karma-coffee-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.3",
"karma-requirejs": "~0.1.0",
"karma-phantomjs-launcher": "~0.1.0",
"karma": "~0.10.2",
"grunt-karma": "~0.6.2",
"karma-browserify": "0.0.5",
"karma-mocha": "~0.1.0",
"grunt-simple-mocha": "~0.4.0"
},
"engine": "node >= 0.10",
"main": "lib/index.js",
Expand Down
49 changes: 0 additions & 49 deletions tasks/test_phantom.coffee

This file was deleted.

11 changes: 7 additions & 4 deletions test/browser/connection.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
assert = require 'assert'


describe 'Connection', ->

{Connection} = require('share')
{BCSocket} = require('bcsocket')
share = require('../../lib/client')
Connection = share.Connection
{BCSocket} = require('browserchannel/dist/bcsocket')

describe 'connecting', ->

Expand All @@ -22,7 +24,7 @@ describe 'Connection', ->
connection.on 'connected', ->
socket.close()
done()


describe '#get', ->

Expand All @@ -35,8 +37,9 @@ describe 'Connection', ->
delete @connection

it 'returns a document', ->
Doc = require('share').Doc
Doc = share.Doc
doc = @connection.get('cars', 'porsche')
console.log doc
assert.equal doc.constructor, Doc

it 'always returns the same document', ->
Expand Down
6 changes: 3 additions & 3 deletions test/browser/doc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ sinon = require 'sinon'

describe 'Doc', ->

{Connection} = require('share')
{BCSocket} = require('bcsocket')
{Connection} = require('../../lib/client')
{BCSocket} = require('browserchannel/dist/bcsocket')

fixtures = require('../helpers/fixtures')()
fixtures = require('../helpers/fixtures.coffee')()

before ->
@connection = @alice = new Connection(new BCSocket)
Expand Down
17 changes: 0 additions & 17 deletions test/browser/index.coffee

This file was deleted.

13 changes: 0 additions & 13 deletions test/browser/index.html

This file was deleted.

6 changes: 3 additions & 3 deletions test/browser/subscribed.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
assert = require 'assert'
{Connection} = require('share')
{BCSocket} = require('bcsocket')
{Connection} = require('../../lib/client')
{BCSocket} = require('browserchannel/dist/bcsocket')
ottypes = require('ottypes')

describe 'Subscribed Document', ->
Expand All @@ -16,7 +16,7 @@ describe 'Subscribed Document', ->
connection.socket.close()
delete connections[name]

fixtures = require('../helpers/fixtures')()
fixtures = require('../helpers/fixtures.coffee')()

beforeEach (done)->
fixtures.reset(done)
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/fixtures.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{BCSocket} = require('bcsocket')
{BCSocket} = require('browserchannel/dist/bcsocket')

# Control documents on the server
#
Expand Down
22 changes: 1 addition & 21 deletions test/helpers/server.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
express = require 'express'
connect = require 'connect'
browserify = require 'browserify'
{Duplex} = require 'stream'

# Creates a sharejs instance with a livedb backend
Expand Down Expand Up @@ -73,23 +72,4 @@ module.exports = (options = {})->

app.use(connect.logger('dev')) if log

app.use(connect.static('test/browser'))
# Serve compiled mocha.js and mocha.css
.use(connect.static('node_modules/mocha'))

# Compile all client tests
.get '/tests.js', (req, res)->
res.type('js')
browserify(extensions: ['.coffee'])
.transform('coffeeify')
.add('./test/browser')
.require('browserchannel/dist/bcsocket', expose: 'bcsocket')
.require('./lib/client', expose: 'share')
.add('./lib/types')
.bundle (error, source)->
if error
console.error error
res.status 500
res.end "console.error(#{JSON.stringify(error)}}"
else
res.end(source)
app
4 changes: 0 additions & 4 deletions test/mocha.opts

This file was deleted.

4 changes: 2 additions & 2 deletions test/connection.coffee → test/server/connection.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sinon = require 'sinon'
assert = require 'assert'
{Connection} = require '../lib/client'
{Doc} = require '../lib/client/doc'
{Connection} = require '../../lib/client'
{Doc} = require '../../lib/client/doc'


describe 'Connection', ->
Expand Down
6 changes: 3 additions & 3 deletions test/doc.coffee → test/server/doc.coffee
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{expect} = require 'chai'
{Doc} = require '../lib/client/doc'
{Doc} = require '../../lib/client/doc'
ottypes = require 'ottypes'
require '../lib/types/text-api'
require '../../lib/types/text-api'

describe 'Doc', ->

textType = ottypes['http://sharejs.org/types/textv1']
numberType = require('./helpers/ot_number')
numberType = require('../helpers/ot_number')

# TODO Use the real Connection class and stub things out on demand
connection =
Expand Down
4 changes: 2 additions & 2 deletions test/integration.coffee → test/server/integration.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ assert = require 'assert'
{EventEmitter} = require 'events'
ottypes = require 'ottypes'

createSession = require '../lib/server/session'
{Connection} = require '../lib/client'
createSession = require '../../lib/server/session'
{Connection} = require '../../lib/client'

describe 'integration', ->
beforeEach ->
Expand Down
4 changes: 2 additions & 2 deletions test/json-api.coffee → test/server/json-api.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
assert = require("assert")
types = require("ottypes")
require("../lib/types/json-api")
require("../../lib/types/json-api")
json = types.json0
MicroEvent = require("../lib/client/microevent")
MicroEvent = require("../../lib/client/microevent")

# in the future, it would be less brittle to use the real Doc object instead of this fake one
Doc = (data) ->
Expand Down
Loading

0 comments on commit ed5916d

Please sign in to comment.