make it an enum

This commit is contained in:
Simon Knott 2025-02-03 16:13:44 +01:00
parent b0cce73542
commit fe608159ac
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
5 changed files with 10 additions and 8 deletions

View file

@ -679,7 +679,7 @@ export default defineConfig({
## property: TestOptions.mockingProxy
* since: v1.51
- type: <[boolean]> Enables the mocking proxy. Playwright will inject the proxy URL into all outgoing requests under the `x-playwright-proxy` header.
- type: <[MockingProxyMode]<"off"|"inject-via-header">> Enables the mocking proxy. Playwright will inject the proxy URL into all outgoing requests under the `x-playwright-proxy` header.
**Usage**
@ -688,7 +688,7 @@ import { defineConfig } from '@playwright/test';
export default defineConfig({
use: {
mockingProxy: true
mockingProxy: 'inject-via-header'
},
});
```

View file

@ -74,8 +74,8 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel> {
return (channel as any)._object;
}
async _startMockingProxy(requestContextOptions: NewContextOptions) {
const requestContext = await this.request._newContext(requestContextOptions, this._connection.localUtils()._channel);
async _startMockingProxy() {
const requestContext = await this.request._newContext(undefined, this._connection.localUtils()._channel);
const { mockingProxy } = await this._connection.localUtils()._channel.newMockingProxy({ requestContext: requestContext._channel });
return (mockingProxy as any)._object;
}

View file

@ -125,7 +125,7 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({
}, { scope: 'worker', timeout: 0 }],
_mockingProxy: [async ({ mockingProxy: mockingProxyOption, playwright }, use) => {
if (!mockingProxyOption)
if (mockingProxyOption !== 'inject-via-header')
return await use(undefined);
const mockingProxy = await (playwright as PlaywrightImpl)._startMockingProxy();
await use(mockingProxy);

View file

@ -6166,18 +6166,19 @@ export interface PlaywrightWorkerOptions {
*
* export default defineConfig({
* use: {
* mockingProxy: true
* mockingProxy: 'inject-via-header'
* },
* });
* ```
*
*/
mockingProxy: boolean | undefined;
mockingProxy: MockingProxyMode | undefined;
}
export type ScreenshotMode = 'off' | 'on' | 'only-on-failure' | 'on-first-failure';
export type TraceMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry' | 'on-all-retries' | 'retain-on-first-failure';
export type VideoMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry';
export type MockingProxyMode = 'off' | 'inject-via-header';
/**
* Playwright Test provides many options to configure test environment,

View file

@ -236,12 +236,13 @@ export interface PlaywrightWorkerOptions {
screenshot: ScreenshotMode | { mode: ScreenshotMode } & Pick<PageScreenshotOptions, 'fullPage' | 'omitBackground'>;
trace: TraceMode | /** deprecated */ 'retry-with-trace' | { mode: TraceMode, snapshots?: boolean, screenshots?: boolean, sources?: boolean, attachments?: boolean };
video: VideoMode | /** deprecated */ 'retry-with-video' | { mode: VideoMode, size?: ViewportSize };
mockingProxy: boolean | undefined;
mockingProxy: MockingProxyMode | undefined;
}
export type ScreenshotMode = 'off' | 'on' | 'only-on-failure' | 'on-first-failure';
export type TraceMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry' | 'on-all-retries' | 'retain-on-first-failure';
export type VideoMode = 'off' | 'on' | 'retain-on-failure' | 'on-first-retry';
export type MockingProxyMode = 'off' | 'inject-via-header';
export interface PlaywrightTestOptions {
acceptDownloads: boolean;