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 { export interface RouteChannel extends Channel {
abort(params: { errorCode: string }): Promise<void>; 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: { fulfill(params: {
response: { status?: number,
status?: number, headers?: types.Headers,
headers?: types.Headers, body: string,
body: string, isBase64: boolean,
isBase64: boolean,
}
}): Promise<void>; }): Promise<void>;
} }
export type RouteInitializer = { export type RouteInitializer = {

View file

@ -152,11 +152,11 @@ export class Route extends ChannelOwner<RouteChannel, RouteInitializer> {
async fulfill(response: types.FulfillResponse & { path?: string }) { async fulfill(response: types.FulfillResponse & { path?: string }) {
const normalized = await normalizeFulfillParameters(response); 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 } = {}) { 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> { async continue(params: { method?: string, headers?: types.Headers, postData?: string }): Promise<void> {
await this._object.continue(params.overrides); await this._object.continue(params);
} }
async fulfill(params: { response: { status?: number, headers?: types.Headers, contentType?: string, body: string, isBase64: boolean } }): Promise<void> { async fulfill(params: { status?: number, headers?: types.Headers, contentType?: string, body: string, isBase64: boolean }): Promise<void> {
const { response } = params;
await this._object.fulfill({ await this._object.fulfill({
status: response.status, status: params.status,
headers: response.headers, headers: params.headers,
body: response.isBase64 ? Buffer.from(response.body, 'base64') : response.body, body: params.isBase64 ? Buffer.from(params.body, 'base64') : params.body,
}); });
} }

View file

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

View file

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