Skip to content

Commit

Permalink
chore: update deps, fix linting, fix tap parallel & deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed May 20, 2021
1 parent 4501e97 commit c541c5c
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 28 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
27 changes: 18 additions & 9 deletions st.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -560,10 +565,14 @@ class Mount {
return ['<a href="' + linkName + '">' + showName + '</a>',
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(' ')
Expand Down
8 changes: 4 additions & 4 deletions test/cli/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions test/cli/host-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
}
Expand Down
Empty file added test/cli/tap-parallel-not-ok
Empty file.
4 changes: 2 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -56,7 +56,7 @@ test('setup', (t) => {
})
})

tearDown(() => {
teardown(() => {
server.close()
})

Expand Down
4 changes: 2 additions & 2 deletions test/dot-common.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down Expand Up @@ -37,7 +37,7 @@ test('setup', (t) => {
})
})

tearDown(() => {
teardown(() => {
server.close()
})

Expand Down
2 changes: 1 addition & 1 deletion test/gzip-after-no-gzip.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions test/preset-cache-control.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -42,7 +42,7 @@ test('setup', (t) => {
})
})

tearDown(() => {
teardown(() => {
server.close()
})

Expand Down
Empty file added test/tap-parallel-not-ok
Empty file.

0 comments on commit c541c5c

Please sign in to comment.