Skip to content

Commit

Permalink
Add browser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslankerimov committed Oct 11, 2014
1 parent dd16a6d commit 4c1ee24
Show file tree
Hide file tree
Showing 20 changed files with 237 additions and 159 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ language: node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
- "0.6"
before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
28 changes: 19 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,42 @@ ISTANBUL := $(BIN_DIR)istanbul
BORSCHIK := $(BIN_DIR)borschik
MOCHA := $(BIN_DIR)mocha
_MOCHA := $(BIN_DIR)_mocha
KARMA := $(PRJ_DIR)node_modules/karma/bin/karma

DIRS_FOR_LINT := $(PRJ_DIR)lib $(PRJ_DIR)test
FILES_FOR_LINT := $(PRJ_DIR)lib $(PRJ_DIR)test/*.js $(PRJ_DIR)karma.conf.js

all: build test
all: build test hook

.PHONY: test
test: jshint jscs unittests
test: codestyle unittests

.PHONY: codestyle
codestyle: jscs jshint

.PHONY: unittests
unittests: $(MOCHA) build
$(MOCHA) -u exports -R spec $(PRJ_DIR)test
ROUTER=dist $(MOCHA) -u exports -R spec $(PRJ_DIR)test
unittests: nodejsunittests browsersunittests

.PHONY: unittests_in_nodejs
nodejsunittests: $(MOCHA)
$(MOCHA) -u bdd -R spec -r chai $(PRJ_DIR)test/lib/nodejs.js $(PRJ_DIR)test/*.js

.PHONY: unittests_in_browsers
browsersunittests: $(KARMA) build
PHANTOMJS_BIN=/usr/bin/phantomjs $(KARMA) start $(PRJ_DIR)karma.conf.js --single-run

.PHONY: jshint
jshint: $(JSHINT)
$(JSHINT) $(DIRS_FOR_LINT)
$(JSHINT) $(FILES_FOR_LINT)

.PHONY: jscs
jscs: $(JSCS)
$(JSCS) $(DIRS_FOR_LINT)
$(JSCS) $(FILES_FOR_LINT)

.PHONY: coverage
coverage: $(ISTANBUL) $(_MOCHA)
$(ISTANBUL) cover $(_MOCHA) -- -u exports $(PRJ_DIR)test

$(JSHINT) $(MOCHA) $(_MOCHA) $(ISTANBUL) $(JSCS) $(BORSCHIK):
$(JSHINT) $(MOCHA) $(_MOCHA) $(ISTANBUL) $(JSCS) $(BORSCHIK) $(KARMA):
npm install

.PHONY: hook
Expand Down
61 changes: 61 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Karma configuration
// Generated on Thu Oct 09 2014 00:34:17 GMT+0400 (MSK)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath : '',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks : [ 'mocha' ],

// list of files / patterns to load in the browser
files : [
'dist/susanin.min.js',
'node_modules/chai/chai.js',
'test/lib/browser.js',
'lib/querystring.js',
'test/*.js'
],

// list of files to exclude
exclude : [
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors : {
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters : [ 'dots' ],

// 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 : false,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers : process.env.TRAVIS ?
[ 'Firefox', 'PhantomJS' ] :
[ 'Firefox', 'PhantomJS', 'Chrome' ],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun : false

});
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
"istanbul" : "0.1.x",
"mocha" : "1.11.x",
"chai" : "1.7.x",
"borschik" : "0.3.x"
"borschik" : "0.3.x",
"karma" : "~0.12.24",
"karma-chrome-launcher" : "~0.1.5",
"karma-firefox-launcher" : "~0.1.3",
"karma-phantomjs-launcher" : "~0.1.4",
"karma-mocha" : "~0.1.9"
},
"optionalDependencies" : {},
"main" : "lib/router.js",
Expand Down
16 changes: 8 additions & 8 deletions test/isTrailingSlashOptional_option.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var Route = require('./lib/router').Route,
assert = require('chai').assert;
/* global describe, it, Router, assert */

