diff --git a/test/fixtures/br.json.gz b/test/fixtures/br.json.gz new file mode 100644 index 0000000..89b085d Binary files /dev/null and b/test/fixtures/br.json.gz differ diff --git a/test/fixtures/index.html/index b/test/fixtures/index.html/index new file mode 100644 index 0000000..2fa59a7 --- /dev/null +++ b/test/fixtures/index.html/index @@ -0,0 +1 @@ +text index \ No newline at end of file diff --git a/test/fixtures/world/world b/test/fixtures/world/world new file mode 100644 index 0000000..3e575fa --- /dev/null +++ b/test/fixtures/world/world @@ -0,0 +1 @@ +html index \ No newline at end of file diff --git a/test/index.js b/test/index.js index f1f9c6a..d72a503 100644 --- a/test/index.js +++ b/test/index.js @@ -180,6 +180,34 @@ describe('send(ctx, file)', function () { .expect('html index', done) }) }) + + describe('when the index file is not present', function () { + it('should 404 if the index is a directory', function (done) { + const app = new Koa() + + app.use(async (ctx) => { + const opts = { root: 'test', index: 'index', extensions:['html', 'htm'] } + await send(ctx, 'fixtures/', opts) + }) + + request(app.listen()) + .get('/') + .expect(404, done) + }) + + it('should 404 if the index is a directory', function (done) { + const app = new Koa() + + app.use(async (ctx) => { + const opts = { root: 'test', index: 'world' } + await send(ctx, 'fixtures/', opts) + }) + + request(app.listen()) + .get('/') + .expect(404, done) + }) + }) }) describe('when path is not a file', function () { @@ -467,6 +495,21 @@ describe('send(ctx, file)', function () { .expect('{ "name": "tobi" }') .expect(200, done) }) + + it('should return .gz path when brotli is unavailable', function (done) { + const app = new Koa() + + app.use(async (ctx) => { + await send(ctx, '/test/fixtures/br.json') + }) + + request(app.listen()) + .get('/') + .set('Accept-Encoding', 'br, gzip, deflate, identity') + .expect('Content-Length', '48') + .expect('{ "name": "tobi" }') + .expect(200, done) + }) }) describe('and max age is specified', function () {