From 0226aea74e873ba96dae414edc533c33b1e51867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tarnay=20K=C3=A1lm=C3=A1n?= Date: Tue, 9 Aug 2022 15:56:11 +0200 Subject: [PATCH 1/2] feat(ByRole): improved byRole query performance (#1086) Co-authored-by: Sebastian Silbermann --- src/role-helpers.js | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/role-helpers.js b/src/role-helpers.js index 0b494da5..500bcdd2 100644 --- a/src/role-helpers.js +++ b/src/role-helpers.js @@ -105,27 +105,32 @@ function buildElementRoleList(elementRolesMap) { } function match(element) { + let {attributes = []} = element + + // https://github.com/testing-library/dom-testing-library/issues/814 + const typeTextIndex = attributes.findIndex( + attribute => + attribute.value && + attribute.name === 'type' && + attribute.value === 'text', + ) + + if (typeTextIndex >= 0) { + // not using splice to not mutate the attributes array + attributes = [ + ...attributes.slice(0, typeTextIndex), + ...attributes.slice(typeTextIndex + 1), + ] + } + + const selector = makeElementSelector({...element, attributes}) + return node => { - let {attributes = []} = element - // https://github.com/testing-library/dom-testing-library/issues/814 - const typeTextIndex = attributes.findIndex( - attribute => - attribute.value && - attribute.name === 'type' && - attribute.value === 'text', - ) - if (typeTextIndex >= 0) { - // not using splice to not mutate the attributes array - attributes = [ - ...attributes.slice(0, typeTextIndex), - ...attributes.slice(typeTextIndex + 1), - ] - if (node.type !== 'text') { - return false - } + if (typeTextIndex >= 0 && node.type !== 'text') { + return false } - return node.matches(makeElementSelector({...element, attributes})) + return node.matches(selector) } } From b7aaf1859f966f5a5db6a42309c4555b7555ea1d Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Tue, 9 Aug 2022 15:58:32 +0200 Subject: [PATCH 2/2] docs: add kalmi as a contributor for code (#1155) Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com> --- .all-contributorsrc | 9 +++++++++ README.md | 1 + 2 files changed, 10 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index bc6ef6b4..e0f082df 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -1553,6 +1553,15 @@ "contributions": [ "code" ] + }, + { + "login": "kalmi", + "name": "Tarnay Kálmán", + "avatar_url": "https://avatars.githubusercontent.com/u/54426?v=4", + "profile": "https://github.com/kalmi", + "contributions": [ + "code" + ] } ], "repoHost": "https://github.com/" diff --git a/README.md b/README.md index 377ff7d5..9b814514 100644 --- a/README.md +++ b/README.md @@ -335,6 +335,7 @@ Thanks goes to these people ([emoji key][emojis]):
Robin Drexler

💻
Omer Dolev

💻
Lirlev48

💻 +
Tarnay Kálmán

💻