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
6 changed files
with
104 additions
and
0 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
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
alert("hello"); |
Binary file not shown.
Binary file not shown.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "tomgallacher", | ||
"website": "www.tomgallacher.info" | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
); | ||
} | ||
}; |