diff --git a/package.json b/package.json index d45e1d9..5f198c3 100644 --- a/package.json +++ b/package.json @@ -6,18 +6,18 @@ "bin": "bin/server.js", "dependencies": { "async-cache": "^1.1.0", - "bl": "^4.0.0", - "fd": "~0.0.2", - "mime": "^2.4.4", + "bl": "^5.0.0", + "fd": "~0.0.3", + "mime": "^2.5.2", "negotiator": "~0.6.2" }, "optionalDependencies": { "graceful-fs": "^4.2.3" }, "devDependencies": { - "request": "^2.88.0", - "rimraf": "^3.0.0", - "standard": "^14.3.1", + "request": "^2.88.2", + "rimraf": "^3.0.2", + "standard": "^16.0.3", "tap": "^15.0.9" }, "scripts": { diff --git a/st.js b/st.js index 545ed57..9496781 100644 --- a/st.js +++ b/st.js @@ -115,8 +115,10 @@ class Mount { this.opt = opt this.url = opt.url this.path = opt.path - this._index = opt.index === false ? false - : typeof opt.index === 'string' ? opt.index + this._index = opt.index === false + ? false + : typeof opt.index === 'string' + ? opt.index : true this.fdman = FD() @@ -348,9 +350,12 @@ class Mount { } error (er, res) { - res.statusCode = typeof er === 'number' ? er - : er.code === 'ENOENT' || er.code === 'EISDIR' ? 404 - : er.code === 'EPERM' || er.code === 'EACCES' ? 403 + res.statusCode = typeof er === 'number' + ? er + : er.code === 'ENOENT' || er.code === 'EISDIR' + ? 404 + : er.code === 'EPERM' || er.code === 'EACCES' + ? 403 : 500 if (typeof res.error === 'function') { @@ -560,10 +565,14 @@ class Mount { return ['' + showName + '', d.mtime, d.size, showName] }).sort((a, b) => { - return a[2] === '-' && b[2] !== '-' ? -1 // dirs first - : a[2] !== '-' && b[2] === '-' ? 1 - : a[0].toLowerCase() < b[0].toLowerCase() ? -1 // then alpha - : a[0].toLowerCase() > b[0].toLowerCase() ? 1 + return a[2] === '-' && b[2] !== '-' // dirs first + ? -1 + : a[2] !== '-' && b[2] === '-' + ? 1 + : a[0].toLowerCase() < b[0].toLowerCase() // then alpha + ? -1 + : a[0].toLowerCase() > b[0].toLowerCase() + ? 1 : 0 }).forEach((line) => { const namePad = new Array(8 + nameLen - line[3].length).join(' ') diff --git a/test/cli/basic-test.js b/test/cli/basic-test.js index 56f99fb..3e81d29 100644 --- a/test/cli/basic-test.js +++ b/test/cli/basic-test.js @@ -4,12 +4,12 @@ const { serve, stExpect } = require('./common') test('Basic cli operation', (t) => { serve([], (req) => { req('/st.js', (er, res, body) => { - t.ifError(er) && + t.error(er) && t.equal(res.statusCode, 200) && t.equal(body.toString(), stExpect) }) }, (er, stdout, stderr) => { - t.ifError(er) + t.error(er) t.match(stdout, /^listening at http:\/\/(\[::\]|0\.0\.0\.0):[0-9]+\n$/) t.equal(stderr, '') t.end() @@ -19,12 +19,12 @@ test('Basic cli operation', (t) => { test('Listening on localhost only', (t) => { serve(['--localhost'], (req) => { req('/st.js', (er, res, body) => { - t.ifError(er) && + t.error(er) && t.equal(res.statusCode, 200) && t.equal(body.toString(), stExpect) }) }, (er, stdout, stderr) => { - t.ifError(er) + t.error(er) t.match(stdout, /^listening at http:\/\/localhost:[0-9]+\n$/) t.equal(stderr, '') t.end() diff --git a/test/cli/host-test.js b/test/cli/host-test.js index d3998a6..780c6bc 100644 --- a/test/cli/host-test.js +++ b/test/cli/host-test.js @@ -44,7 +44,7 @@ function testServer (name, args, addr, canConnect, cannotConnect) { canConnect.forEach(checkConnections(t, req, true)) cannotConnect.forEach(checkConnections(t, req, false)) }, (err, stdout, stderr) => { - t.ifError(err) + t.error(err) t.equal(stderr, '') if (addr) { t.equal(stdout, 'listening at ' + addr2url(addr) + '\n') @@ -59,7 +59,7 @@ function checkConnections (t, req, canConnect) { const url = addr2url(addr, '/st.js') req(url, (er, res, body) => { if (canConnect) { - t.ifError(er, url) && t.equal(res.statusCode, 200, url) + t.error(er, url) && t.equal(res.statusCode, 200, url) } else { t.ok(er, url) } diff --git a/test/cli/tap-parallel-not-ok b/test/cli/tap-parallel-not-ok new file mode 100644 index 0000000..e69de29 diff --git a/test/common.js b/test/common.js index 9ee57ae..f855ee0 100644 --- a/test/common.js +++ b/test/common.js @@ -2,7 +2,7 @@ const path = require('path') const fs = require('fs') const http = require('http') const request = require('request') -const { test, tearDown } = require('tap') +const { test, teardown } = require('tap') const st = require('../st.js') @@ -56,7 +56,7 @@ test('setup', (t) => { }) }) -tearDown(() => { +teardown(() => { server.close() }) diff --git a/test/dot-common.js b/test/dot-common.js index f221f63..9cfb33b 100644 --- a/test/dot-common.js +++ b/test/dot-common.js @@ -1,7 +1,7 @@ const path = require('path') const http = require('http') const request = require('request') -const { test, tearDown } = require('tap') +const { test, teardown } = require('tap') const st = require('../st.js') @@ -37,7 +37,7 @@ test('setup', (t) => { }) }) -tearDown(() => { +teardown(() => { server.close() }) diff --git a/test/gzip-after-no-gzip.js b/test/gzip-after-no-gzip.js index 114b1f7..512ce6c 100644 --- a/test/gzip-after-no-gzip.js +++ b/test/gzip-after-no-gzip.js @@ -25,7 +25,7 @@ test('gzips second response', (t) => { t.equal(res.headers['x-from-cache'], 'true') t.ok(body, 'returned a body') - t.notEqual(body.toString(), stExpect, 'gzipped string') + t.not(body.toString(), stExpect, 'gzipped string') zlib.gunzip(body, (er, body) => { if (er) { diff --git a/test/preset-cache-control.js b/test/preset-cache-control.js index 4e78804..0aa143c 100644 --- a/test/preset-cache-control.js +++ b/test/preset-cache-control.js @@ -1,5 +1,5 @@ const st = require('../st.js') -const { test, tearDown } = require('tap') +const { test, teardown } = require('tap') const path = require('path') const http = require('http') const request = require('request') @@ -42,7 +42,7 @@ test('setup', (t) => { }) }) -tearDown(() => { +teardown(() => { server.close() }) diff --git a/test/tap-parallel-not-ok b/test/tap-parallel-not-ok new file mode 100644 index 0000000..e69de29