1. /** @flow */
    
  2. 
    
  3. 'use strict';
    
  4. 
    
  5. const {runOnlyForReactRange} = require('./utils');
    
  6. const listAppUtils = require('./list-app-utils');
    
  7. const devToolsUtils = require('./devtools-utils');
    
  8. const {test, expect} = require('@playwright/test');
    
  9. const config = require('../../playwright.config');
    
  10. test.use(config);
    
  11. test.describe('Profiler', () => {
    
  12.   let page;
    
  13. 
    
  14.   test.beforeEach(async ({browser}) => {
    
  15.     page = await browser.newPage();
    
  16.     await page.goto(config.use.url, {
    
  17.       waitUntil: 'domcontentloaded',
    
  18.     });
    
  19. 
    
  20.     await page.waitForSelector('#iframe');
    
  21. 
    
  22.     await devToolsUtils.clickButton(page, 'TabBarButton-profiler');
    
  23.   });
    
  24. 
    
  25.   test('should record renders and commits when active', async () => {
    
  26.     // Profiling is only available in 16.5 and over
    
  27.     runOnlyForReactRange('>=16.5');
    
  28.     async function getSnapshotSelectorText() {
    
  29.       return await page.evaluate(() => {
    
  30.         const {createTestNameSelector, findAllNodes} =
    
  31.           window.REACT_DOM_DEVTOOLS;
    
  32.         const container = document.getElementById('devtools');
    
  33. 
    
  34.         const input = findAllNodes(container, [
    
  35.           createTestNameSelector('SnapshotSelector-Input'),
    
  36.         ])[0];
    
  37.         const label = findAllNodes(container, [
    
  38.           createTestNameSelector('SnapshotSelector-Label'),
    
  39.         ])[0];
    
  40.         return `${input.value}${label.innerText}`;
    
  41.       });
    
  42.     }
    
  43. 
    
  44.     async function clickButtonAndVerifySnapshotSelectorText(
    
  45.       buttonTagName,
    
  46.       expectedText
    
  47.     ) {
    
  48.       await devToolsUtils.clickButton(page, buttonTagName);
    
  49.       const text = await getSnapshotSelectorText();
    
  50.       expect(text).toBe(expectedText);
    
  51.     }
    
  52. 
    
  53.     await devToolsUtils.clickButton(page, 'ProfilerToggleButton');
    
  54. 
    
  55.     await listAppUtils.addItem(page, 'four');
    
  56.     await listAppUtils.addItem(page, 'five');
    
  57.     await listAppUtils.addItem(page, 'six');
    
  58. 
    
  59.     await devToolsUtils.clickButton(page, 'ProfilerToggleButton');
    
  60. 
    
  61.     await page.waitForFunction(() => {
    
  62.       const {createTestNameSelector, findAllNodes} = window.REACT_DOM_DEVTOOLS;
    
  63.       const container = document.getElementById('devtools');
    
  64. 
    
  65.       const input = findAllNodes(container, [
    
  66.         createTestNameSelector('SnapshotSelector-Input'),
    
  67.       ]);
    
  68. 
    
  69.       return input.length === 1;
    
  70.     });
    
  71. 
    
  72.     const text = await getSnapshotSelectorText();
    
  73.     expect(text).toBe('1 / 3');
    
  74. 
    
  75.     await clickButtonAndVerifySnapshotSelectorText(
    
  76.       'SnapshotSelector-NextButton',
    
  77.       '2 / 3'
    
  78.     );
    
  79.     await clickButtonAndVerifySnapshotSelectorText(
    
  80.       'SnapshotSelector-NextButton',
    
  81.       '3 / 3'
    
  82.     );
    
  83.     await clickButtonAndVerifySnapshotSelectorText(
    
  84.       'SnapshotSelector-NextButton',
    
  85.       '1 / 3'
    
  86.     );
    
  87.     await clickButtonAndVerifySnapshotSelectorText(
    
  88.       'SnapshotSelector-PreviousButton',
    
  89.       '3 / 3'
    
  90.     );
    
  91.     await clickButtonAndVerifySnapshotSelectorText(
    
  92.       'SnapshotSelector-PreviousButton',
    
  93.       '2 / 3'
    
  94.     );
    
  95.     await clickButtonAndVerifySnapshotSelectorText(
    
  96.       'SnapshotSelector-PreviousButton',
    
  97.       '1 / 3'
    
  98.     );
    
  99.     await clickButtonAndVerifySnapshotSelectorText(
    
  100.       'SnapshotSelector-PreviousButton',
    
  101.       '3 / 3'
    
  102.     );
    
  103.   });
    
  104. });