Skip to content

Commit

Permalink
fixed loading of .types file and test that ecstatic throws if path to…
Browse files Browse the repository at this point in the history
… .types file is wrong
  • Loading branch information
dotnetCarpenter committed May 11, 2015
1 parent 81d1820 commit 3a13400
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
8 changes: 2 additions & 6 deletions lib/ecstatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ var ecstatic = module.exports = function (dir, options) {

// Support hashes and .types files in mimeTypes @since 0.8
if (opts.mimeTypes) {
if (opts.mimeTypes instanceof String) {
try {
mime.load(opts.mimeTypes);
} catch(e) { /* NOT SURE HOW TO TEST THIS - SEE COMMENT IN PR */
console.debug(e.message);
}
if (typeof opts.mimeTypes === 'string') {
mime.load( path.join(dir, opts.mimeTypes) );
} else if (typeof opts.mimeTypes === 'object') {
mime.define(opts.mimeTypes);
}
Expand Down
32 changes: 11 additions & 21 deletions test/content-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test('custom contentType', function(t) {
t.ifError(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-type'], 'application/xml; charset=utf-8');
teardown();
teardown(t);
});
});
});
Expand All @@ -73,30 +73,20 @@ test('custom contentType via .types file', function(t) {
t.ifError(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-type'], 'application/xml; charset=utf-8');
teardown();
teardown(t);
});
});
});

/* NOT SURE HOW TO TEST THIS - SEE COMMENT IN PR
test('warning when custom contentType .types file does not exist', function(t) {
var server = setup({
root: __dirname + '/public/',
'mime-types': 'this_file_does_not_exist.types'
});
t.plan(3);
test('throws when custom contentType .types file does not exist', function(t) {
t.plan(1);

t.on('end', function() { server.close(); });
t.throws(
setup.bind(null, {
root: __dirname + '/public/',
'mime-types': 'this_file_does_not_exist.types'
})
);

server.listen(0, function() {
var port = server.address().port;
request.get('http://localhost:' + port + '/custom_mime_type.opml', function(err, res, body) {
t.ifError(err);
t.equal(res.statusCode, 200);
t.equal(res.headers['content-type'], 'application/xml; charset=utf-8');
teardown();
});
});
teardown(t);
});
*/

0 comments on commit 3a13400

Please sign in to comment.