Permalink
Browse files

Cleanup

  • Loading branch information...
1 parent 6214d37 commit 73f70ceec7a9b4510b35270e6bc01124702f7664 @hueniverse hueniverse committed Dec 6, 2012
Showing with 87 additions and 40 deletions.
  1. +2 −0 .gitignore
  2. +1 −1 LICENSE
  3. +5 −5 Makefile
  4. +38 −2 README.md
  5. +1 −1 index.js
  6. 0 lib/{shot.js → index.js}
  7. +2 −3 package.json
  8. +38 −0 test/index.js
  9. +0 −28 test/shot.js
View
@@ -13,4 +13,6 @@ config.json
._*
*/._*
*/*/._*
+coverage.*
+lib-cov
View
@@ -8,7 +8,7 @@ modification, are permitted provided that the following conditions are met:
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- * Neither the name of Walmart nor the
+ * Neither the name of Eran Hammer nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
View
@@ -2,7 +2,7 @@ REPORTER = dot
test:
@#lib-cov
- @NODE_ENV=test ./node_modules/.bin/mocha --recursive --reporter $(REPORTER) --ignore-leaks
+ @NODE_ENV=test ./node_modules/.bin/mocha --recursive --reporter $(REPORTER) --ignore-leaks --timeout 3000
@#$(MAKE) rm-lib-cov
tests: test
@@ -14,11 +14,11 @@ rm-lib-cov:
@rm -rf ./lib-cov/
test-cov: lib-cov
- @$(MAKE) test EXPRESS_COV=1 REPORTER=json-cov > coverage.json
+ @$(MAKE) test TEST_COV=1 REPORTER=json-cov > coverage.json
@$(MAKE) rm-lib-cov
test-cov-html: lib-cov
- @$(MAKE) test EXPRESS_COV=1 REPORTER=html-cov > coverage.html
+ @$(MAKE) test TEST_COV=1 REPORTER=html-cov > coverage.html
@$(MAKE) rm-lib-cov
tap: lib-cov
@@ -27,7 +27,7 @@ tap: lib-cov
unit:
@#lib-cov
- @NODE_ENV=test ./node_modules/.bin/mocha --recursive -R xunit --ignore-leaks > results.xml
+ @NODE_ENV=test ./node_modules/.bin/mocha --recursive -R xunit --ignore-leaks > results.xml --timeout 3000
@#$(MAKE) rm-lib-cov
-.PHONY: test tap test-cv test-cov-html unit lib-cov rm-lib-cov
+.PHONY: test tap test-cov test-cov-html unit lib-cov rm-lib-cov
View
@@ -1,7 +1,43 @@
-shot
-====
+# shot
Injects a fake HTTP request/response into a node HTTP server for simulating server logic, writing tests, or debugging. Does not use a socket
connection so can be run against an inactive server (server not in listen mode). This module is still experimental.
[![Build Status](https://secure.travis-ci.org/hueniverse/shot.png)](http://travis-ci.org/hueniverse/shot)
+
+For example:
+
+```javascript
+// Load modules
+
+var Http = require('http');
+var Shot = require('shot');
+
+
+// Declare internals
+
+var internals = {};
+
+
+internals.main = function () {
+
+ var dispatch = function (req, res) {
+
+ var reply = 'Hello World';
+ res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length });
+ res.end(reply);
+ };
+
+ var server = Http.createServer(dispatch);
+
+ Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) {
+
+ console.log(res.readPayload());
+ });
+};
+
+
+internals.main();
+```
+
+Note how `server.listen` is never called.
View
@@ -1 +1 @@
-module.exports = require('./lib/shot');
+module.exports = require('./lib');
File renamed without changes.
View
@@ -5,7 +5,7 @@
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)",
"contributors":[
],
- "repository": "git://github.com/hueniverse/injection",
+ "repository": "git://github.com/hueniverse/shot",
"main": "index",
"keywords": [
"utilities",
@@ -20,8 +20,7 @@
},
"devDependencies": {
"mocha": "1.x.x",
- "should": "1.x.x",
- "sinon": "1.3.4"
+ "chai": "1.2.x"
},
"scripts": {
"test": "make test && make unit"
View
@@ -0,0 +1,38 @@
+// Load modules
+
+var Chai = require('chai');
+var Shot = process.env.TEST_COV ? require('../lib-cov') : require('../lib');
+
+
+// Declare internals
+
+var internals = {};
+
+
+// Test shortcuts
+
+var expect = Chai.expect;
+
+
+describe('Shot', function () {
+
+ var reply = 'Hello World';
+ var dispatch = function (req, res) {
+
+ res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length });
+ res.end(reply);
+ };
+
+ describe('#inject', function () {
+
+ it('should return the payload', function (done) {
+
+ Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) {
+
+ expect(res.readPayload()).to.equal(reply);
+ done();
+ });
+ })
+ });
+});
+
View
@@ -1,28 +0,0 @@
-// Load modules
-
-var Should = require('should');
-var Shot = require('../lib/shot');
-
-
-describe('shot', function () {
-
- var reply = 'Hello World';
- var dispatch = function (req, res) {
-
- res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': reply.length });
- res.end(reply);
- };
-
- describe('#inject', function () {
- it('should return the payload', function (done) {
- (function () {
- Shot.inject(dispatch, { method: 'get', url: '/' }, function (res) {
-
- res.readPayload().should.equal(reply);
- });
- }).should.not.throw();
- done();
- })
- });
-});
-

0 comments on commit 73f70ce

Please sign in to comment.