-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
192 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
coverage | ||
*.swp | ||
*.swo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
language: node_js | ||
node_js: | ||
- "0.11" | ||
- "0.10" | ||
script: 'npm test --coverage' | ||
after_success: 'npm run report-cov' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* global describe, it */ | ||
|
||
'use strict'; | ||
|
||
var router = new (require('../'))().listen(), | ||
request = require('supertest')(router._server); | ||
|
||
describe('router', function () { | ||
var routes = ['/a', '/a/b', '/a/b/c']; | ||
|
||
routes.forEach(function (route) { | ||
router.when(route, function (req, res) { | ||
res.statusCode = 200; | ||
res.end(route); | ||
}); | ||
}); | ||
|
||
routes.forEach(function (route) { | ||
it ('should route to ' + route, function (done) { | ||
request | ||
.get(route) | ||
.expect(200) | ||
.expect(route) | ||
.end(done); | ||
}); | ||
|
||
it ('should route to child /a of' + route, function (done) { | ||
request | ||
.get(route + '/a') | ||
.expect(200) | ||
.expect(route) | ||
.end(done); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* global describe, it, before */ | ||
|
||
'use strict'; | ||
|
||
var router = new (require('../'))(), | ||
request = require('supertest')(require('http').createServer(router.dispatch)); | ||
|
||
describe('router.dispatch', function () { | ||
before(function (done) { | ||
router.when('/', function (req, res) { | ||
res.statusCode = 200; | ||
res.end('so dispatch'); | ||
}); | ||
|
||
done(); | ||
}); | ||
|
||
it('should function as a request handler for a server', function (done) { | ||
request | ||
.get('/') | ||
.expect(200) | ||
.expect('so dispatch') | ||
.end(done); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* global describe, it */ | ||
|
||
'use strict'; | ||
|
||
var router = new (require('../'))().listen(), | ||
request = require('supertest')(router._server); | ||
|
||
describe('router', function () { | ||
it('should 404 with no routes defined', function (done) { | ||
request | ||
.get('/') | ||
.expect(404) | ||
.end(done); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* global describe, it, before */ | ||
|
||
'use strict'; | ||
|
||
var router = new (require('../'))().listen(), | ||
request = require('supertest')(router._server); | ||
|
||
describe('router', function () { | ||
before(function (done) { | ||
router | ||
.when('abc', function (req, res) { | ||
res.statusCode = 200; | ||
res.end('/abc'); | ||
}); | ||
|
||
done(); | ||
}); | ||
|
||
it('should add a leading slash to routes', function (done) { | ||
request | ||
.get('/abc') | ||
.expect(200) | ||
.expect('/abc') | ||
.end(done); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* global describe, it */ | ||
|
||
'use strict'; | ||
|
||
var router = new (require('../'))().listen(), | ||
request = require('supertest')(router._server); | ||
|
||
describe('router', function () { | ||
it('should replace existing routes', function (done) { | ||
router | ||
.when('/abc', function (req, res) { | ||
res.statusCode = 200; | ||
res.end('/abc'); | ||
}); | ||
|
||
request | ||
.get('/abc') | ||
.expect(200) | ||
.expect('/abc') | ||
.end(function (err) { | ||
/* istanbul ignore if */ | ||
if (err) { | ||
done(err); | ||
} | ||
|
||
router | ||
.when('/abc', function (req, res) { | ||
res.statusCode = 200; | ||
res.end('super new fun times'); | ||
}); | ||
|
||
request | ||
.get('/abc') | ||
.expect(200) | ||
.expect('super new fun times') | ||
.end(done); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* global describe, it */ | ||
|
||
'use strict'; | ||
|
||
var router = new (require('../'))().listen(), | ||
request = require('supertest')(router._server); | ||
|
||
describe('router', function () { | ||
router.when('/a', function (req, res) { | ||
res.statusCode = 200; | ||
res.end('/a'); | ||
}); | ||
|
||
it('should route to /a', function (done) { | ||
request | ||
.get('/a') | ||
.expect(200) | ||
.expect('/a') | ||
.end(done); | ||
}); | ||
|
||
it('should route to /a/', function (done) { | ||
request | ||
.get('/a/') | ||
.expect(200) | ||
.expect('/a') | ||
.end(done); | ||
}); | ||
|
||
it('should not route to superstring /ab', function (done) { | ||
request | ||
.get('/ab') | ||
.expect(404) | ||
.end(done); | ||
}); | ||
}); |