fix!: make console warn level compatible with WebDriver BiDi (#11790)

This commit is contained in:
Alex Rudenko 2024-02-02 13:22:07 +01:00 committed by GitHub
parent f18d44761c
commit d4e9d8d591
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 11 deletions

View File

@ -14,7 +14,7 @@ export type ConsoleMessageType =
| 'debug'
| 'info'
| 'error'
| 'warning'
| 'warn'
| 'dir'
| 'dirxml'
| 'table'

View File

@ -33,6 +33,7 @@ import {Coverage} from '../cdp/Coverage.js';
import {EmulationManager as CdpEmulationManager} from '../cdp/EmulationManager.js';
import {FrameTree} from '../cdp/FrameTree.js';
import {Tracing} from '../cdp/Tracing.js';
import type {ConsoleMessageType} from '../common/ConsoleMessage.js';
import {
ConsoleMessage,
type ConsoleMessageLocation,
@ -408,7 +409,7 @@ export class BidiPage extends Page {
this.emit(
PageEvent.Console,
new ConsoleMessage(
event.method as any,
event.method as ConsoleMessageType,
text,
args,
getStackTraceLocations(event.stackTrace)

View File

@ -85,6 +85,15 @@ import {
} from './utils.js';
import {CdpWebWorker} from './WebWorker.js';
function convertConsoleMessageLevel(method: string): ConsoleMessageType {
switch (method) {
case 'warning':
return 'warn';
default:
return method as ConsoleMessageType;
}
}
/**
* @internal
*/
@ -475,7 +484,12 @@ export class CdpPage extends Page {
if (source !== 'worker') {
this.emit(
PageEvent.Console,
new ConsoleMessage(level, text, [], [{url, lineNumber}])
new ConsoleMessage(
convertConsoleMessageLevel(level),
text,
[],
[{url, lineNumber}]
)
);
}
}
@ -811,7 +825,11 @@ export class CdpPage extends Page {
const values = event.args.map(arg => {
return createCdpHandle(context._world, arg);
});
this.#addConsoleMessage(event.type, values, event.stackTrace);
this.#addConsoleMessage(
convertConsoleMessageLevel(event.type),
values,
event.stackTrace
);
}
async #onBindingCalled(
@ -843,7 +861,7 @@ export class CdpPage extends Page {
}
#addConsoleMessage(
eventType: ConsoleMessageType,
eventType: string,
args: JSHandle[],
stackTrace?: Protocol.Runtime.StackTrace
): void {
@ -875,7 +893,7 @@ export class CdpPage extends Page {
}
}
const message = new ConsoleMessage(
eventType,
convertConsoleMessageLevel(eventType),
textTokens.join(' '),
args,
stackTraceLocations

View File

@ -8,7 +8,6 @@ import type {Protocol} from 'devtools-protocol';
import type {CDPSession} from '../api/CDPSession.js';
import type {Realm} from '../api/Realm.js';
import {WebWorker} from '../api/WebWorker.js';
import type {ConsoleMessageType} from '../common/ConsoleMessage.js';
import {TimeoutSettings} from '../common/TimeoutSettings.js';
import {debugError} from '../common/util.js';
@ -20,7 +19,7 @@ import {CdpJSHandle} from './JSHandle.js';
* @internal
*/
export type ConsoleAPICalledCallback = (
eventType: ConsoleMessageType,
eventType: string,
handles: CdpJSHandle[],
trace?: Protocol.Runtime.StackTrace
) => void;

View File

@ -35,7 +35,7 @@ export type ConsoleMessageType =
| 'debug'
| 'info'
| 'error'
| 'warning'
| 'warn'
| 'dir'
| 'dirxml'
| 'table'

View File

@ -922,7 +922,7 @@
"testIdPattern": "[page.spec] Page Page.Events.Console should work for different console API calls with logging functions",
"platforms": ["darwin", "linux", "win32"],
"parameters": ["webDriverBiDi"],
"expectations": ["FAIL"]
"expectations": ["PASS"]
},
{
"testIdPattern": "[page.spec] Page Page.Events.error should throw when page crashes",

View File

@ -445,7 +445,7 @@ describe('Page', function () {
messages.map(msg => {
return msg.type();
})
).toEqual(['trace', 'dir', 'warning', 'error', 'log']);
).toEqual(['trace', 'dir', 'warn', 'error', 'log']);
expect(
messages.map(msg => {
return msg.text();