From af78cc768fb6eadcf192e8de7294f71cd45194a0 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Mon, 8 Aug 2022 16:31:12 +0200 Subject: [PATCH] chore: fix proxy-related tests (#8753) --- test/src/proxy.spec.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/src/proxy.spec.ts b/test/src/proxy.spec.ts index d5b2a2f07c0..eb71905355d 100644 --- a/test/src/proxy.spec.ts +++ b/test/src/proxy.spec.ts @@ -27,7 +27,21 @@ import type {Browser} from '../../lib/cjs/puppeteer/common/Browser.js'; import type {AddressInfo} from 'net'; import {TestServer} from '../../utils/testserver/lib/index.js'; -const HOSTNAME = os.hostname().toLowerCase(); +let HOSTNAME = os.hostname(); + +// Hostname might not be always accessible in environments other than GitHub +// Actions. Therefore, we try to find an external IPv4 address to be used as a +// hostname in these tests. +const networkInterfaces = os.networkInterfaces(); +for (const key of Object.keys(networkInterfaces)) { + const interfaces = networkInterfaces[key]; + for (const net of interfaces || []) { + if (net.family === 'IPv4' && !net.internal) { + HOSTNAME = net.address; + break; + } + } +} /** * Requests to localhost do not get proxied by default. Create a URL using the hostname