mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-01 01:38:07 +08:00
Eliminate initial timeout in waitForFunction
Bug: 1112692 Change-Id: I28bc29b0f5c2af55d3cf54614fe4d6641b64dd76 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2336716 Reviewed-by: Mathias Bynens <mathias@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Changhao Han <changhaohan@chromium.org> Commit-Queue: Changhao Han <changhaohan@chromium.org> Commit-Queue: Mathias Bynens <mathias@chromium.org>
This commit is contained in:
@@ -37,6 +37,11 @@ describe('The Console Tab', async () => {
|
||||
await frontend.keyboard.press('Enter');
|
||||
});
|
||||
|
||||
// Wait for the console to be usable again.
|
||||
await frontend.waitForFunction(() => {
|
||||
return document.querySelectorAll('.console-user-command-result').length === 2;
|
||||
});
|
||||
|
||||
await step('retrieve the console log', async () => {
|
||||
messages = await getCurrentConsoleMessages();
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import {assert} from 'chai';
|
||||
import {describe, it} from 'mocha';
|
||||
|
||||
import {closeAllCloseableTabs, getBrowserAndPages, goToResource} from '../../shared/helper.js';
|
||||
import {closeAllCloseableTabs, getBrowserAndPages, goToResource, timeout} from '../../shared/helper.js';
|
||||
import {getCurrentConsoleMessages} from '../helpers/console-helpers.js';
|
||||
import {openPanelViaMoreTools} from '../helpers/settings-helpers.js';
|
||||
|
||||
@@ -17,6 +17,8 @@ describe('Browser', async () => {
|
||||
|
||||
// Open a few closeable panels
|
||||
await openPanelViaMoreTools('Animations');
|
||||
// FIXME(crbug/1112692): Refactor test to remove the timeout.
|
||||
await timeout(100);
|
||||
await openPanelViaMoreTools('Rendering');
|
||||
|
||||
const messages = await getCurrentConsoleMessages();
|
||||
@@ -37,6 +39,8 @@ describe('Browser', async () => {
|
||||
|
||||
// Open a few closeable panels
|
||||
await openPanelViaMoreTools('Animations');
|
||||
// FIXME(crbug/1112692): Refactor test to remove the timeout.
|
||||
await timeout(100);
|
||||
await openPanelViaMoreTools('Rendering');
|
||||
|
||||
await closeAllCloseableTabs();
|
||||
|
||||
@@ -6,7 +6,7 @@ import {assert} from 'chai';
|
||||
import {describe, it} from 'mocha';
|
||||
import * as puppeteer from 'puppeteer';
|
||||
|
||||
import {click, getBrowserAndPages, goToResource, waitFor} from '../../shared/helper.js';
|
||||
import {click, getBrowserAndPages, goToResource, timeout, waitFor} from '../../shared/helper.js';
|
||||
import {assertContentOfSelectedElementsNode, getAriaLabelSelectorFromPropertiesSelector, getComputedStylesForDomNode, getCSSPropertySwatchStyle, getDisplayedCSSPropertyNames, getDisplayedStyleRules, getStyleSectionSubtitles, waitForElementsStyleSection, waitForStyleRule} from '../helpers/elements-helpers.js';
|
||||
|
||||
const PROPERTIES_TO_DELETE_SELECTOR = '#properties-to-delete';
|
||||
@@ -32,6 +32,9 @@ describe('The Styles pane', async () => {
|
||||
await goToResource('elements/simple-styled-page.html');
|
||||
await waitForElementsStyleSection();
|
||||
|
||||
// FIXME(crbug/1112692): Refactor test to remove the timeout.
|
||||
await timeout(100);
|
||||
|
||||
// Select the H1 element by pressing down, since <body> is the default selected element.
|
||||
const onH1RuleAppeared = waitForStyleRule('h1');
|
||||
await frontend.keyboard.press('ArrowDown');
|
||||
@@ -126,6 +129,9 @@ describe('The Styles pane', async () => {
|
||||
await goToResource('elements/stylesheets-with-various-sources.html');
|
||||
await waitForElementsStyleSection();
|
||||
|
||||
// FIXME(crbug/1112692): Refactor test to remove the timeout.
|
||||
await timeout(100);
|
||||
|
||||
// Select the div element by pressing down, since <body> is the default selected element.
|
||||
const onDivRuleAppeared = waitForStyleRule('div');
|
||||
await frontend.keyboard.press('ArrowDown');
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import * as puppeteer from 'puppeteer';
|
||||
|
||||
import {$, click, getBrowserAndPages, goToResource, pasteText, waitFor} from '../../shared/helper.js';
|
||||
import {$, click, getBrowserAndPages, goToResource, pasteText, timeout, waitFor} from '../../shared/helper.js';
|
||||
|
||||
export const CONSOLE_TAB_SELECTOR = '#tab-console';
|
||||
export const CONSOLE_MESSAGES_SELECTOR = '.console-group-messages';
|
||||
@@ -74,6 +74,9 @@ export async function getCurrentConsoleMessages(
|
||||
|
||||
const selector = withAnchor ? CONSOLE_MESSAGE_TEXT_AND_ANCHOR_SELECTOR : CONSOLE_FIRST_MESSAGES_SELECTOR;
|
||||
|
||||
// FIXME(crbug/1112692): Refactor test to remove the timeout.
|
||||
await timeout(100);
|
||||
|
||||
// Get the messages from the console.
|
||||
return frontend.evaluate(selector => {
|
||||
return Array.from(document.querySelectorAll(selector)).map(message => message.textContent);
|
||||
|
||||
@@ -138,7 +138,8 @@ export const forcePseudoState = async (pseudoState: string) => {
|
||||
// Open element state pane and wait for it to be loaded asynchronously
|
||||
await click('[aria-label="Toggle Element State"]');
|
||||
await waitFor(`[aria-label="${pseudoState}"]`);
|
||||
|
||||
// FIXME(crbug/1112692): Refactor test to remove the timeout.
|
||||
await timeout(100);
|
||||
await click(`[aria-label="${pseudoState}"]`);
|
||||
};
|
||||
|
||||
@@ -283,5 +284,7 @@ export const navigateToElementsTab = async () => {
|
||||
|
||||
export const clickOnFirstLinkInStylesPanel = async () => {
|
||||
const stylesPane = await waitFor('div.styles-pane');
|
||||
// FIXME(crbug/1112692): Refactor test to remove the timeout.
|
||||
await timeout(100);
|
||||
await click('div.styles-section-subtitle span.devtools-link', {root: stylesPane});
|
||||
};
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import {assert} from 'chai';
|
||||
|
||||
import {$$, click, goToResource, waitFor, waitForNone} from '../../shared/helper.js';
|
||||
import {$$, click, goToResource, waitFor, waitForFunction, waitForNone} from '../../shared/helper.js';
|
||||
|
||||
const NEW_HEAP_SNAPSHOT_BUTTON = 'button[aria-label="Take heap snapshot"]';
|
||||
const MEMORY_PANEL_CONTENT = 'div[aria-label="Memory panel"]';
|
||||
@@ -27,8 +25,11 @@ export async function takeHeapSnapshot() {
|
||||
export async function waitForHeapSnapshotData() {
|
||||
await waitFor('#profile-views');
|
||||
await waitFor('#profile-views .data-grid');
|
||||
const rowCount = await getCountOfDataGridRows('#profile-views table.data');
|
||||
assert.notEqual(rowCount, 0);
|
||||
const rowCountNotZero = async () => {
|
||||
const rowCount = await getCountOfDataGridRows('#profile-views table.data');
|
||||
return rowCount !== 0;
|
||||
};
|
||||
await waitForFunction(rowCountNotZero);
|
||||
}
|
||||
|
||||
export async function getCountOfDataGridRows(selector: string) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import {assert} from 'chai';
|
||||
import * as puppeteer from 'puppeteer';
|
||||
|
||||
import {$$, click, getBrowserAndPages, getHostedModeServerPort, goToResource, pressKey, step, typeText, waitFor} from '../../shared/helper.js';
|
||||
import {$$, click, getBrowserAndPages, getHostedModeServerPort, goToResource, pressKey, step, typeText, waitFor, waitForFunction} from '../../shared/helper.js';
|
||||
|
||||
export const PAUSE_ON_EXCEPTION_BUTTON = '[aria-label="Pause on exceptions"]';
|
||||
export const PAUSE_BUTTON = '[aria-label="Pause script execution"]';
|
||||
@@ -113,6 +113,10 @@ export async function sourceLineNumberSelector(lineNumber: number) {
|
||||
|
||||
export async function checkBreakpointIsActive(lineNumber: number) {
|
||||
await step(`check that the breakpoint is still active at line ${lineNumber}`, async () => {
|
||||
await waitForFunction(async () => {
|
||||
const elements = await $$(SOURCES_LINES_SELECTOR);
|
||||
return elements.length >= lineNumber;
|
||||
});
|
||||
const sourcesLines = await $$(SOURCES_LINES_SELECTOR);
|
||||
const codeLineNums = await Promise.all(sourcesLines.map(elements => {
|
||||
return elements.evaluate(el => el.className);
|
||||
@@ -310,7 +314,7 @@ export async function getScopeNames() {
|
||||
return scopeNames;
|
||||
}
|
||||
|
||||
export async function getValuesForScope(scope: string, expandCount = 0) {
|
||||
export async function getValuesForScope(scope: string, expandCount = 0, waitForNoOfValues = 0) {
|
||||
const scopeSelector = `[aria-label="${scope}"]`;
|
||||
await waitFor(scopeSelector);
|
||||
for (let i = 0; i < expandCount; i++) {
|
||||
@@ -319,7 +323,13 @@ export async function getValuesForScope(scope: string, expandCount = 0) {
|
||||
await click(unexpandedSelector);
|
||||
}
|
||||
const valueSelector = `${scopeSelector} + ol .name-and-value`;
|
||||
const valueSelectorElements = await $$(valueSelector);
|
||||
const valueSelectorElements = await waitForFunction(async () => {
|
||||
const elements = await $$(valueSelector);
|
||||
if (elements.length >= waitForNoOfValues) {
|
||||
return elements;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
const values = await Promise.all(valueSelectorElements.map(elem => elem.evaluate(n => n.textContent as string)));
|
||||
return values;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import {assert} from 'chai';
|
||||
import {describe, it} from 'mocha';
|
||||
|
||||
import {getBrowserAndPages, getResourcesPath, goToResource, waitFor} from '../../shared/helper.js';
|
||||
import {getBrowserAndPages, getResourcesPath, goToResource, timeout, waitFor} from '../../shared/helper.js';
|
||||
import {getCurrentUrl} from '../helpers/layers-helpers.js';
|
||||
import {openPanelViaMoreTools} from '../helpers/settings-helpers.js';
|
||||
|
||||
@@ -17,6 +17,10 @@ describe('The Layers Panel', async () => {
|
||||
await openPanelViaMoreTools('Layers');
|
||||
|
||||
await waitFor('[aria-label="layers"]:not([test-current-url=""])');
|
||||
|
||||
// FIXME(crbug/1112692): Refactor test to remove the timeout.
|
||||
await timeout(100);
|
||||
|
||||
const url = await getCurrentUrl();
|
||||
assert.strictEqual(url, `${getResourcesPath()}/${targetUrl}`);
|
||||
});
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {describe, it} from 'mocha';
|
||||
|
||||
import {$$} from '../../shared/helper.js';
|
||||
import {navigateToMemoryTab, takeHeapSnapshot, waitForHeapSnapshotData} from '../helpers/memory-helpers.js';
|
||||
|
||||
describe('The Memory Panel', async () => {
|
||||
@@ -17,5 +19,7 @@ describe('The Memory Panel', async () => {
|
||||
await waitForHeapSnapshotData();
|
||||
await takeHeapSnapshot();
|
||||
await waitForHeapSnapshotData();
|
||||
const heapSnapShots = await $$('.heap-snapshot-sidebar-tree-item');
|
||||
assert.strictEqual(heapSnapShots.length, 2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,12 +66,12 @@ describe('Source Tab', async () => {
|
||||
});
|
||||
|
||||
await step('check that the module scope content is as before', async () => {
|
||||
const currentModuleScopeValues = await getValuesForScope('Module');
|
||||
const currentModuleScopeValues = await getValuesForScope('Module', 0, moduleScopeValues.length);
|
||||
assert.deepEqual(currentModuleScopeValues, moduleScopeValues);
|
||||
});
|
||||
|
||||
await step('check that the local scope content is as before', async () => {
|
||||
const updatedLocalScopeValues = await getValuesForScope('Local');
|
||||
const updatedLocalScopeValues = await getValuesForScope('Local', 0, localScopeValues.length);
|
||||
assert.deepEqual(updatedLocalScopeValues, localScopeValues);
|
||||
});
|
||||
|
||||
|
||||
@@ -178,9 +178,6 @@ export const $textContent = async (textContent: string, root?: puppeteer.JSHandl
|
||||
const {frontend} = getBrowserAndPages();
|
||||
const rootElement = root ? root as puppeteer.ElementHandle : frontend;
|
||||
const element = await rootElement.$('pierceShadowText/' + textContent);
|
||||
if (!element) {
|
||||
throw new Error(`Unable to find element with textContent ${textContent}`);
|
||||
}
|
||||
return element;
|
||||
};
|
||||
|
||||
@@ -206,18 +203,19 @@ export const waitForNone = async (selector: string, root?: puppeteer.JSHandle, a
|
||||
export const waitForElementWithTextContent =
|
||||
(textContent: string, root?: puppeteer.JSHandle, asyncScope = new AsyncScope()) => {
|
||||
return asyncScope.exec(() => waitForFunction(async () => {
|
||||
return await $textContent(textContent, root);
|
||||
const elem = await $textContent(textContent, root);
|
||||
return elem || undefined;
|
||||
}, asyncScope));
|
||||
};
|
||||
|
||||
export const waitForFunction = async<T>(fn: () => Promise<T|undefined>, asyncScope = new AsyncScope()): Promise<T> => {
|
||||
return await asyncScope.exec(async () => {
|
||||
while (true) {
|
||||
await timeout(100);
|
||||
const result = await fn();
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
await timeout(100);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user