Compare commits

...

11 Commits

Author SHA1 Message Date
Douglas Christopher Wilson
9a77df8c77 1.5.1 2014-11-22 23:21:30 -05:00
Douglas Christopher Wilson
856450da8f tests: use assert instead of should 2014-11-22 23:01:45 -05:00
Douglas Christopher Wilson
1bda9f95e4 deps: supertest@~0.15.0 2014-11-22 22:26:12 -05:00
Douglas Christopher Wilson
f0652de409 deps: mocha@~2.0.1 2014-11-22 22:25:24 -05:00
Douglas Christopher Wilson
f0579f7093 deps: mime-types@~2.0.3 2014-11-22 22:24:52 -05:00
Douglas Christopher Wilson
970b567f48 deps: accepts@~1.1.3 2014-11-22 22:22:37 -05:00
Douglas Christopher Wilson
47b3884bbe 1.5.0 2014-10-17 01:31:52 -04:00
Douglas Christopher Wilson
5b2ff74554 Create errors with http-errors 2014-10-16 23:16:04 -04:00
Douglas Christopher Wilson
7dc0ff4d97 deps: debug@~2.1.0 2014-10-16 23:10:10 -04:00
Douglas Christopher Wilson
1bdd53c05d deps: mime-types@~2.0.2 2014-10-16 23:08:47 -04:00
Douglas Christopher Wilson
dce12186f8 docs: Gittip is now Gratipay 2014-10-16 23:07:23 -04:00
5 changed files with 72 additions and 76 deletions

View File

@@ -1,3 +1,21 @@
1.5.1 / 2014-11-22
==================
* deps: accepts@~1.1.3
- deps: mime-types@~2.0.3
* deps: mime-types@~2.0.3
- Add new mime types
- deps: mime-db@~1.2.0
1.5.0 / 2014-10-16
==================
* Create errors with `http-errors`
* deps: debug@~2.1.0
- Implement `DEBUG_FD` env variable support
* deps: mime-types@~2.0.2
- deps: mime-db@~1.1.0
1.4.1 / 2014-10-15
==================

View File

