Skip to content

Commit

Permalink
fix: find the svg owner element (#473)
Browse files Browse the repository at this point in the history
This PR fixes a bug where an svg owner is null if the target element is
an svg element already.

Drive-by: noticed missing dispose calls.
  • Loading branch information
OrKoN committed Feb 17, 2023
1 parent e77bac0 commit f84617a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/PuppeteerRunnerExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,14 +545,20 @@ async function scrollIntoViewIfNeeded(
if (intersectionTarget) {
await waitForInViewport(intersectionTarget, timeout);
}
await intersectionTarget.dispose();
if (intersectionTarget !== element) {
await element.dispose();
}
}

async function getOwnerSVGElement(
handle: ElementHandle<SVGElement>
): Promise<ElementHandle<SVGSVGElement>> {
// If there is no ownerSVGElement, the element must be the top-level SVG
// element itself.
return await handle.evaluateHandle((element) => {
/* c8 ignore start */
return element.ownerSVGElement!;
return element.ownerSVGElement ?? (element as SVGSVGElement);
/* c8 ignore stop */
});
}
Expand Down
8 changes: 7 additions & 1 deletion test/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe('Runner', () => {
);
});

it('should be able to replay click steps on SVG path elements', async () => {
it('should be able to replay click steps on SVG elements', async () => {
const runner = await createRunner(
{
title: 'test',
Expand All @@ -197,6 +197,12 @@ describe('Runner', () => {
offsetX: 1,
offsetY: 1,
},
{
type: StepType.Click,
selectors: ['svg'],
offsetX: 1,
offsetY: 1,
},
],
},
new PuppeteerRunnerExtension(browser, page)
Expand Down

0 comments on commit f84617a

Please sign in to comment.