From fa2fb79975c53f8a7d61f4bd70aa2a2346ebc20d Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Thu, 30 Dec 2021 16:34:38 +0100 Subject: [PATCH] imrove tests: is proxy used --- src/test/test.ts | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/src/test/test.ts b/src/test/test.ts index c221302..ee421db 100644 --- a/src/test/test.ts +++ b/src/test/test.ts @@ -10,7 +10,7 @@ import { join } from 'path'; import { IncomingMessage, ServerResponse } from 'http'; test('text content', async t => { - const testContent = JSON.stringify({ hello: 1, world: true}) + const testContent = JSON.stringify({ hello: 1, world: true }) const server = await createServer(); server.on('request', (req, res) => res.end(testContent)); @@ -45,9 +45,11 @@ test('binary content', async t => { test('proxy http to http', async t => { + let proxyUsed = false; const server = await createServer(); const proxy = await createProxy(); server.on('request', (req, res) => res.end('ok')); + proxy.on('request', () => proxyUsed = true); const proxyAddress = proxy.address() as AddressInfo; @@ -59,38 +61,18 @@ test('proxy http to http', async t => { t.is(response.responseText, 'ok'); t.is(response.status, 200); + t.is(proxyUsed, true); server.close(); proxy.close(); }); -test('invalid proxy http to http', async t => { - const server = await createServer(); - const proxy = await createProxy(); - server.on('request', (req, res) => res.end('ok')); - - const invalidProxyAddress = { - address: '192.168.29.165', - port: '808' - } - - configure(`http://${invalidProxyAddress.address}:${invalidProxyAddress.port}`, false); - - const serverAddress = server.address() as AddressInfo; - - await xhr({ url: `http://${serverAddress.address}:${serverAddress.port}` }).catch((response) => { - t.deepEqual(response.responseText, 'Unable to connect to http://' + `${serverAddress.address}` + ':' + `${serverAddress.port}` + ' through a proxy . Error: connect ECONNREFUSED 192.168.29.165:808'); - t.is(response.status, 404); - }); - server.close(); - proxy.close(); -}); - - test('proxy https to https', async t => { + let proxyUsed = false; const server = await createSecureServer(); const proxy = await createSecureProxy(); - server.on('request', (req, res) => res.end('ok')) + server.on('request', (req, res) => res.end('ok')); + proxy.on('request', () => proxyUsed = true); const proxyAddress = proxy.address() as AddressInfo; @@ -102,6 +84,7 @@ test('proxy https to https', async t => { t.is(response.responseText, 'ok'); t.is(response.status, 200); + t.is(proxyUsed, true); server.close(); proxy.close();