Skip to content

Commit

Permalink
Merge pull request #24 from krakenjs/favicon
Browse files Browse the repository at this point in the history
Updating deps (static-favicon -> serve-favicon)
  • Loading branch information
aredridel committed Aug 18, 2014
2 parents 56b600f + 5e7e52f commit 0084220
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 83 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@
}
],
"devDependencies": {
"tape": "^2.12.3",
"body-parser": "^1.0.2",
"cookie-parser": "^1.0.1",
"express": "^4.6.1",
"istanbul": "^0.2.7",
"supertest": "^0.11.0",
"jshint": "^2.5.0",
"static-favicon": "^1.0.2",
"serve-static": "^1.0.4",
"morgan": "^1.0.0",
"body-parser": "^1.0.2",
"cookie-parser": "^1.0.1"
"serve-favicon": "^2.0.1",
"serve-static": "^1.0.4",
"shortstop": "^1.0.1",
"shortstop-handlers": "^1.0.0",
"supertest": "^0.11.0",
"tape": "^2.12.3"
},
"dependencies": {
"caller": "0.0.1",
Expand Down
7 changes: 5 additions & 2 deletions test/fixtures/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"favicon": {
"enabled": true,
"priority": 10,
"module": "static-favicon"
"module": {
"name": "serve-favicon",
"arguments": [ "path:./fixtures/favicon.ico" ]
}
},

"static": {
Expand Down Expand Up @@ -51,4 +54,4 @@
}
}

}
}
5 changes: 4 additions & 1 deletion test/fixtures/disabled.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"favicon": {
"priority": 10,
"module": "static-favicon"
"module": {
"name": "serve-favicon",
"arguments": [ "path:./fixtures/favicon.ico" ]
}
},

"static": {
Expand Down
7 changes: 5 additions & 2 deletions test/fixtures/enabled.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"favicon": {
"enabled": true,
"priority": 10,
"module": "static-favicon"
"module": {
"name": "serve-favicon",
"arguments": [ "path:./fixtures/favicon.ico" ]
}
},

"static": {
Expand Down Expand Up @@ -51,4 +54,4 @@
}
}

}
}
Binary file added test/fixtures/favicon.ico
Binary file not shown.
7 changes: 5 additions & 2 deletions test/fixtures/no-priority.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

"favicon": {
"enabled": true,
"module": "static-favicon"
"module": {
"name": "serve-favicon",
"arguments": [ "path:./fixtures/favicon.ico" ]
}
},

"static": {
Expand All @@ -20,4 +23,4 @@
"arguments": [ "path:./.build" ]
}
}
}
}
7 changes: 5 additions & 2 deletions test/fixtures/undefined.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"favicon": {
"enabled": true,
"priority": 10,
"module": "static-favicon"
"module": {
"name": "serve-favicon",
"arguments": [ "path:./fixtures/favicon.ico" ]
}
},

"static": {
Expand Down Expand Up @@ -39,4 +42,4 @@

"session": null

}
}
164 changes: 96 additions & 68 deletions test/meddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,20 @@
var test = require('tape'),
express = require('express'),
request = require('supertest'),
shortstop = require('shortstop'),
handlers = require('shortstop-handlers'),
meddle = require('../');

function Resolver() {
var _resolver = shortstop.create();
_resolver.use('path', handlers.path(__dirname));
return function (config, cb) {
_resolver.resolve(config, cb);
};
}

var resolve = Resolver();


test('meddleware', function (t) {

Expand All @@ -28,16 +40,18 @@ test('meddleware', function (t) {
config = require('./fixtures/defaults');
names = Object.keys(config);

app = express();
app.use(meddle(config));
resolve(config, function (err, config) {
app = express();
app.use(meddle(config));

t.equal(app._router.stack.length, names.length + 2, 'middleware stack is appropriate length');
names.forEach(function (name, i) {
var handle = app._router.stack[i + 2].handle;
t.equal(typeof handle, 'function', 'middleware is correctly defined');
t.ok(handle.name.match(new RegExp(name, 'g')), 'middleware name is correct');
t.equal(app._router.stack.length, names.length + 2, 'middleware stack is appropriate length');
names.forEach(function (name, i) {
var handle = app._router.stack[i + 2].handle;
t.equal(typeof handle, 'function', 'middleware is correctly defined');
t.ok(handle.name.match(new RegExp(name, 'g')), 'middleware name is correct');
});
t.end();
});
t.end();
});


Expand All @@ -46,11 +60,14 @@ test('meddleware', function (t) {

config = require('./fixtures/undefined');

app = express();
app.use(meddle(config));
resolve(config, function (err, config) {
app = express();
app.use(meddle(config));

t.equal(app._router.stack.length, 6, 'middleware stack is appropriate length');
t.end();
});

t.equal(app._router.stack.length, 6, 'middleware stack is appropriate length');
t.end();
});

});
Expand All @@ -62,25 +79,27 @@ test('priority', function (t) {
var config, app, entry;

config = require('./fixtures/no-priority');
app = express();
app.use(meddle(config));
resolve(config, function (err, config) {
app = express();
app.use(meddle(config));

entry = app._router.stack[2];
t.ok(entry, 'position 2 middleware exists');
t.equal(typeof entry.handle, 'function', 'position 2 middleware is a function');
t.equal(entry.handle.name, 'favicon', 'position 2 middleware has the expected name');
entry = app._router.stack[2];
t.ok(entry, 'position 2 middleware exists');
t.equal(typeof entry.handle, 'function', 'position 2 middleware is a function');
t.equal(entry.handle.name, 'favicon', 'position 2 middleware has the expected name');

entry = app._router.stack[3];
t.ok(entry, 'position 3 middleware exists');
t.equal(typeof entry.handle, 'function', 'position 3 middleware is a function');
t.equal(entry.handle.name, 'staticMiddleware', 'position 3 middleware has the expected name');
entry = app._router.stack[3];
t.ok(entry, 'position 3 middleware exists');
t.equal(typeof entry.handle, 'function', 'position 3 middleware is a function');
t.equal(entry.handle.name, 'staticMiddleware', 'position 3 middleware has the expected name');

entry = app._router.stack[4];
t.ok(entry, 'position 4 middleware exists');
t.equal(typeof entry.handle, 'function', 'position 4 middleware is a function');
t.equal(entry.handle.name, 'logger', 'position 4 middleware has the expected name');
entry = app._router.stack[4];
t.ok(entry, 'position 4 middleware exists');
t.equal(typeof entry.handle, 'function', 'position 4 middleware is a function');
t.equal(entry.handle.name, 'logger', 'position 4 middleware has the expected name');

t.end();
t.end();
});
});

});
Expand Down Expand Up @@ -184,18 +203,20 @@ test('enabled', function (t) {
return config[prop].enabled !== false;
});

