Skip to content

Commit

Permalink
fix[devtools/e2e]: fixed source inspection in e2e tests (facebook#28518)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxyq authored and AndyPengc12 committed Apr 15, 2024
1 parent 6c164e2 commit 4cf802e
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ test.describe('Components', () => {
const isEditableValue = semver.gte(config.use.react_version, '16.8.0');

// Then read the inspected values.
const [propName, propValue, sourceText] = await page.evaluate(
const [propName, propValue] = await page.evaluate(
isEditable => {
const {createTestNameSelector, findAllNodes} =
window.REACT_DOM_DEVTOOLS;
Expand All @@ -85,21 +85,41 @@ test.describe('Components', () => {
createTestNameSelector('InspectedElementPropsTree'),
createTestNameSelector(selectorValue),
])[0];
const source = findAllNodes(container, [
createTestNameSelector('InspectedElementView-Source'),
])[0];
const value = isEditable.value
? valueElement.value
: valueElement.innerText;

return [name, value, source.innerText];
return [name, value];
},
{name: isEditableName, value: isEditableValue}
);

expect(propName).toBe('label');
expect(propValue).toBe('"one"');
expect(sourceText).toMatch(/e2e-app[a-zA-Z]*\.js/);
});

test('Should allow inspecting source of the element', async () => {
// Source inspection is available only in modern renderer.
runOnlyForReactRange('>=16.8');

// Select the first list item in DevTools.
await devToolsUtils.selectElement(page, 'ListItem', 'List\nApp');

// Then read the inspected values.
const sourceText = await page.evaluate(() => {
const {createTestNameSelector, findAllNodes} = window.REACT_DOM_DEVTOOLS;
const container = document.getElementById('devtools');

const source = findAllNodes(container, [
createTestNameSelector('InspectedElementView-Source'),
])[0];

return source.innerText;
});

// If React version is specified, the e2e-regression.html page will be used
// If not, then e2e.html, see playwright.config.js, how url is constructed
expect(sourceText).toMatch(/e2e-app[\-a-zA-Z]*\.js/);
});

test('should allow props to be edited', async () => {
Expand Down

0 comments on commit 4cf802e

Please sign in to comment.