@@ -4,7 +4,7 @@
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![Gittip][gittip-image]][gittip-url]
[![Gratipay][gratipay-image]][gratipay-url]
Serves pages that contain directory listings for a given path.
@@ -123,5 +123,5 @@ are created by/copyright of [FAMFAMFAM](http://www.famfamfam.com/).
[coveralls-url]: https://coveralls.io/r/expressjs/serve-index?branch=master
[downloads-image]: https://img.shields.io/npm/dm/serve-index.svg?style=flat
[downloads-url]: https://npmjs.org/package/serve-index
[gittip-image]: https://img.shields.io/gittip/dougwilson.svg?style=flat
[gittip-url]: https://www.gittip.com/dougwilson/
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
[gratipay-url]: https://www.gratipay.com/dougwilson/

View File

@@ -1,4 +1,3 @@
/*!
* serve-index
* Copyright(c) 2011 Sencha Inc.
@@ -15,9 +14,9 @@
*/
var accepts = require('accepts');
var createError = require('http-errors');
var debug = require('debug')('serve-index');
var http = require('http')
, fs = require('fs')
var fs = require('fs')
, path = require('path')
, normalize = path.normalize
, sep = path.sep
@@ -214,22 +213,6 @@ exports.plain = function(req, res, files){
res.end(buf);
};
/**
* Generate an `Error` from the given status `code`
* and optional `msg`.
*
* @param {Number} code
* @param {String} msg
* @return {Error}
* @api private
*/
function createError(code, msg) {
var err = new Error(msg || http.STATUS_CODES[code]);
err.status = code;
return err;
};
/**
* Sort function for with directories first.
*/

View File

@@ -1,22 +1,23 @@
{
"name": "serve-index",
"description": "Serve directory listings",
"version": "1.4.1",
"version": "1.5.1",
"author": "Douglas Christopher Wilson <doug@somethingdoug.com>",
"license": "MIT",
"repository": "expressjs/serve-index",
"dependencies": {
"accepts": "~1.1.2",
"accepts": "~1.1.3",
"batch": "0.5.1",
"debug": "~2.0.0",
"mime-types": "~2.0.1",
"debug": "~2.1.0",
"http-errors": "~1.2.7",
"mime-types": "~2.0.3",
"parseurl": "~1.3.0"
},
"devDependencies": {
"after": "0.8.1",
"istanbul": "0.3.2",
"mocha": "~1.21.5",
"should": "~4.0.0",
"supertest": "~0.14.0"
"mocha": "~2.0.1",
"supertest": "~0.15.0"
},
"files": [
"public/",

View File

@@ -1,9 +1,10 @@
var after = require('after');
var assert = require('assert');
var http = require('http');
var fs = require('fs');
var path = require('path');
var request = require('supertest');
var should = require('should');
var serveIndex = require('..');
var fixtures = path.join(__dirname, '/fixtures');
@@ -13,7 +14,7 @@ var skipRelative = ~relative.indexOf('..') || path.resolve(relative) === relativ
describe('serveIndex(root)', function () {
it('should require root', function () {
serveIndex.should.throw(/root path required/)
assert.throws(serveIndex, /root path required/)
})
it('should serve text/html without Accept header', function (done) {
@@ -146,7 +147,7 @@ describe('serveIndex(root)', function () {
.end(function (err, res) {
if (err) throw err;
var urls = res.text.split(/<a href="([^"]*)"/).filter(function(s, i){ return i%2; });
urls.should.eql([
assert.deepEqual(urls, [
'/%23directory',
'/collect',
'/g%23%20%253%20o%20%252525%20%2537%20dir',
@@ -198,11 +199,8 @@ describe('serveIndex(root)', function () {
request(server)
.get('/')
.expect(200, function (err, res) {
if (err) return done(err)
res.text.should.not.containEql('.hidden')
done()
});
.expect(bodyDoesNotContain('.hidden'))
.expect(200, done)
});
it('should filter hidden files', function (done) {
@@ -210,11 +208,8 @@ describe('serveIndex(root)', function () {
request(server)
.get('/')
.expect(200, function (err, res) {
if (err) return done(err)
res.text.should.not.containEql('.hidden')
done()
});
.expect(bodyDoesNotContain('.hidden'))
.expect(200, done)
});
it('should not filter hidden files', function (done) {
@@ -228,61 +223,51 @@ describe('serveIndex(root)', function () {
describe('with "filter" option', function () {
it('should custom filter files', function (done) {
var seen = false
var cb = after(2, done)
var server = createServer(fixtures, {'filter': filter})
function filter(name) {
if (name.indexOf('foo') === -1) return true
seen = true
cb()
return false
}
request(server)
.get('/')
.expect(200, function (err, res) {
if (err) return done(err)
seen.should.be.true
res.text.should.not.containEql('foo')
done()
});
.expect(bodyDoesNotContain('foo'))
.expect(200, cb)
});
it('should filter after hidden filter', function (done) {
var seen = false
var server = createServer(fixtures, {'filter': filter, 'hidden': false})
function filter(name) {
seen = seen || name.indexOf('.') === 0
if (name.indexOf('.') === 0) {
done(new Error('unexpected hidden file'))
}
return true
}
request(server)
.get('/')
.expect(200, function (err, res) {
if (err) return done(err)
seen.should.be.false
done()
});
.expect(200, done)
});
it('should filter directory paths', function (done) {
var seen = false
var cb = after(3, done)
var server = createServer(fixtures, {'filter': filter})
function filter(name, index, list, dir) {
if (path.normalize(dir) === path.normalize(path.join(fixtures, '/users'))) {
seen = true
cb()
}
return true
}
request(server)
.get('/users')
.expect(200, function (err, res) {
if (err) return done(err)
seen.should.be.true
done()
});
.expect(200, cb)
});
});
@@ -306,10 +291,7 @@ describe('serveIndex(root)', function () {
describe('when using custom handler', function () {
describe('exports.html', function () {
var orig = serveIndex.html
after(function () {
serveIndex.html = orig
})
alterProperty(serveIndex, 'html', serveIndex.html)
it('should get called with Accept: text/html', function (done) {
var server = createServer()
@@ -404,10 +386,7 @@ describe('serveIndex(root)', function () {
});
describe('exports.plain', function () {
var orig = serveIndex.plain
after(function () {
serveIndex.plain = orig
})
alterProperty(serveIndex, 'plain', serveIndex.plain)
it('should get called with Accept: text/plain', function (done) {
var server = createServer()
@@ -425,10 +404,7 @@ describe('serveIndex(root)', function () {
});
describe('exports.json', function () {
var orig = serveIndex.json
after(function () {
serveIndex.json = orig
})
alterProperty(serveIndex, 'json', serveIndex.json)
it('should get called with Accept: application/json', function (done) {
var server = createServer()
@@ -604,6 +580,18 @@ describe('serveIndex(root)', function () {
});
});
function alterProperty(obj, prop, val) {
var prev
beforeEach(function () {
prev = obj[prop]
obj[prop] = val
})
afterEach(function () {
obj[prop] = prev
})
}
function createServer(dir, opts) {
dir = dir || fixtures
@@ -616,3 +604,9 @@ function createServer(dir, opts) {
})
})
}
function bodyDoesNotContain(text) {
return function (res) {
assert.equal(res.text.indexOf(text), -1)
}
}