@@ -44,6 +44,8 @@ const internalExampleText: Record<string, string> = {
4444} ;
4545
4646const usingMockServer = process . env . DEEPL_MOCK_SERVER_PORT !== undefined ;
47+ const usingMockProxyServer =
48+ usingMockServer && process . env . DEEPL_MOCK_PROXY_SERVER_PORT !== undefined ;
4749
4850/**
4951 * Creates a random authKey for testing purposes. Only valid if using mock-server.
@@ -84,6 +86,7 @@ export interface TestTranslatorOptions {
8486 randomAuthKey ?: boolean ;
8587 maxRetries ?: number ;
8688 minTimeout ?: number ;
89+ proxy ?: deepl . ProxyConfig ;
8790
8891 mockServerNoResponseTimes ?: number ;
8992 mockServer429ResponseTimes ?: number ;
@@ -161,14 +164,24 @@ export function makeTranslator(options?: TestTranslatorOptions) {
161164 headers : sessionHeaders ,
162165 minTimeout : options ?. minTimeout ,
163166 maxRetries : options ?. maxRetries ,
167+ proxy : options ?. proxy ,
164168 } ) ;
165169}
166170
167171// Use instead of it(...) for tests that require a mock-server
168172export const withMockServer = usingMockServer ? it : it . skip ;
173+ // Use instead of it(...) for tests that require a mock-server with proxy
174+ export const withMockProxyServer = usingMockProxyServer ? it : it . skip ;
169175// Use instead of it(...) for tests that cannot run using mock-server
170176export const withRealServer = usingMockServer ? it . skip : it ;
171177
178+ const proxyUrlString = process . env . DEEPL_PROXY_URL ;
179+ const proxyUrl = proxyUrlString ? new URL ( proxyUrlString ) : undefined ;
180+ const proxyConfigHost = proxyUrl ? proxyUrl . hostname : '' ;
181+ const proxyConfigPort = parseInt ( process . env . DEEPL_MOCK_PROXY_SERVER_PORT || '' ) ;
182+
183+ export const proxyConfig : deepl . ProxyConfig = { host : proxyConfigHost , port : proxyConfigPort } ;
184+
172185// Wrap setTimeout() with Promise
173186export const timeout = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
174187
@@ -180,7 +193,9 @@ module.exports = {
180193 exampleLargeDocumentOutput,
181194 tempFiles,
182195 withMockServer,
196+ withMockProxyServer,
183197 withRealServer,
184198 makeTranslator,
185199 timeout,
200+ proxyConfig,
186201} ;
0 commit comments