chore: misc test fixes (#2857)

This commit is contained in:
Pavel Feldman 2020-07-08 18:42:31 -07:00 committed by GitHub
parent 6209d14f87
commit b3ca4afd40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 34 deletions

View File

@ -274,14 +274,12 @@ export type RequestInitializer = {
export interface RouteChannel extends Channel {
abort(params: { errorCode: string }): Promise<void>;
continue(params: { overrides: { method?: string, headers?: types.Headers, postData?: string } }): Promise<void>;
continue(params: { method?: string, headers?: types.Headers, postData?: string }): Promise<void>;
fulfill(params: {
response: {
status?: number,
headers?: types.Headers,
body: string,
isBase64: boolean,
}
status?: number,
headers?: types.Headers,
body: string,
isBase64: boolean,
}): Promise<void>;
}
export type RouteInitializer = {

View File

@ -152,11 +152,11 @@ export class Route extends ChannelOwner<RouteChannel, RouteInitializer> {
async fulfill(response: types.FulfillResponse & { path?: string }) {
const normalized = await normalizeFulfillParameters(response);
await this._channel.fulfill({ response: normalized });
await this._channel.fulfill(normalized);
}
async continue(overrides: { method?: string; headers?: types.Headers; postData?: string } = {}) {
await this._channel.continue({ overrides });
await this._channel.continue(overrides);
}
}

View File

@ -80,16 +80,15 @@ export class RouteDispatcher extends Dispatcher<Route, RouteInitializer> impleme
});
}
async continue(params: { overrides: { method?: string, headers?: types.Headers, postData?: string } }): Promise<void> {
await this._object.continue(params.overrides);
async continue(params: { method?: string, headers?: types.Headers, postData?: string }): Promise<void> {
await this._object.continue(params);
}
async fulfill(params: { response: { status?: number, headers?: types.Headers, contentType?: string, body: string, isBase64: boolean } }): Promise<void> {
const { response } = params;
async fulfill(params: { status?: number, headers?: types.Headers, contentType?: string, body: string, isBase64: boolean }): Promise<void> {
await this._object.fulfill({
status: response.status,
headers: response.headers,
body: response.isBase64 ? Buffer.from(response.body, 'base64') : response.body,
status: params.status,
headers: params.headers,
body: params.isBase64 ? Buffer.from(params.body, 'base64') : params.body,
});
}

View File

@ -90,13 +90,6 @@ describe('Page.evaluateHandle', function() {
}, { foo: 42 });
expect(result).toEqual({});
});
it('should use the same JS wrappers', async({page, server}) => {
const aHandle = await page.evaluateHandle(() => {
window.FOO = 123;
return window;
});
expect(await page.evaluate(e => e.FOO, aHandle)).toBe(123);
});
it('should work with primitives', async({page, server}) => {
const aHandle = await page.evaluateHandle(() => {
window.FOO = 123;
@ -152,10 +145,10 @@ describe('JSHandle.jsonValue', function() {
const json = await aHandle.jsonValue();
expect(json).toEqual({foo: 'bar'});
});
it('should not work with dates', async({page, server}) => {
it('should work with dates', async({page, server}) => {
const dateHandle = await page.evaluateHandle(() => new Date('2017-09-26T00:00:00.000Z'));
const json = await dateHandle.jsonValue();
expect(json).toEqual({});
expect(json instanceof Date).toBeTruthy();
});
it('should throw for circular objects', async({page, server}) => {
const windowHandle = await page.evaluateHandle('window');
@ -163,11 +156,6 @@ describe('JSHandle.jsonValue', function() {
await windowHandle.jsonValue().catch(e => error = e);
expect(error.message).toContain('Argument is a circular structure');
});
it('should work with tricky values', async({page, server}) => {
const aHandle = await page.evaluateHandle(() => ({a: 1}));
const json = await aHandle.jsonValue();
expect(json).toEqual({a: 1});
});
});
describe('JSHandle.getProperties', function() {

View File

@ -34,13 +34,13 @@ describe('Keyboard', function() {
await page.type('textarea', 'Hello World!');
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello World!');
for (let i = 0; i < 'World!'.length; i++)
page.keyboard.press('ArrowLeft');
await page.keyboard.press('ArrowLeft');
await page.keyboard.type('inserted ');
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello inserted World!');
page.keyboard.down('Shift');
await page.keyboard.down('Shift');
for (let i = 0; i < 'inserted '.length; i++)
page.keyboard.press('ArrowLeft');
page.keyboard.up('Shift');
await page.keyboard.press('ArrowLeft');
await page.keyboard.up('Shift');
await page.keyboard.press('Backspace');
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello World!');
});