mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test: fix api coverage (#3114)
Coverage for browser-specific events was missing.
This commit is contained in:
parent
244ce45799
commit
30e21e0bee
@ -21,9 +21,10 @@
|
||||
* @param {string} className
|
||||
* @param {!Object} classType
|
||||
*/
|
||||
function traceAPICoverage(apiCoverage, events, className, classType) {
|
||||
function traceAPICoverage(apiCoverage, api, events) {
|
||||
const uninstalls = [];
|
||||
className = className.substring(0, 1).toLowerCase() + className.substring(1);
|
||||
for (const [name, classType] of Object.entries(api)) {
|
||||
const className = name.substring(0, 1).toLowerCase() + name.substring(1);
|
||||
for (const methodName of Reflect.ownKeys(classType.prototype)) {
|
||||
const method = Reflect.get(classType.prototype, methodName);
|
||||
if (methodName === 'constructor' || typeof methodName !== 'string' || methodName.startsWith('_') || typeof method !== 'function')
|
||||
@ -37,21 +38,21 @@ function traceAPICoverage(apiCoverage, events, className, classType) {
|
||||
Reflect.set(classType.prototype, methodName, override);
|
||||
uninstalls.push(() => Reflect.set(classType.prototype, methodName, method));
|
||||
}
|
||||
|
||||
if (events[classType.name]) {
|
||||
for (const event of Object.values(events[classType.name])) {
|
||||
if (events[name]) {
|
||||
const emitClassType = (name === 'BrowserContext' ? api['ChromiumBrowserContext'] : undefined) || classType;
|
||||
for (const event of Object.values(events[name])) {
|
||||
if (typeof event !== 'symbol')
|
||||
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, false);
|
||||
}
|
||||
const method = Reflect.get(classType.prototype, 'emit');
|
||||
Reflect.set(classType.prototype, 'emit', function(event, ...args) {
|
||||
const method = Reflect.get(emitClassType.prototype, 'emit');
|
||||
Reflect.set(emitClassType.prototype, 'emit', function(event, ...args) {
|
||||
if (typeof event !== 'symbol' && this.listenerCount(event))
|
||||
apiCoverage.set(`${className}.emit(${JSON.stringify(event)})`, true);
|
||||
return method.call(this, event, ...args);
|
||||
});
|
||||
uninstalls.push(() => Reflect.set(classType.prototype, 'emit', method));
|
||||
uninstalls.push(() => Reflect.set(emitClassType.prototype, 'emit', method));
|
||||
}
|
||||
}
|
||||
|
||||
return () => uninstalls.forEach(u => u());
|
||||
}
|
||||
|
||||
@ -72,7 +73,7 @@ function apiForBrowser(browserName) {
|
||||
name: 'Chromium',
|
||||
events: {
|
||||
...require('../../lib/events').Events,
|
||||
...require('../../lib/chromium/events').Events,
|
||||
ChromiumBrowserContext: require('../../lib/chromium/events').Events.CRBrowserContext,
|
||||
}
|
||||
},
|
||||
];
|
||||
@ -101,12 +102,9 @@ function apiForBrowser(browserName) {
|
||||
* @param {string} browserName
|
||||
*/
|
||||
function installCoverageHooks(browserName) {
|
||||
const uninstalls = [];
|
||||
const {api, events} = apiForBrowser(browserName);
|
||||
const coverage = new Map();
|
||||
for (const [name, value] of Object.entries(api))
|
||||
uninstalls.push(traceAPICoverage(coverage, events, name, value));
|
||||
const uninstall = () => uninstalls.map(u => u());
|
||||
const uninstall = traceAPICoverage(coverage, api, events);
|
||||
return {coverage, uninstall};
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user