@@ -33,6 +33,8 @@ import { LOCATIONS } from '../fixtures/locationinfo';
3333import { Server } from '../utils/server' ;
3434import { CLIMock } from '../utils/test-config' ;
3535import { mkdir , rm , writeFile } from 'fs/promises' ;
36+ // import { createProxyServer } from 'http-proxy';
37+ // import http from "http";
3638
3739describe ( 'Locations' , ( ) => {
3840 const apiKey = 'foo' ;
@@ -97,10 +99,11 @@ describe('Locations', () => {
9799 } ) ;
98100
99101 const runLocations = async ( args : Array < string > = [ ] ) => {
100- const cli = new CLIMock ( )
102+ const cli = new CLIMock ( true )
101103 . args ( [ 'locations' , ...args ] )
102104 . run ( { cwd : PROJECT_DIR , env : process . env } ) ;
103- expect ( await cli . exitCode ) . toBe ( 0 ) ;
105+ // expect(await cli.exitCode).toBe(0);
106+ console . log ( cli . stderr ( ) ) ;
104107 return cli . stderr ( ) ;
105108 } ;
106109
@@ -125,5 +128,50 @@ describe('Locations', () => {
125128 expect ( output ) . toContain ( `custom location 1` ) ;
126129 expect ( output ) . toContain ( `custom location 2` ) ;
127130 } ) ;
131+
132+ describe ( 'Proxy options' , ( ) => {
133+ // let requests: Array<any> = [];
134+ // let proxyServer;
135+
136+ beforeAll ( async ( ) => {
137+ await fakeProjectSetup ( { url : server . PREFIX } ) ;
138+ // proxyServer = createProxyServer({ target: server.PREFIX }).listen(8019);
139+ // proxyServer.on('proxyReq', function (proxyReq, req) {
140+ // requests.push(req);
141+ // });
142+ // const proxy = createProxyServer({});
143+
144+ //
145+ // Create your custom server and just call `proxy.web()` to proxy
146+ // a web request to the target passed in the options
147+ // also you can use `proxy.ws()` to proxy a websockets request
148+ //
149+ // proxyServer = http.createServer(function (req, res) {
150+ // proxy.web(req, res, { target: server.PREFIX });
151+ // }).listen(8019);
152+ } ) ;
153+
154+ // afterAll(async () => {
155+ // proxyServer.close();
156+ // });
157+
158+ // beforeEach(() => {
159+ // requests = []
160+ // });
161+
162+ it ( 'enables proxy based on HTTP_PROXY' , async ( ) => {
163+ const output = await runLocations ( [
164+ '--url' ,
165+ server . PREFIX ,
166+ '--auth' ,
167+ apiKey ,
168+ '--proxy-uri' ,
169+ 'http://localhost:9191' ,
170+ ] ) ;
171+ console . log ( output ) ;
172+ // expect(requests).toHaveLength(1);
173+ expect ( output ) . toContain ( `custom location 1` ) ;
174+ } ) ;
175+ } ) ;
128176 } ) ;
129177} ) ;
0 commit comments