From 00597b3258b5b09216816fb1f08c81a2e2c75cd3 Mon Sep 17 00:00:00 2001 From: Yosuke Saito Date: Sat, 12 Nov 2016 16:47:27 +0900 Subject: [PATCH] test: fix test-http-status-reason-invalid-chars.js Use port 0 instead of common.PORT, and use server address instead of localhost to follow writing test guideline. This is a part of Code And Learn at NodeFest 2016 Challenge in Tokyo. PR-URL: https://github.com/nodejs/node/pull/9572 --- test/parallel/test-http-status-reason-invalid-chars.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http-status-reason-invalid-chars.js b/test/parallel/test-http-status-reason-invalid-chars.js index 7a8564a906131a..245822d0146975 100644 --- a/test/parallel/test-http-status-reason-invalid-chars.js +++ b/test/parallel/test-http-status-reason-invalid-chars.js @@ -3,6 +3,7 @@ const common = require('../common'); const assert = require('assert'); const http = require('http'); +const net = require('net'); function explicit(req, res) { assert.throws(() => { @@ -32,8 +33,10 @@ const server = http.createServer((req, res) => { } else { implicit(req, res); } -}).listen(common.PORT, common.mustCall(() => { - const url = `http://localhost:${common.PORT}`; +}).listen(0, common.mustCall(() => { + const addr = server.address().address; + const hostname = net.isIPv6(addr) ? `[${addr}1]` : addr; + const url = `http://${hostname}:${server.address().port}`; let left = 2; const check = common.mustCall((res) => { left--;