Repository: puppeteer/puppeteer
File: test/src/cdp/devtools.spec.ts (TypeScript)

Code before:
  it('target.page() should return a DevTools page if custom isPageTarget is provided', async function () {
    const {puppeteer} = await getTestState({skipLaunch: true});
    const originalBrowser = await launchBrowser(launchOptions);

    const browserWSEndpoint = originalBrowser.wsEndpoint();

    const browser = await puppeteer.connect({
      browserWSEndpoint,
      _isPageTarget(target) {
        return (
          target.type() === 'other' && target.url().startsWith('devtools://')
        );
      },
    });
    const devtoolsPageTarget = await browser.waitForTarget(target => {
      return target.type() === 'other';
    });
    const page = (await devtoolsPageTarget.page())!;
    expect(
      await page.evaluate(() => {
        return 2 * 3;
      })
    ).toBe(6);
    expect(await browser.pages()).toContain(page);
  });
  it('target.page() should return a DevTools page if asPage is used', async function () {
    const {puppeteer} = await getTestState({skipLaunch: true});
    const originalBrowser = await launchBrowser(launchOptions);

    const browserWSEndpoint = originalBrowser.wsEndpoint();

    const browser = await puppeteer.connect({
      browserWSEndpoint,
    });
    const devtoolsPageTarget = await browser.waitForTarget(target => {
      return target.type() === 'other';
    });
    const page = (await devtoolsPageTarget.asPage())!;
    expect(
      await page.evaluate(() => {
        return 2 * 3;
      })
    ).toBe(6);
    // The page won't be part of browser.pages() if a custom isPageTarget is not provided
    expect(await browser.pages()).not.toContain(page);
  });
  it('should open devtools when "devtools: true" option is given', async () => {
    const browser = await launchBrowser(
      Object.assign({devtools: true}, launchOptions)
    );
    const context = await browser.createBrowserContext();

Review comment (suggestion):
Name should be closer to:
```suggestion
  it('target.page() should return Page when calling asPage on DevTools target', async function () {
```

Code after:
  it('target.page() should return a DevTools page if custom isPageTarget is provided', async function () {
    const {puppeteer} = await getTestState({skipLaunch: true});
    const originalBrowser = await launchBrowser(launchOptions);

    const browserWSEndpoint = originalBrowser.wsEndpoint();

    const browser = await puppeteer.connect({
      browserWSEndpoint,
      _isPageTarget(target) {
        return (
          target.type() === 'other' && target.url().startsWith('devtools://')
        );
      },
    });
    const devtoolsPageTarget = await browser.waitForTarget(target => {
      return target.type() === 'other';
    });
    const page = (await devtoolsPageTarget.page())!;
    expect(
      await page.evaluate(() => {
        return 2 * 3;
      })
    ).toBe(6);
    expect(await browser.pages()).toContain(page);
  });
  it('target.page() should return Page when calling asPage on DevTools target', async function () {
    const {puppeteer} = await getTestState({skipLaunch: true});
    const originalBrowser = await launchBrowser(launchOptions);

    const browserWSEndpoint = originalBrowser.wsEndpoint();

    const browser = await puppeteer.connect({
      browserWSEndpoint,
    });
    const devtoolsPageTarget = await browser.waitForTarget(target => {
      return target.type() === 'other';
    });
    const page = (await devtoolsPageTarget.asPage())!;
    expect(
      await page.evaluate(() => {
        return 2 * 3;
      })
    ).toBe(6);
    // The page won't be part of browser.pages() if a custom isPageTarget is not provided
    expect(await browser.pages()).not.toContain(page);
  });
  it('should open devtools when "devtools: true" option is given', async () => {
    const browser = await launchBrowser(
      Object.assign({devtools: true}, launchOptions)
    );
    const context = await browser.createBrowserContext();