Browse files

Revert "Removed staticCache tests for now"

This reverts commit 2c93ba9.
  • Loading branch information...
1 parent b5dd0d8 commit b37c0f066677280bd852fbfe9c8e388168abe3d9 @tj tj committed Oct 24, 2011
Showing with 194 additions and 1 deletion.
  1. +2 −1 Makefile
  2. +192 −0 test/staticCache.test.js
View
3 Makefile
@@ -4,7 +4,8 @@ TESTS ?= test/*.test.js
SRC = $(shell find lib -type f -name "*.js")
test:
- @NODE_ENV=test ./node_modules/.bin/expresso $(TEST_FLAGS) $(TESTS)
+ @NODE_ENV=test ./$(TEST) \
+ $(TEST_FLAGS) $(TESTS)
docs:
@mkdir -p docs
View
192 test/staticCache.test.js
@@ -0,0 +1,192 @@
+
+/**
+ * Module dependencies.
+ */
+
+var connect = require('../')
+ , assert = require('assert')
+ , should = require('should')
+ , http = require('http');
+
+/**
+ * Path to ./test/fixtures/
+ */
+
+var fixturesPath = __dirname + '/fixtures';
+
+var app = connect(
+ connect.staticCache(),
+ connect.static(fixturesPath, { maxAge: 60000 })
+);
+
+var app2 = connect(
+ connect.staticCache(),
+ connect.static(fixturesPath, { maxAge: 0 })
+);
+
+
+module.exports = {
+
+ 'unconditional request': function() {
+ assert.response(
+ app,
+ { url: '/user.json' },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('last-modified');
+ res.headers.should.have.property('etag');
+ assert.response(
+ app,
+ { url: '/user.json' },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('date');
+ res.headers.should.have.property('last-modified');
+ res.headers.should.have.property('etag');
+ }
+ );
+ }
+ );
+ },
+
+ 'ifnonematch request': function() {
+ assert.response(
+ app,
+ { url: '/user.json' },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('etag');
+ assert.response(
+ app,
+ {
+ url: '/user.json',
+ headers: {
+ "If-None-Match": res.headers.etag
+ }
+ },
+ function(res) {
+ res.statusCode.should.equal(304);
+ res.headers.should.have.property('date');
+ res.headers.should.have.property('last-modified');
+ res.headers.should.have.property('etag');
+ }
+ );
+ }
+ );
+ },
+
+ 'old if-none-match request': function() {
+ assert.response(
+ app,
+ { url: '/user.json' },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('etag');
+ assert.response(
+ app,
+ { url: '/user.json',
+ headers: {
+ 'If-None-Match': 'foobar'
+ }
+ },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('date');
+ res.headers.should.have.property('last-modified');
+ res.headers.should.have.property('etag');
+ }
+ );
+ }
+ );
+ },
+
+ 'if-modified since request': function() {
+ assert.response(
+ app,
+ { url: '/user.json' },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('last-modified');
+ assert.response(
+ app,
+ {
+ url: '/user.json',
+ headers: {
+ 'If-Modified-Since': res.headers['last-modified']
+ }
+ },
+ function(res) {
+ res.statusCode.should.equal(304);
+ res.headers.should.have.property('date');
+ res.headers.should.have.property('last-modified');
+ res.headers.should.have.property('etag');
+ }
+ );
+ }
+ );
+ },
+
+ 'old if-modified-since request': function() {
+ assert.response(
+ app2,
+ { url: '/user.json' },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('last-modified');
+ res.headers.should.have.property('etag');
+ assert.response(
+ app2,
+ {
+ url: '/user.json',
+ headers: {
+ 'If-Modified-Since': 'Sat, 29 Oct 1994 19:43:31 GMT'
+ }
+ },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('date');
+ res.headers.should.have.property('last-modified');
+ res.headers.should.have.property('etag');
+ }
+ );
+ }
+ );
+ },
+
+ 'no-cache request': function() {
+ assert.response(
+ app,
+ { url: '/user.json' },
+ function(res) {
+ res.statusCode.should.equal(200);
+ res.headers.should.have.property('etag');
+ assert.response(
+ app,
+ {
+ url: '/user.json',
+ headers: {
+ 'Cache-Control': 'no-cache, max-age=0',
+ 'If-None-Match': res.headers.etag
+ }
+ },
+ function(res) {
+ res.statusCode.should.equal(304);
+ // res.headers.should.have.property('date');
+ res.headers.should.have.property('last-modified');
+ res.headers.should.have.property('etag');
+ }
+ );
+ }
+ );
+ },
+
+ 'test range request': function(){
+ assert.response(app,
+ { url: '/list' },
+ function(res) {
+ assert.response(app,
+ { url: '/list', headers: { Range: 'bytes=3-6' }},
+ { body: '4567', 'Content-Range': 'bytes 3-6/9', status: 206 });
+ });
+ }
+};

0 comments on commit b37c0f0

Please sign in to comment.