Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"request handler",
"middleware"
],
"scripts": {
"test": "node test/staticFileTests.js"
},
"maintainers": [
{
"name": "Xavi",
Expand All @@ -24,6 +27,9 @@
"engines": {
"node": ">= 0.3.1"
},
"devDependencies" : {
"tape" : ">=1.0.1"
},
"dependencies": {
"lru-cache": "~2.3.0"
}
Expand Down
119 changes: 119 additions & 0 deletions test/staticFileTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
var test = require('tape'),
bee = require("../");


test('StaticFile defaults max-age to 31536000', function (t) {
t.plan(1);

var staticFile = bee.staticFile('./index.js', 'text/javascript');

staticFile({ headers: {}, url: "/load-existing-static-file" }, {
setHeader: function(type, value) {
if(type === 'Cache-Control')
{
t.equal(value, 'private, max-age=31536000');
}
},
writeHead: function() {},
removeHeader: function() {},
end: function() {}
});

});

test('StaticFile set max-age when provided', function (t) {
t.plan(1);

var maxAge = 123456,
staticFile = bee.staticFile('./index.js', 'text/javascript', maxAge);

staticFile({ headers: {}, url: "/load-existing-static-file" }, {
setHeader: function(type, value) {
if(type === 'Cache-Control')
{
t.equal(value, 'private, max-age=' + maxAge);
}
},
writeHead: function() {},
removeHeader: function() {},
end: function() {}
});

});

test('StaticFile set max-age when is 0', function (t) {
t.plan(1);

var maxAge = 0,
staticFile = bee.staticFile('./index.js', 'text/javascript', maxAge);

staticFile({ headers: {}, url: "/load-existing-static-file" }, {
setHeader: function(type, value) {
if(type === 'Cache-Control')
{
t.equal(value, 'private, max-age=' + maxAge);
}
},
writeHead: function() {},
removeHeader: function() {},
end: function() {}
});

});

test('StaticDir defaults max-age to 31536000', function (t) {
t.plan(1);

var staticDir = bee.staticDir("./", { ".json": "application/json", "js": "application/x-javascript" });
staticDir({ headers: {}, url: "/load-existing-file-from-static-dir" }, {
setHeader: function(type, value) {
if(type === 'Cache-Control')
{
t.equal(value, 'private, max-age=31536000');
}
},
writeHead: function() {},
removeHeader: function() {},
end: function() {}
}, [ "package.json" ]);

});

test('StaticDir set max-age when provided', function (t) {
t.plan(1);

var maxAge = 123456;
debugger;
var staticDir = bee.staticDir("./", { ".json": "application/json", "js": "application/x-javascript" }, maxAge);
staticDir({ headers: {}, url: "/load-existing-file-from-static-dir" }, {
setHeader: function(type, value) {
if(type === 'Cache-Control')
{
t.equal(value, 'private, max-age=' + maxAge);
}
},
writeHead: function() {},
removeHeader: function() {},
end: function() {}
}, [ "package.json" ]);

});

test('StaticDir set max-age when is 0', function (t) {
t.plan(1);

var maxAge = 0,
staticDir = bee.staticDir("./", { ".json": "application/json", "js": "application/x-javascript" }, maxAge);
staticDir({ headers: {}, url: "/load-existing-file-from-static-dir" }, {
setHeader: function(type, value) {
if(type === 'Cache-Control')
{
t.equal(value, 'private, max-age=' + maxAge);
}
},
writeHead: function() {},
removeHeader: function() {},
end: function() {}
}, [ "package.json" ]);

});