app = express();
app.use(meddle(config));
resolve(config, function (err, config) {
app = express();
app.use(meddle(config));

t.equal(app._router.stack.length, 8, 'middleware stack is appropriate length');
t.equal(app._router.stack.length, 8, 'middleware stack is appropriate length');

names.forEach(function (name, i) {
var handle = app._router.stack[i + 2].handle;
t.equal(typeof handle, 'function', 'position ' + i + ' middleware is a function');
t.ok(handle.name, 'position ' + i + ' middleware has a name');
t.ok(handle.name.match(new RegExp(name, 'g')), 'position ' + i + ' middleware name matches ' + name);
names.forEach(function (name, i) {
var handle = app._router.stack[i + 2].handle;
t.equal(typeof handle, 'function', 'position ' + i + ' middleware is a function');
t.ok(handle.name, 'position ' + i + ' middleware has a name');
t.ok(handle.name.match(new RegExp(name, 'g')), 'position ' + i + ' middleware name matches ' + name);
});
t.end();
});
t.end();

});

Expand All @@ -207,18 +228,20 @@ test('enabled', function (t) {
return config[prop].enabled !== false;
});

app = express();
app.use(meddle(config));
resolve(config, function (err, config) {
app = express();
app.use(meddle(config));

t.equal(app._router.stack.length, 8, 'middleware stack is appropriate length');
t.equal(app._router.stack.length, 8, 'middleware stack is appropriate length');

names.forEach(function (name, i) {
var handle = app._router.stack[i + 2].handle;
t.equal(typeof handle, 'function', 'position ' + i + ' middleware is a function');
t.ok(handle.name, 'position ' + i + ' middleware has a name');
t.ok(handle.name.match(new RegExp(name, 'g')), 'position ' + i + ' middleware name matches ' + name);
names.forEach(function (name, i) {
var handle = app._router.stack[i + 2].handle;
t.equal(typeof handle, 'function', 'position ' + i + ' middleware is a function');
t.ok(handle.name, 'position ' + i + ' middleware has a name');
t.ok(handle.name.match(new RegExp(name, 'g')), 'position ' + i + ' middleware name matches ' + name);
});
t.end();
});
t.end();
});


Expand Down Expand Up @@ -284,42 +307,47 @@ test('events', function (t) {
var config, app, events = 0;

config = require('./fixtures/defaults');
app = express();

app.on('middleware:before', function () {
events += 1;
});
resolve(config, function (err, config) {
app = express();

app.on('middleware:after', function () {
events += 1;
});
app.on('middleware:before', function () {
events += 1;
});

app.use(meddle(config));
t.equal(events, 12, 'registration events were triggered');
t.end();
app.on('middleware:after', function () {
events += 1;
});

app.use(meddle(config));
t.equal(events, 12, 'registration events were triggered');
t.end();
});
});


t.test('before and after named registration events', function (t) {
var config, events, app;

config = require('./fixtures/defaults');
events = 0;
app = express();
resolve(config, function (err, config) {
events = 0;
app = express();

app.on('middleware:before:favicon', function (eventargs) {
t.equal(eventargs.app, app);
events += 1;
});
app.on('middleware:before:favicon', function (eventargs) {
t.equal(eventargs.app, app);
events += 1;
});

app.on('middleware:after:favicon', function (eventargs) {
t.equal(eventargs.app, app);
events += 1;
});
app.on('middleware:after:favicon', function (eventargs) {
t.equal(eventargs.app, app);
events += 1;
});

app.use(meddle(config));
t.equal(events, 2, 'registration events were triggered');
t.end();
app.use(meddle(config));
t.equal(events, 2, 'registration events were triggered');
t.end();
});
});

});
Expand Down

0 comments on commit 0084220

Please sign in to comment.