more events
This commit is contained in:
parent
75a8ace20e
commit
bcf1240818
|
|
@ -18,7 +18,7 @@ import { MockingProxy } from '../mockingProxy';
|
||||||
import type { RootDispatcher } from './dispatcher';
|
import type { RootDispatcher } from './dispatcher';
|
||||||
import { Dispatcher, existingDispatcher } from './dispatcher';
|
import { Dispatcher, existingDispatcher } from './dispatcher';
|
||||||
import type * as channels from '@protocol/channels';
|
import type * as channels from '@protocol/channels';
|
||||||
import { APIRequestContextDispatcher, RequestDispatcher, RouteDispatcher } from './networkDispatchers';
|
import { APIRequestContextDispatcher, RequestDispatcher, ResponseDispatcher, RouteDispatcher } from './networkDispatchers';
|
||||||
import type { Request, Route } from '../network';
|
import type { Request, Route } from '../network';
|
||||||
import { urlMatches } from '../../utils/isomorphic/urlMatch';
|
import { urlMatches } from '../../utils/isomorphic/urlMatch';
|
||||||
|
|
||||||
|
|
@ -43,6 +43,20 @@ export class MockingProxyDispatcher extends Dispatcher<MockingProxy, channels.Mo
|
||||||
this.addObjectListener(MockingProxy.Events.Request, ({ request, correlation }: { request: Request, correlation?: string }) => {
|
this.addObjectListener(MockingProxy.Events.Request, ({ request, correlation }: { request: Request, correlation?: string }) => {
|
||||||
this._dispatchEvent('request', { request: RequestDispatcher.from(this as any, request), correlation });
|
this._dispatchEvent('request', { request: RequestDispatcher.from(this as any, request), correlation });
|
||||||
});
|
});
|
||||||
|
this.addObjectListener(MockingProxy.Events.RequestFailed, (request: Request) => {
|
||||||
|
this._dispatchEvent('requestFailed', {
|
||||||
|
request: RequestDispatcher.from(this as any, request),
|
||||||
|
failureText: request._failureText ?? undefined,
|
||||||
|
responseEndTiming: request._responseEndTiming,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.addObjectListener(MockingProxy.Events.RequestFinished, (request: Request) => {
|
||||||
|
this._dispatchEvent('requestFinished', {
|
||||||
|
request: RequestDispatcher.from(this as any, request),
|
||||||
|
response: ResponseDispatcher.fromNullable(this as any, request._existingResponse()),
|
||||||
|
responseEndTiming: request._responseEndTiming,
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async setInterceptionPatterns(params: channels.MockingProxySetInterceptionPatternsParams, metadata?: CallMetadata): Promise<channels.MockingProxySetInterceptionPatternsResult> {
|
async setInterceptionPatterns(params: channels.MockingProxySetInterceptionPatternsParams, metadata?: CallMetadata): Promise<channels.MockingProxySetInterceptionPatternsResult> {
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ export class MockingProxy extends SdkObject implements RequestContext {
|
||||||
response.setTransferSize(transferSize);
|
response.setTransferSize(transferSize);
|
||||||
response.setEncodedBodySize(encodedBodySize);
|
response.setEncodedBodySize(encodedBodySize);
|
||||||
response.setResponseHeadersSize(transferSize - encodedBodySize);
|
response.setResponseHeadersSize(transferSize - encodedBodySize);
|
||||||
this.emit(MockingProxy.Events.RequestFinished, { request, response });
|
this.emit(MockingProxy.Events.RequestFinished, request);
|
||||||
resolve();
|
resolve();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
request._setFailureText('' + error);
|
request._setFailureText('' + error);
|
||||||
|
|
|
||||||
|
|
@ -134,11 +134,9 @@ test('all properties are populated', async ({ runInlineTest, server, request })
|
||||||
expect(await response.headersArray()).toContainEqual({ name: 'foo', value: 'bar' });
|
expect(await response.headersArray()).toContainEqual({ name: 'foo', value: 'bar' });
|
||||||
expect(await response.body()).toEqual(Buffer.from('fallback'));
|
expect(await response.body()).toEqual(Buffer.from('fallback'));
|
||||||
|
|
||||||
// TODO: implement, this currently blocks because requestFinished isn't emitted
|
expect(await response.finished()).toBe(null);
|
||||||
// expect(await response.finished()).toBe(null);
|
|
||||||
expect(request.serviceWorker()).toBe(null);
|
expect(request.serviceWorker()).toBe(null);
|
||||||
expect(request.frame()).not.toBe(null);
|
expect(request.frame()).not.toBe(null);
|
||||||
expect(response.frame()).not.toBe(null);
|
|
||||||
|
|
||||||
expect(request.failure()).toBe(null);
|
expect(request.failure()).toBe(null);
|
||||||
expect(request.isNavigationRequest()).toBe(false);
|
expect(request.isNavigationRequest()).toBe(false);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue