Permalink
Browse files

push test case to github, add makefile

  • Loading branch information...
1 parent 122e4f6 commit 51057704eb2b59fcb24827dfe4b5302743ba7935 @tblobaum committed Feb 21, 2012
Showing with 44 additions and 1 deletion.
  1. +7 −0 Makefile
  2. +1 −1 lib/subdomains.js
  3. +36 −0 test/subdomains.test.js
View
@@ -0,0 +1,7 @@
+ test:
+ @NODE_ENV=test mocha \
+ --reporter spec \
+ test/*.test.js
+
+.PHONY: test
+
View
@@ -21,7 +21,7 @@ module.exports = {
forEachAsync(subs, function(fn, item, i, arr) {
if (RegExp(item.base, "gi").test(req.headers.host)) {
if (item.base !== '.') req.url = '/' + item.base + req.url
- next()
+ next(req, res, next)
}
else fn()
})
View
@@ -0,0 +1,36 @@
+
+// Dependencies
+var assert = require('assert')
+ , subdomains = require(__dirname +'/../lib/subdomains')
+
+// Run tests
+describe('subdomains.use', function () {
+
+ it('should convert a basic subdomain into a route', function (done) {
+ var args = [
+ { url: '/', headers: { host: 'api.domain.com' } },
+ {},
+ function (req, res, next) {
+ assert.strictEqual(req.url, '/api/', 'route should be `/api/`')
+ done()
+ }
+ ]
+ subdomains.use('api')
+ subdomains.middleware.apply({}, args)
+ })
+
+ it('should convert a multi level subdomain into a route', function (done) {
+ var args = [
+ { url: '/', headers: { host: 'api.01.vanity.domain.com' } },
+ {},
+ function (req, res, next) {
+ assert.strictEqual(req.url, '/api.01.vanity/', 'route should be `/api.01.vanity/`')
+ done()
+ }
+ ]
+ subdomains.use('api.01.vanity')
+ subdomains.middleware.apply({}, args)
+ })
+
+})
+

0 comments on commit 5105770

Please sign in to comment.