Skip to content

Commit

Permalink
Adding expresso tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgco committed Jun 20, 2011
1 parent dcedf36 commit 00107cc
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
7 changes: 7 additions & 0 deletions package.json
Expand Up @@ -15,5 +15,12 @@
{
"compress" : "0.1.9",
"mime" : "1.2.2"
},
"devDependencies":
{
"expresso": "0.7.6",
"should": "0.2.1",
"connect": "1.4.4",
"express": "2.3.11"
}
}
1 change: 1 addition & 0 deletions test/fixtures/test.js
@@ -0,0 +1 @@
alert("hello");
Binary file added test/fixtures/test.js.gzip
Binary file not shown.
Binary file added test/fixtures/user.gzip
Binary file not shown.
4 changes: 4 additions & 0 deletions test/fixtures/user.json
@@ -0,0 +1,4 @@
{
"name": "tomgallacher",
"website": "www.tomgallacher.info"
}
92 changes: 92 additions & 0 deletions test/staticGzipTest.js
@@ -0,0 +1,92 @@

/**
* Module dependencies.
*/

var staticProvider,
assert = require('assert'),
should = require('should'),
http = require('http'),
gzippo = require('../'),
crypto = require('crypto'),
fs = require('fs'),
shasum = crypto.createHash('sha1');

try {
staticProvider = require('connect');
} catch (e) {
staticProvider = require('express');
}

/**
* Path to ./test/fixtures/
*/

var fixturesPath = __dirname + '/fixtures';

var app = staticProvider.createServer(
gzippo.staticGzip(fixturesPath)
);

module.exports = {
'requesting gzipped json file succeeds': function() {
assert.response(app,
{
url: '/user.json',
headers: {
'Accept-Encoding':"gzip"
}
},
function(res){
var gzippedData = res.body;
assert.response(app, { url: '/user.gzip' }, function(res) {
assert.equal(gzippedData, res.body, "Data is not gzipped");
});

res.statusCode.should.equal(200);
res.headers.should.have.property('content-type', 'application/json');
res.headers.should.have.property('content-length', '69');
res.headers.should.have.property('content-encoding', 'gzip');
}
);
},
'requesting gzipped js file succeeds': function() {
assert.response(app,
{
url: '/test.js',
headers: {
'Accept-Encoding':"gzip"
}
},
function(res){
var gzippedData = res.body;
assert.response(app, { url: '/test.js.gzip' }, function(res) {
assert.equal(gzippedData, res.body, "Data is not gzipped");
});

res.statusCode.should.equal(200);
res.headers.should.have.property('content-type', 'application/javascript');
res.headers.should.have.property('content-length', '35');
res.headers.should.have.property('content-encoding', 'gzip');
}
);
},
'requesting js file without gzip succeeds': function() {
assert.response(app,
{
url: '/test.js'
},
function(res){
var gzippedData = res.body;

fs.readFile(fixturesPath + '/test.js', function (err, data) {
if (err) throw err;
assert.equal(gzippedData, data, "Data returned does not match file data on filesystem");
});

res.statusCode.should.equal(200);
res.headers.should.have.property('content-length', '15');
}
);
}
};

0 comments on commit 00107cc

Please sign in to comment.