Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(playwright-test): explicit proxy config will override env variab…
…les for REST interaction Serenity/JS Playwright Test adapter will now use the `proxy` property defined in Playwright Test config to override any proxy-related environment variables when instantiating the ability to CallAnApi. This will allow for consistent behaviour between the browser and the HTTP client. Related tickets: #1949
- Loading branch information
Showing
10 changed files
with
907 additions
and
151 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/rest/spec/screenplay/abilities/proxy/axiosProxyOverridesFor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { expect } from '@integration/testing-tools'; | ||
import axios from 'axios'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import { axiosProxyOverridesFor } from '../../../../src/screenplay/abilities/proxy'; | ||
import { ProxyAgent } from '../../../../src/screenplay/abilities/proxy/ProxyAgent'; | ||
|
||
describe('axiosProxyOverridesFor', () => { | ||
|
||
describe('when no proxy overrides are defined', () => { | ||
|
||
it('overrides Axios built-in proxy mechanism to use env variables', () => { | ||
|
||
const overrides = axiosProxyOverridesFor(axios.create({}).defaults); | ||
|
||
expect(overrides.proxy).to.equal(false); | ||
expect(overrides.httpAgent).to.be.instanceof(ProxyAgent); | ||
expect(overrides.httpsAgent).to.be.instanceof(ProxyAgent); | ||
}); | ||
}); | ||
|
||
describe('when proxy overrides are defined', () => { | ||
|
||
it('creates an Axios instance that overrides Axios built-in proxy mechanism', () => { | ||
|
||
const overrides = axiosProxyOverridesFor(axios.create({ | ||
proxy: { | ||
protocol: 'http', | ||
host: 'proxy.mycompany.com', | ||
port: 9000, | ||
} | ||
}).defaults); | ||
|
||
expect(overrides.proxy).to.equal(false); | ||
expect(overrides.httpAgent).to.be.instanceof(ProxyAgent); | ||
expect(overrides.httpsAgent).to.be.instanceof(ProxyAgent); | ||
}); | ||
}); | ||
}); |
41 changes: 0 additions & 41 deletions
41
packages/rest/spec/screenplay/abilities/proxy/withProxySupport.spec.ts
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
packages/rest/src/screenplay/abilities/AxiosRequestConfigDefaults.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { type CreateAxiosDefaults } from 'axios'; | ||
|
||
export type AxiosRequestConfigDefaults<Data = any> = Omit<CreateAxiosDefaults<Data>, 'proxy'> & { | ||
proxy?: { | ||
host: string; | ||
port?: number; // SOCKS proxy doesn't require port number | ||
auth?: { | ||
username: string; | ||
password: string; | ||
}; | ||
protocol?: string; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './AxiosRequestConfigDefaults'; | ||
export * from './CallAnApi'; |
16 changes: 3 additions & 13 deletions
16
...nplay/abilities/proxy/withProxySupport.ts → ...abilities/proxy/axiosProxyOverridesFor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './withProxySupport'; | ||
export * from './axiosProxyOverridesFor'; |