[Pkg-javascript-commits] [node-static] 71/151: Adding integration tests

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Tue Jan 7 23:17:59 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository node-static.

commit 63f93859a1165a08184283312adb105504fb8e75
Author: Pablo Cantero <pablo at pablocantero.com>
Date:   Sun Jul 1 17:40:38 2012 -0300

    Adding integration tests
---
 .gitignore                           |   3 +
 package.json                         |  29 ++++++----
 test/fixtures/hello.txt              |   1 +
 test/fixtures/index.html             |   8 +++
 test/integration/node-static-test.js | 104 +++++++++++++++++++++++++++++++++++
 5 files changed, 134 insertions(+), 11 deletions(-)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..073cfe2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+npm-debug.log
+node_modules
+
diff --git a/package.json b/package.json
index b142f3a..f064db1 100644
--- a/package.json
+++ b/package.json
@@ -1,10 +1,10 @@
 {
-  "name"          : "node-static",
-  "description"   : "simple, compliant file streaming module for node",
-  "url"           : "http://github.com/cloudhead/node-static",
-  "keywords"      : ["http", "static", "file", "server"],
-  "author"        : "Alexis Sellier <self at cloudhead.net>",
-  "contributors"  : [
+  "name" : "node-static",
+  "description" : "simple, compliant file streaming module for node",
+  "url" : "http://github.com/cloudhead/node-static",
+  "keywords" : ["http", "static", "file", "server"],
+  "author" : "Alexis Sellier <self at cloudhead.net>",
+  "contributors" : [
 		{
 			"name": "Pablo Cantero",
 			"email": "pablo at pablocantero.com"
@@ -14,9 +14,16 @@
     "type": "git",
     "url": "http://github.com/cloudhead/node-static"
   },
-  "main"          : "./lib/node-static",
-  "license"      : "MIT",
-  "dependencies"  : {},
-  "version"       : "0.6.0",
-  "engines"       : { "node": ">= 0.4.1" }
+  "main" : "./lib/node-static",
+  "scripts": {
+    "test": "vows --spec --isolate"
+  },
+  "license" : "MIT",
+  "dependencies" : {},
+	"devDependencies" : {
+		"request": "latest",
+		"vows": "latest"
+	},
+  "version" : "0.6.0",
+  "engines" : { "node": ">= 0.4.1" }
 }
diff --git a/test/fixtures/hello.txt b/test/fixtures/hello.txt
new file mode 100644
index 0000000..95d09f2
--- /dev/null
+++ b/test/fixtures/hello.txt
@@ -0,0 +1 @@
+hello world
\ No newline at end of file
diff --git a/test/fixtures/index.html b/test/fixtures/index.html
new file mode 100644
index 0000000..eee1c7a
--- /dev/null
+++ b/test/fixtures/index.html
@@ -0,0 +1,8 @@
+<html lang="en">
+<head>
+	<title>Awesome page</title>
+</head>
+<body>
+	hello world!
+</body>
+</html>
diff --git a/test/integration/node-static-test.js b/test/integration/node-static-test.js
new file mode 100644
index 0000000..0bcb7d5
--- /dev/null
+++ b/test/integration/node-static-test.js
@@ -0,0 +1,104 @@
+var vows = require('vows')
+	, request = require('request')
+	, assert = require('assert')
+	,	static = require('../../lib/node-static');
+
+var fileServer = new(static.Server)(__dirname + '/../fixtures', {});
+
+var suite = vows.describe('node-static');
+
+var TEST_PORT = 8080;
+var TEST_SERVER = 'http://localhost:' + TEST_PORT;
+var server;
+
+suite.addBatch({
+  'once an http server is listening': {
+    topic: function () {
+      server = require('http').createServer(function (request, response) {
+        request.addListener('end', function () {
+          fileServer.serve(request, response);
+        });
+      }).listen(TEST_PORT, this.callback)
+    },
+    'should be listening' : function(){
+			assert.isTrue(true);
+    }
+  }
+}).addBatch({
+    'requesting a file not found': {
+      topic : function(){
+        request.get(TEST_SERVER + '/not-found', this.callback);
+      }, 
+      'should respond with 404' : function(error, response, body){
+        assert.equal(response.statusCode, 404);
+      }
+    }
+}).addBatch({
+  'serving hello.txt': {
+    topic : function(){
+      request.get(TEST_SERVER + '/hello.txt', this.callback);
+    }, 
+    'should respond with 200' : function(error, response, body){
+      assert.equal(response.statusCode, 200);
+    }, 
+    'should respond with text/plain': function(error, response, body){
+      assert.equal(response.headers['content-type'], 'text/plain');
+    }, 
+    'should respond with hello world': function(error, response, body){
+      assert.equal(body, 'hello world');
+    }
+  }
+}).addBatch({
+  'implicit serving index.html': {
+    topic : function(){
+      request.get(TEST_SERVER, this.callback);
+    }, 
+    'should respond with 200' : function(error, response, body){
+      assert.equal(response.statusCode, 200);
+    }, 
+    'should respond with text/html': function(error, response, body){
+      assert.equal(response.headers['content-type'], 'text/html');
+    }
+  }
+}).addBatch({
+  'serving index.html from the cache': {
+    topic : function(){
+      request.get(TEST_SERVER + '/index.html', this.callback);
+    }, 
+    'should respond with 200' : function(error, response, body){
+      assert.equal(response.statusCode, 200);
+    }, 
+    'should respond with text/html': function(error, response, body){
+      assert.equal(response.headers['content-type'], 'text/html');
+    }
+  }
+}).addBatch({
+  'requesting with If-None-Match': {
+    topic : function(){
+      var _this = this;
+      request.get(TEST_SERVER + '/index.html', function(error, response, body){
+        request({
+          method: 'GET',
+          uri: TEST_SERVER + '/index.html',
+          headers: {'if-none-match': response.headers['etag']}
+        },
+        _this.callback);
+      });
+    }, 
+    'should respond with 304' : function(error, response, body){
+      assert.equal(response.statusCode, 304);
+    }
+  }
+}).addBatch({
+  'requesting HEAD': {
+    topic : function(){
+      request.head(TEST_SERVER + '/index.html', this.callback);
+    },
+    'should respond with 200' : function(error, response, body){
+      assert.equal(response.statusCode, 200);
+    }, 
+    'head must has no body' : function(error, response, body){
+      assert.isUndefined(body);
+    }
+  }
+}).export(module);
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-static.git



More information about the Pkg-javascript-commits mailing list