Skip to content

Commit

Permalink
test: add localhost addresses test
Browse files Browse the repository at this point in the history
  • Loading branch information
KernelDeimos committed Sep 30, 2024
1 parent e8a96d0 commit b7c46ac
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/localhost.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const test = require('tap').test;
const ecstatic = require('../lib/core');
const http = require('http');
const request = require('request');

test('can connect from all localhost addresses', t => {
const server = http.createServer(ecstatic(`${__dirname}/public/subdir`));
t.on('end', () => { server.close(); });
server.listen(0, () => {
const port = server.address().port;
const addresses = [
'localhost',
'127.0.0.1',
'::1',
];

t.plan(addresses.length * 2);

for (const address of addresses) {
request.get(`http://${address}:${port}/index.html`, (err, res, body) => {
t.error(err);
t.equal(res.statusCode, 200);
});
}
});
});

0 comments on commit b7c46ac

Please sign in to comment.