Skip to content

Commit

Permalink
chore: make tests more resilient in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Oct 25, 2024
1 parent 2b801f4 commit e7970f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 12 additions & 6 deletions test/cli/host-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const os = require('os')
const dns = require('dns')
let { test, fail, comment } = require('tap')
const { serve } = require('./common')
const port = 1338
Expand Down Expand Up @@ -73,12 +74,6 @@ testServer(
['127.0.0.1', 'localhost', otherAddress], []
)

testServer(
'Restricted to localhost',
['--localhost'], 'localhost',
['127.0.0.1', 'localhost'], [otherAddress]
)

testServer(
'Restricted to non-local host',
['--host', otherAddress], otherAddress,
Expand All @@ -90,3 +85,14 @@ testServer(
['--host', '127.0.0.1'], '127.0.0.1',
['127.0.0.1'], ['::1']
)

dns.lookup('localhost', (err, address) => {
if (err) {
throw err
}
testServer(
'Restricted to localhost',
['--localhost'], 'localhost',
[address, 'localhost'], [otherAddress]
)
})
5 changes: 3 additions & 2 deletions test/multi-mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test('setup middleware server', function (t) {
})
})
})
middlewareServer.listen(port, '127.0.0.1', function () {
middlewareServer.listen(port, 'localhost', function () {
t.pass('listening')
t.end()
})
Expand All @@ -103,7 +103,7 @@ test('setup regular server', function (t) {
return res.end(`Not a match: ${req.url}`)
}
})
server.listen(port + 1, '127.0.0.1', function () {
server.listen(port + 1, 'localhost', function () {
t.pass('listening')
t.end()
})
Expand All @@ -114,6 +114,7 @@ const stExpect = fs.readFileSync(require.resolve('../st.js')).toString()

test('/test/st.js', function (t) {
req('/test/st.js', function (er, res, body) {
t.error(er)
t.equal(res.statusCode, 200)
t.ok(res.headers.etag)
stEtag = res.headers.etag
Expand Down

0 comments on commit e7970f0

Please sign in to comment.