MCPcopy Create free account
hub / github.com/facebook/memlab / testInBrowser

Function testInBrowser

packages/api/src/API.ts:448–501  ·  view source on GitHub ↗
(options: APIOptions = {})

Source from the content-addressed store, hash-verified

446 * @internal
447 */
448export async function testInBrowser(options: APIOptions = {}): Promise<void> {
449 const config = options.config ?? defaultConfig;
450 if (config.verbose) {
451 info.lowLevel(`Xvfb: ${config.useXVFB}`);
452 }
453
454 const testPlanner = options.testPlanner ?? defaultTestPlanner;
455 let interactionManager: Nullable<E2EInteractionManager> = null;
456 let xvfb: Nullable<XvfbType> = null;
457 let browser: Nullable<Browser> = null;
458 let page: Nullable<Page> = null;
459 let maybeError: Nullable<Error> = null;
460 try {
461 xvfb = Xvfb.startIfEnabled();
462 browser = await APIUtils.getBrowser();
463 const pages = await browser.pages();
464 page = pages.length > 0 ? pages[0] : await browser.newPage();
465 // create and configure web page interaction manager
466 interactionManager = new E2EInteractionManager(page, browser);
467 if (options.evalInBrowserAfterInitLoad) {
468 interactionManager.setEvalFuncAfterInitLoad(
469 options.evalInBrowserAfterInitLoad,
470 );
471 }
472 const visitPlan = testPlanner.getVisitPlan();
473 // setup page configuration
474 config.setDevice(visitPlan.device);
475 await initBrowserInfoInConfig(browser);
476 browserInfo.monitorWebConsole(page);
477 await setupPage(page, options);
478 // interact with the web page and take heap snapshots
479 await interactionManager.visitAndGetSnapshots(options);
480 } catch (ex) {
481 maybeError = utils.getError(ex);
482 utils.checkUninstalledLibrary(maybeError);
483 } finally {
484 if (browser && page) {
485 await utils.closePuppeteer(browser, [page]);
486 }
487 if (interactionManager) {
488 interactionManager.clearCDPSession();
489 }
490 if (xvfb) {
491 xvfb.stop((err: Optional<Error>) => {
492 if (err) {
493 utils.haltOrThrow(err);
494 }
495 });
496 }
497 if (maybeError != null) {
498 utils.haltOrThrow(maybeError);
499 }
500 }
501}

Callers 4

warmupAndTakeSnapshotsFunction · 0.85
runFunction · 0.85
takeSnapshotsFunction · 0.85

Calls 11

initBrowserInfoInConfigFunction · 0.85
setupPageFunction · 0.85
lowLevelMethod · 0.80
getVisitPlanMethod · 0.80
setDeviceMethod · 0.80
monitorWebConsoleMethod · 0.80
visitAndGetSnapshotsMethod · 0.80
clearCDPSessionMethod · 0.80
stopMethod · 0.80
haltOrThrowMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…