From 0eb144cb2a9f03eeec8b6432ba21373f2c51b93a Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 22 Mar 2018 20:52:33 -0700 Subject: [PATCH 1/2] Added tests which should highlight errors in compression and index handling --- test/fixtures/br.json.gz | Bin 0 -> 48 bytes test/fixtures/index.html/index | 1 + test/fixtures/world/world | 1 + test/index.js | 42 +++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 test/fixtures/br.json.gz create mode 100644 test/fixtures/index.html/index create mode 100644 test/fixtures/world/world diff --git a/test/fixtures/br.json.gz b/test/fixtures/br.json.gz new file mode 100644 index 0000000000000000000000000000000000000000..89b085de38a13bddfe1ee1066a26c5a2aa1d1e24 GIT binary patch literal 48 zcmb2|=HN)qxDdj?oL-e#pqEvgpU1E|EZ~&)8Q;)NK>=DP{ZEAitzczXU(NMRh=G9t E0Hsk85&!@I literal 0 HcmV?d00001 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..29664fa 100644 --- a/test/index.js +++ b/test/index.js @@ -180,6 +180,33 @@ 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 +494,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 () { From a4d91196a98f6cfd848d586c05ee33ca6571b13e Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 22 Mar 2018 21:02:22 -0700 Subject: [PATCH 2/2] Restored lost braces --- test/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/index.js b/test/index.js index 29664fa..d72a503 100644 --- a/test/index.js +++ b/test/index.js @@ -207,6 +207,7 @@ describe('send(ctx, file)', function () { .get('/') .expect(404, done) }) + }) }) describe('when path is not a file', function () {