From 49dc789850c1d345086f4bba9b111fc0084c900a Mon Sep 17 00:00:00 2001 From: Lloyd Brookes Date: Fri, 19 Feb 2016 19:48:35 +0000 Subject: [PATCH] upgrade koa-static --- package.json | 2 +- test/static.js | 33 +++++++++++++++++++++++++++++++++ test/test.js | 16 ---------------- 3 files changed, 34 insertions(+), 17 deletions(-) create mode 100644 test/static.js diff --git a/package.json b/package.json index b72b1c8..4ecead6 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "koa-route": "^3", "koa-send": "^3.1.0", "koa-serve-index": "^1.1.0", - "koa-static": "^1.5.2", + "koa-static": "^2.0.0", "path-to-regexp": "^1.2.1", "stream-log-stats": "^1.1.2", "string-tools": "^1.0.0", diff --git a/test/static.js b/test/static.js new file mode 100644 index 0000000..837d684 --- /dev/null +++ b/test/static.js @@ -0,0 +1,33 @@ +'use strict' +const test = require('tape') +const request = require('req-then') +const localWebServer = require('../') +const http = require('http') + +function launchServer (app, options) { + options = options || {} + const path = `http://localhost:8100${options.path || '/'}` + const server = http.createServer(app.callback()) + return server.listen(options.port || 8100, () => { + const req = request(path, options.reqOptions) + if (options.onSuccess) req.then(options.onSuccess) + if (!options.leaveOpen) req.then(() => server.close()) + req.catch(err => console.error('LAUNCH ERROR', err.stack)) + }) +} + +test('static', function (t) { + t.plan(1) + const app = localWebServer({ + log: { format: 'none' }, + static: { + root: __dirname + '/fixture', + options: { + index: 'file.txt' + } + } + }) + launchServer(app, { onSuccess: response => { + t.ok(/test/.test(response.data)) + }}) +}) diff --git a/test/test.js b/test/test.js index 4231b6d..22dc2fb 100644 --- a/test/test.js +++ b/test/test.js @@ -24,22 +24,6 @@ function checkResponse (t, status, body) { } } -test('static', function (t) { - t.plan(1) - const app = localWebServer({ - log: { format: 'none' }, - static: { - root: __dirname + '/fixture', - options: { - index: 'file.txt' - } - } - }) - launchServer(app, { onSuccess: response => { - t.ok(/test/.test(response.data)) - }}) -}) - test('serve-index', function (t) { t.plan(2) const app = localWebServer({