-
Notifications
You must be signed in to change notification settings - Fork 11
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
7 changed files
with
160 additions
and
5 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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
lib-cov | |||
coverage.html | |||
*.seed | |||
*.log | |||
*.csv | |||
*.dat | |||
*.out | |||
*.pid | |||
*.gz | |||
|
|||
pids | |||
logs | |||
results | |||
|
|||
node_modules | |||
npm-debug.log |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
language: node_js | |||
node_js: | |||
- 0.9 | |||
- 0.8 |
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,23 @@ | |||
TESTS = test/*.test.js | |||
REPORTER = spec | |||
TIMEOUT = 1000 | |||
JSCOVERAGE = ./node_modules/jscover/bin/jscover | |||
|
|||
install: | |||
@npm install | |||
|
|||
test: install | |||
@NODE_ENV=test ./node_modules/mocha/bin/mocha \ | |||
--reporter $(REPORTER) \ | |||
--timeout $(TIMEOUT) \ | |||
$(TESTS) | |||
|
|||
test-cov: lib-cov | |||
@CONNECT_DOMAIN_COV=1 $(MAKE) test | |||
@CONNECT_DOMAIN_COV=1 $(MAKE) test REPORTER=html-cov > coverage.html | |||
|
|||
lib-cov: install | |||
@rm -rf $@ | |||
@$(JSCOVERAGE) lib $@ | |||
|
|||
.PHONY: test-cov test lib-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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1 +1 @@ | |||
module.exports = require('./lib/connect-domain'); | module.exports = process.env.CONNECT_DOMAIN_COV ? require('./lib-cov/connect-domain') : require('./lib/connect-domain'); |
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
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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,106 @@ | |||
/*! | |||
* connect-domain - test/domian.test.js | |||
* Copyright(c) 2012 fengmk2 <fengmk2@gmail.com> | |||
* MIT Licensed | |||
*/ | |||
|
|||
"use strict"; | |||
|
|||
/** | |||
* Module dependencies. | |||
*/ | |||
|
|||
var connect = require('connect'); | |||
var connectDomain = require('../'); | |||
var should = require('should'); | |||
var request = require('supertest'); | |||
var pedding = require('pedding'); | |||
|
|||
|
|||
describe('domain.test.js', function () { | |||
var normalHandler = function normalHandler(req, res, next) { | |||
if (req.url === '/sync_error') { | |||
throw new Error('sync_error'); | |||
} | |||
if (req.url === '/async_error') { | |||
process.nextTick(function () { | |||
ff.foo(); | |||
}); | |||
return; | |||
} | |||
res.end(req.url); | |||
}; | |||
|
|||
var errorHandler = function errorHandler(err, req, res, next) { | |||
res.statusCode = 500; | |||
res.end(err.message); | |||
}; | |||
|
|||
var app = connect() | |||
.use(connectDomain()) | |||
.use(normalHandler) | |||
.use(errorHandler); | |||
|
|||
var app2 = connect() | |||
.use(connectDomain(function errorHandler2(err, req, res, next) { | |||
err.message += ', process by errorHandler2'; | |||
next(err); | |||
})) | |||
.use(normalHandler) | |||
.use(errorHandler); | |||
|
|||
it('should GET / status 200', function (done) { | |||
done = pedding(2, done); | |||
|
|||
request(app) | |||
.get('/') | |||
.expect(200, done); | |||
|
|||
request(app2) | |||
.get('/') | |||
.expect(200, done); | |||
}); | |||
|
|||
it('should GET /sync_error status 500', function (done) { | |||
done = pedding(2, done); | |||
|
|||
request(app) | |||
.get('/sync_error') | |||
.expect('sync_error') | |||
.expect(500, done); | |||
|
|||
request(app2) | |||
.get('/sync_error') | |||
.expect('sync_error') | |||
.expect(500, done); | |||
}); | |||
|
|||
describe('hack for async error', function () { | |||
// Because `domain` will still throw `uncaughtException`, we need to hack for `mocha` test. | |||
// https://github.com/joyent/node/issues/4375 | |||
// https://gist.github.com/4179636 | |||
var mochaHandler; | |||
before(function () { | |||
mochaHandler = process.listeners('uncaughtException').pop(); | |||
}); | |||
after(function () { | |||
// ...but be sure to re-enable mocha's error handler | |||
process.on('uncaughtException', mochaHandler); | |||
}); | |||
|
|||
it('should GET /async_error status 500', function (done) { | |||
done = pedding(2, done); | |||
|
|||
request(app) | |||
.get('/async_error') | |||
.expect('ff is not defined') | |||
.expect(500, done); | |||
|
|||
request(app2) | |||
.get('/async_error') | |||
.expect('ff is not defined, process by errorHandler2') | |||
.expect(500, done); | |||
}); | |||
}); | |||
|
|||
}); |