Skip to content
Browse files

Redoing tests and started adding in logging with Winston

  • Loading branch information...
1 parent 8a0ddaf commit d2e84f5ce73218e56a50a0717b29d94fed62ca73 @ncrohn committed
Showing with 19 additions and 62 deletions.
  1. +11 −9 lib/middleware.js
  2. +3 −3 package.json
  3. +5 −1 readme.md
  4. +0 −9 test/basic.test.js
  5. +0 −20 test/caching.test.js
  6. +0 −20 test/fs.test.js
View
20 lib/middleware.js
@@ -5,16 +5,18 @@
*
*/
-var connect = require("connect");
+var winston = require('winston');
module.exports = function(options) {
var uglify = require("uglify-js"),
fsys = require("../lib/filesystem.js"),
url = require("url"),
- src,
+ src, logLevel = options.logLevel,
maxAge = options.maxAge || 86400000; // default to 1 day
+ winston.setLevels(winston.config.syslog.levels);
+
if(options.hasOwnProperty("src")) {
src = options.src;
} else {
@@ -39,28 +41,28 @@ module.exports = function(options) {
ast = uglify.uglify.ast_squeeze(ast);
ast = uglify.uglify.gen_code(ast);
} catch (x) {
- console.error("\r\nERROR: ", path, x);
+ winston.error("\r\nERROR: ", path, x);
}
if(ast) {
// Cache the file so we don't have to do it again.
fsys.writeFile(src+path, ast,
function() {
- console.log("Cached uglified: "+path);
+ winston.debug("Cached uglified: "+path);
});
- console.log('"GET', path, '" 200 - Minified');
+ winston.info('"GET', path, '" 200 - Minified');
res.send(ast, {"Content-Type": "application/javascript"}, 200);
} else {
- console.log('"GET', path, '" 200 - Failed to Minify');
- res.contentType('js');
+ winston.info('"GET', path, '" 200 - Failed to Minify');
+ res.contentType('text/javascript');
res.send(data, 200);
}
} else {
- console.log('"GET', path, '" 200 - Cached');
+ winston.info('"GET', path, '" 200 - Cached');
res.setHeader('Expires', new Date(Date.now() + maxAge).toUTCString());
res.setHeader('Cache-Control', 'public, max-age=' + (maxAge / 1000));
- res.contentType("js");
+ res.contentType("text/javascript");
res.send(data, 200);
}
}
View
6 package.json
@@ -15,10 +15,10 @@
"node": ">=0.4.8"
},
"dependencies": {
- "uglify-js": ">=1.0.2",
- "connect": ">=1.0.0"
+ "uglify-js": ">=1.0.2"
},
"devDependencies": {
- "express": ">=2.3.11"
+ "express": ">=2.3.11",
+ "vows": "0.6.2"
}
}
View
6 readme.md
@@ -13,7 +13,11 @@ The Express Uglify middleware intercepts JS file calls and runs them through the
## Usage:
- app.use(require('express-uglify').middleware({ src: __dirname + '/public' }));
+ var expressUglify = require('express-uglify');
+ app.use(expressUglify.middleware({
+ src: __dirname + '/public',
+ logLevel: 'info'
+ }));
## MIT LICENSE
View
9 test/basic.test.js
@@ -1,9 +0,0 @@
-var assert = require("assert"),
- expressUglify = require('../lib/express-uglify');
-
-module.exports = {
- 'Validity': function() {
- console.log("Asserting 1 equals 1");
- assert.eql(1, 1);
- }
-};
View
20 test/caching.test.js
@@ -1,20 +0,0 @@
-var assert = require("assert"),
- uglyExpress = require('../lib/express-uglify'),
- app = require("express").createServer();
-
-app.configure(function() {
- app.use(uglyExpress.middleware({ src: __dirname + '/assets'}));
-});
-
-
-module.exports = {
- "Files are being served": function() {
- assert.response(
- app, {
- url: '/test.js', timeout: 500
- }, function(res) {
- console.log("Asserting 'test.js' body is 'var test=function(){var a=\"foo\"}'");
- assert.ok(res.body === 'var test=function(){var a="foo"}', 'Test assert.response() callback');
- });
- }
-};
View
20 test/fs.test.js
@@ -1,20 +0,0 @@
-var assert = require("assert"),
- uglyExpress = require('../lib/express-uglify'),
- app = require("express").createServer();
-
-app.configure(function() {
- app.use(uglyExpress.middleware({ src: __dirname + '/assets'}));
-});
-
-
-module.exports = {
- "Files are being served": function() {
- assert.response(
- app, {
- url: '/no-dir/test.js', timeout: 500
- }, function(res) {
- console.log("Asserting missing file returns a 404");
- assert.ok(res.statusCode === 404);
- });
- }
-};

0 comments on commit d2e84f5

Please sign in to comment.
Something went wrong with that request. Please try again.