module.exports = {
describe('isTrailingSlashOptional option', function() {
var Route = Router.Route;

'isTrailingSlashOptional is true by default => trailing slash is not necessary' : function(done) {
it('isTrailingSlashOptional is true by default => trailing slash is not necessary', function(done) {
var route1 = Route('/opa'),
route2 = Route('/opa/<param>'),
route3 = Route('/opa(/<param>)'),
Expand Down Expand Up @@ -43,9 +43,9 @@ module.exports = {
assert.deepEqual(route5.match('/opa/'), null);

done();
},
});

'isTrailingSlashOptional === false' : function(done) {
it('isTrailingSlashOptional === false', function(done) {
var route1 = Route({ pattern : '/opa', isTrailingSlashOptional : false }),
route2 = Route({ pattern : '/opa/<param>', isTrailingSlashOptional : false }),
route3 = Route({ pattern : '/opa/<param>(/)', isTrailingSlashOptional : false });
Expand All @@ -60,6 +60,6 @@ module.exports = {
assert.deepEqual(route3.match('/opa/value/'), { param : 'value' });

done();
}
});

};
});
3 changes: 3 additions & 0 deletions test/lib/browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var assert = chai.assert,
Router = Susanin;
module = {};
3 changes: 3 additions & 0 deletions test/lib/nodejs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global.Router = require('../..');
global.assert = require('chai').assert;
global.querystring = require('../../lib/querystring');
1 change: 0 additions & 1 deletion test/lib/router.js

This file was deleted.

16 changes: 8 additions & 8 deletions test/postMatch_option.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var Route = require('./lib/router').Route,
assert = require('chai').assert;
/* global describe, it, Router, assert */

module.exports = {
describe('postMatch option', function() {
var Route = Router.Route;

'postMatch must be a function' : function(done) {
it('postMatch must be a function', function(done) {
var route = Route({
pattern : '/opa/<param>',
postMatch : true
Expand All @@ -12,9 +12,9 @@ module.exports = {
assert.deepEqual(route.match('/opa/value'), { param : 'value' });

done();
},
});

'/opa/<param> with postMatch function' : function(done) {
it('/opa/<param> with postMatch function', function(done) {
var route = Route({
pattern : '/opa/<param>',
postMatch : function(params) {
Expand Down Expand Up @@ -50,6 +50,6 @@ module.exports = {
{ param : 'value', foo1 : 'bar2', foo : 'bar' });

done();
}
});

};
});
16 changes: 8 additions & 8 deletions test/preBuild_option.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
var Route = require('./lib/router').Route,
assert = require('chai').assert;
/* global describe, it, Router, assert */

module.exports = {
describe('preBuild option', function() {
var Route = Router.Route;

'preBuild must be a function' : function(done) {
it('preBuild must be a function', function(done) {
var route = Route({
pattern : '/opa/<param>',
preBuild : true
Expand All @@ -12,9 +12,9 @@ module.exports = {
assert.deepEqual(route.build({ param : 'value' }), '/opa/value');

done();
},
});

'/opa/<param> with preBuild function' : function(done) {
it('/opa/<param> with preBuild function', function(done) {
var route = Route({
pattern : '/opa/<param>',
preBuild : function(params) {
Expand All @@ -37,6 +37,6 @@ module.exports = {
assert.deepEqual(route.build({ param : 'value', foo : 'bar1' }), '/opa/value?foo=bar');

done();
}
});

};
});
18 changes: 9 additions & 9 deletions test/querystring.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var qs = require('../lib/querystring'),
assert = require('chai').assert,
undef;
/* global describe, it, assert, querystring */

module.exports = {
describe('querystring module', function() {
var qs = querystring,
undef;

'route.parse()' : function(done) {
it('route.parse()', function(done) {
assert.deepEqual(qs.parse(), {});
assert.deepEqual(qs.parse(null), {});
assert.deepEqual(qs.parse(undef), {});
Expand All @@ -27,9 +27,9 @@ module.exports = {
assert.deepEqual(qs.parse('bla=foo&bla1=foo1'), { bla : 'foo', bla1 : 'foo1' });

done();
},
});

'route.stringify()' : function(done) {
it('route.stringify()', function(done) {
assert.strictEqual(qs.stringify(), '');
assert.strictEqual(qs.stringify(null), '');
assert.strictEqual(qs.stringify(undef), '');
Expand All @@ -51,6 +51,6 @@ module.exports = {
assert.strictEqual(qs.stringify([ 1, 2, 3 ]), '0=1&1=2&2=3');

done();
}
});

};
});
Loading

0 comments on commit 4c1ee24

Please sign in to comment.