@@ -2,6 +2,8 @@ import { expect, test } from '@oclif/test';
2
2
import path from 'path' ;
3
3
import rimraf from 'rimraf' ;
4
4
import { createMockServer , stopMockServer } from '../../helpers' ;
5
+ import { HttpsProxyAgent } from 'https-proxy-agent' ;
6
+ import fetch from 'node-fetch' ;
5
7
const generalOptions = [ 'generate:models' ] ;
6
8
const outputDir = './test/fixtures/generate/models' ;
7
9
@@ -36,6 +38,67 @@ describe('models', () => {
36
38
done ( ) ;
37
39
} ) ;
38
40
41
+ describe ( 'proxy-related tests' , ( ) => {
42
+ test
43
+ . stderr ( )
44
+ . stdout ( )
45
+ . env ( { PROXY_HOST : '127.0.0.1' , PROXY_PORT : '3128' } ) // Mock environment variables for proxy
46
+ . do ( ( ) => {
47
+ process . env . PROXY_HOST = '127.0.0.1' ;
48
+ process . env . PROXY_PORT = '3128' ;
49
+ } )
50
+ . command ( [ ...generalOptions , 'typescript' , 'http://localhost:8080/dummySpec.yml' , '--proxyHost=127.0.0.1' , '--proxyPort=3128' ] )
51
+ . it ( 'works with proxy settings' , ( ctx , done ) => {
52
+ expect ( ctx . stdout ) . to . contain ( 'Successfully generated the following models: ' ) ;
53
+ expect ( process . env . PROXY_HOST ) . to . equal ( '127.0.0.1' ) ;
54
+ expect ( process . env . PROXY_PORT ) . to . equal ( '3128' ) ;
55
+ done ( ) ;
56
+ } ) ;
57
+
58
+ test
59
+ . stderr ( )
60
+ . stdout ( )
61
+ . command ( [ ...generalOptions , 'typescript' , 'http://localhost:8080/dummySpec.yml' ] )
62
+ . it ( 'works without proxy settings' , ( ctx , done ) => {
63
+ expect ( ctx . stdout ) . to . contain ( 'Successfully generated the following models: ' ) ;
64
+ done ( ) ;
65
+ } ) ;
66
+ } ) ;
67
+
68
+ describe ( 'fetch with proxy and without proxy' , ( ) => {
69
+ test
70
+ . stderr ( )
71
+ . stdout ( )
72
+ . do ( ( ) => {
73
+ const proxyUrl = 'http://127.0.0.1:3128' ;
74
+ const proxyAgent = new HttpsProxyAgent ( proxyUrl ) ;
75
+ const customFetch = ( url , options = { } ) => fetch ( url , { ...options , agent : proxyAgent } ) ;
76
+
77
+ customFetch ( 'http://localhost:8080/dummySpec.yml' )
78
+ . then ( ( response ) => {
79
+ expect ( response . ok ) . to . be . true ;
80
+ } )
81
+ . catch ( ( err ) => {
82
+ throw new Error ( `Failed to fetch with proxy: ${ err . message } ` ) ;
83
+ } ) ;
84
+ } )
85
+ . it ( 'tests fetch with proxy agent' ) ;
86
+
87
+ test
88
+ . stderr ( )
89
+ . stdout ( )
90
+ . do ( ( ) => {
91
+ fetch ( 'http://localhost:8080/dummySpec.yml' )
92
+ . then ( ( response ) => {
93
+ expect ( response . ok ) . to . be . true ;
94
+ } )
95
+ . catch ( ( err ) => {
96
+ throw new Error ( `Failed to fetch without proxy: ${ err . message } ` ) ;
97
+ } ) ;
98
+ } )
99
+ . it ( 'tests fetch without proxy agent' ) ;
100
+ } ) ;
101
+
39
102
describe ( 'with logging diagnostics' , ( ) => {
40
103
test
41
104
. stderr ( )
0 commit comments