shadow-dom-testing-library
Advanced tools
Comparing version 1.9.1 to 1.10.0
@@ -1,3 +0,3 @@ | ||
var ge=Object.defineProperty;var Pe=(e,o)=>{for(var n in o)ge(e,n,{get:o[n],enumerable:!0})};import{queries as St,within as yt}from"@testing-library/dom";var A={};Pe(A,{findAllByShadowAltText:()=>v,findAllByShadowDisplayValue:()=>z,findAllByShadowLabelText:()=>H,findAllByShadowPlaceholderText:()=>V,findAllByShadowRole:()=>L,findAllByShadowTestId:()=>se,findAllByShadowText:()=>j,findAllByShadowTitle:()=>ae,findByShadowAltText:()=>ee,findByShadowDisplayValue:()=>Y,findByShadowLabelText:()=>I,findByShadowPlaceholderText:()=>_,findByShadowRole:()=>q,findByShadowTestId:()=>ce,findByShadowText:()=>k,findByShadowTitle:()=>le,getAllByShadowAltText:()=>K,getAllByShadowDisplayValue:()=>W,getAllByShadowLabelText:()=>D,getAllByShadowPlaceholderText:()=>N,getAllByShadowRole:()=>P,getAllByShadowTestId:()=>de,getAllByShadowText:()=>F,getAllByShadowTitle:()=>oe,getByShadowAltText:()=>Z,getByShadowDisplayValue:()=>X,getByShadowLabelText:()=>b,getByShadowPlaceholderText:()=>C,getByShadowRole:()=>R,getByShadowTestId:()=>he,getByShadowText:()=>U,getByShadowTitle:()=>ne,queryAllByShadowAltText:()=>M,queryAllByShadowDisplayValue:()=>p,queryAllByShadowLabelText:()=>y,queryAllByShadowPlaceholderText:()=>f,queryAllByShadowRole:()=>S,queryAllByShadowTestId:()=>E,queryAllByShadowText:()=>T,queryAllByShadowTitle:()=>B,queryByShadowAltText:()=>J,queryByShadowDisplayValue:()=>G,queryByShadowLabelText:()=>Q,queryByShadowPlaceholderText:()=>O,queryByShadowRole:()=>g,queryByShadowTestId:()=>re,queryByShadowText:()=>$,queryByShadowTitle:()=>te});import{buildQueries as c,queryAllByRole as Le,queryAllByLabelText as qe,queryAllByPlaceholderText as Qe,queryAllByText as De,queryAllByDisplayValue as be,queryAllByAltText as He,queryAllByTitle as Ie,queryAllByTestId as Oe}from"@testing-library/dom";function Re(e,o,n={shallow:!1}){let t=Se(e,o,n);return Array.isArray(t)&&t.length>0?t[0]:null}function Se(e,o,n={shallow:!1}){let a=h(e,n).map(l=>Array.from(l.querySelectorAll(o))).flat(1/0);return[...new Set(a)]}function h(e,o={shallow:!1}){return ye(e,"*",o)}function ye(e,o,n={shallow:!1},t=[],a=[]){return e instanceof Document&&(e=document.documentElement),t=[e],a.push(e),e instanceof HTMLElement&&e.shadowRoot!=null&&e.shadowRoot.mode!=="closed"&&(a.push(e.shadowRoot),t.push(e.shadowRoot)),t.forEach(l=>{l.querySelectorAll(o).forEach(r=>{if(r.shadowRoot==null||r.shadowRoot.mode==="closed"){a.push(r);return}if(a.push(r.shadowRoot),n.shallow===!0){r.shadowRoot.querySelectorAll(o).forEach(d=>{a.push(d)});return}r.shadowRoot.querySelectorAll(o).forEach(d=>{a.push(d),t.push(d)}),ye(r.shadowRoot,o,n,t,a)})}),[...new Set(a)]}function u(e){return e.map(o=>(...n)=>{let[t,a,l,...r]=n;return l==null&&(l={}),l.suggest=!1,o(t,a,l,...r)})}function S(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(h(o,t).map(a=>Le(a,n,t)).flat(1/0))]}var Ne=(e,o)=>`Found multiple elements with the role of: ${o}`,Ce=(e,o)=>`Unable to find an element with the role of: ${o}`,[g,P,R,L,q]=u(c(S,Ne,Ce));function y(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(h(o,t).map(a=>qe(a,n,t)).flat(1/0))]}var Ve=(e,o)=>`Found multiple elements with the label text of: ${o}`,_e=(e,o)=>`Unable to find an element with the label text of: ${o}`,[Q,D,b,H,I]=u(c(y,Ve,_e));function f(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(h(o,t).map(a=>Qe(a,n,t)).flat(1/0))]}var $e=(e,o)=>`Found multiple elements with the placeholder text of: ${o}`,Fe=(e,o)=>`Unable to find an element with the placeholder text of: ${o}`,[O,N,C,V,_]=u(c(f,$e,Fe));function T(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(h(o,t).map(a=>De(a,n,t)).flat(1/0))]}var Ue=(e,o)=>`Found multiple elements with the text of: ${o}`,je=(e,o)=>`Unable to find an element with the text of: ${o}`,[$,F,U,j,k]=u(c(T,Ue,je));function p(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(h(o,t).map(a=>be(a,n,t)).flat(1/0))]}var ke=(e,o)=>`Found multiple elements with the display value of: ${o}`,Ge=(e,o)=>`Unable to find an element with the display value of: ${o}`,[G,W,X,z,Y]=u(c(p,ke,Ge));function M(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(h(o,t).map(a=>He(a,n,t)).flat(1/0))]}var We=(e,o)=>`Found multiple elements with the alt text of: ${o}`,Xe=(e,o)=>`Unable to find an element with the alt text of: ${o}`,[J,K,Z,v,ee]=u(c(M,We,Xe));function B(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(h(o,t).map(a=>Ie(a,n,t)).flat(1/0))]}var ze=(e,o)=>`Found multiple elements with the title of: ${o}`,Ye=(e,o)=>`Unable to find an element with the title of: ${o}`,[te,oe,ne,ae,le]=u(c(B,ze,Ye));function E(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(h(o,t).map(a=>Oe(a,n,t)).flat(1/0))]}var Je=(e,o)=>`Found multiple elements with the test id of: ${o}`,Ke=(e,o)=>`Unable to find an element with the test id of: ${o}`,[re,de,he,se,ce]=u(c(E,Je,Ke));import{logDOM as it}from"@testing-library/dom";import{prettyDOM as Ze,getConfig as ve}from"@testing-library/dom";var fe=/([^\S\r\n]*[\f\n\r\t\v]+)/.source;function et(e){return e.replace(new RegExp(`${fe}.*${fe}{2,}`,"g"),"")}function tt(...e){let[o,n,t]=e,a=me((t==null?void 0:t.filterNode)||ue);return t==null&&(t={}),t.plugins==null&&(t.plugins=[]),t.plugins.push(a),Ze(o,n,{...t,plugins:[a]})}function pe(e){return e.replace(/</g,"<").replace(/>/g,">")}function ue(e){return e.nodeType!==ie&&(e.nodeType!==Be||!e.matches(ve().defaultIgnore))}var ot=(e,o,n,t,a,l,r)=>{let d=t+n.indent,s=n.colors;return e.map(i=>{let w=o[i],m=r(w,n,d,a,l);return typeof w!="string"&&(m.indexOf(` | ||
`)!==-1&&(m=n.spacingOuter+d+m+n.spacingOuter+t),m="{"+m+"}"),n.spacingInner+t+s.prop.open+i+s.prop.close+"="+s.value.open+m+s.value.close}).join("")},nt=3,at=(e,o,n,t,a,l)=>et(e.map(r=>{let d=typeof r=="string"?Me(r,o):l(r,o,n,t,a);return d===""&&typeof r=="object"&&r!=null&&r.nodeType!==nt?"":o.spacingOuter+n+d}).join("")),Me=(e,o)=>{let n=o.colors.content;return n.open+pe(e)+n.close},lt=(e,o)=>{let n=o.colors.comment;return n.open+"<!--"+pe(e)+"-->"+n.close},rt=(e,o,n,t,a)=>{let l=t.colors.tag;return l.open+"<"+e+(o&&l.close+o+t.spacingOuter+a+l.open)+(n?">"+l.close+n+t.spacingOuter+a+l.open+"</"+e:(o&&!t.min?"":" ")+"/")+">"+l.close},dt=(e,o)=>{let n=o.colors.tag;return n.open+"<"+e+n.close+" \u2026"+n.open+" />"+n.close},Be=1,Ee=3,ie=8,Ae=11,ht=/^((HTML|SVG)\w*)?Element$/,st=e=>{var l;let o=((l=e==null?void 0:e.constructor)==null?void 0:l.name)||"",{nodeType:n,tagName:t}=e,a=typeof t=="string"&&t.includes("-")||typeof e.hasAttribute=="function"&&e.hasAttribute("is")||e instanceof HTMLElement;return n===Be&&(ht.test(o)||a)||n===Ee&&o==="Text"||n===ie&&o==="Comment"||n===Ae};function ct(e){return e.nodeType===Ee}function ut(e){return e.nodeType===ie}function Te(e){return e.nodeType===Ae}function me(e){function o(n){let t=Array.prototype.slice.call(n.childNodes||n.children);return"shadowRoot"in n&&n.shadowRoot!=null&&n.shadowRoot.mode!=="closed"&&t.unshift(n.shadowRoot),t.filter(e)}return{test:n=>(n==null?void 0:n.constructor)&&st(n),serialize:(n,t,a,l,r,d)=>{if(ct(n))return Me(n.data,t);if(ut(n))return lt(n.data,t);let s="DocumentFragment";return"tagName"in n&&n.tagName?s=n.tagName.toLowerCase():n instanceof ShadowRoot&&(s="ShadowRoot"),++l>t.maxDepth?dt(s,t):rt(s,ot(Te(n)?[]:Array.from(n.attributes).map(i=>i.name).sort(),Te(n)?{}:Array.from(n.attributes).reduce((i,w)=>(i[w.name]=w.value,i),{}),t,a+t.indent,l,r,d),at(o(n),t,a+t.indent,l,r,d),t,a)}}}function x(...e){let[o,n,t]=e,a=me((t==null?void 0:t.filterNode)||ue);t==null&&(t={}),t.plugins==null&&(t.plugins=[]),t.plugins.push(a),it(o,n,t)}function we(...e){let[o,n,t]=e;Array.isArray(o)?o.forEach(a=>x(a,n,t)):x(o,n,t)}import{screen as mt}from"@testing-library/dom";var wt={...mt,debug:we,queryAllByShadowRole:(...e)=>S(document.documentElement,e[0],e[1]),queryByShadowRole:(...e)=>g(document.documentElement,e[0],e[1]),getAllByShadowRole:(...e)=>P(document.documentElement,e[0],e[1]),getByShadowRole:(...e)=>R(document.documentElement,e[0],e[1]),findAllByShadowRole:(...e)=>L(document.documentElement,e[0],e[1],e[2]),findByShadowRole:(...e)=>q(document.documentElement,e[0],e[1],e[2]),queryAllByShadowLabelText:(...e)=>y(document.documentElement,e[0],e[1]),queryByShadowLabelText:(...e)=>Q(document.documentElement,e[0],e[1]),getAllByShadowLabelText:(...e)=>D(document.documentElement,e[0],e[1]),getByShadowLabelText:(...e)=>b(document.documentElement,e[0],e[1]),findAllByShadowLabelText:(...e)=>H(document.documentElement,e[0],e[1],e[2]),findByShadowLabelText:(...e)=>I(document.documentElement,e[0],e[1],e[2]),queryAllByShadowPlaceholderText:(...e)=>f(document.documentElement,e[0],e[1]),queryByShadowPlaceholderText:(...e)=>O(document.documentElement,e[0],e[1]),getAllByShadowPlaceholderText:(...e)=>N(document.documentElement,e[0],e[1]),getByShadowPlaceholderText:(...e)=>C(document.documentElement,e[0],e[1]),findAllByShadowPlaceholderText:(...e)=>V(document.documentElement,e[0],e[1],e[2]),findByShadowPlaceholderText:(...e)=>_(document.documentElement,e[0],e[1],e[2]),queryAllByShadowText:(...e)=>T(document.documentElement,e[0],e[1]),queryByShadowText:(...e)=>$(document.documentElement,e[0],e[1]),getAllByShadowText:(...e)=>F(document.documentElement,e[0],e[1]),getByShadowText:(...e)=>U(document.documentElement,e[0],e[1]),findAllByShadowText:(...e)=>j(document.documentElement,e[0],e[1],e[2]),findByShadowText:(...e)=>k(document.documentElement,e[0],e[1],e[2]),queryAllByShadowDisplayValue:(...e)=>p(document.documentElement,e[0],e[1]),queryByShadowDisplayValue:(...e)=>G(document.documentElement,e[0],e[1]),getAllByShadowDisplayValue:(...e)=>W(document.documentElement,e[0],e[1]),getByShadowDisplayValue:(...e)=>X(document.documentElement,e[0],e[1]),findAllByShadowDisplayValue:(...e)=>z(document.documentElement,e[0],e[1],e[2]),findByShadowDisplayValue:(...e)=>Y(document.documentElement,e[0],e[1],e[2]),queryAllByShadowAltText:(...e)=>M(document.documentElement,e[0],e[1]),queryByShadowAltText:(...e)=>J(document.documentElement,e[0],e[1]),getAllByShadowAltText:(...e)=>K(document.documentElement,e[0],e[1]),getByShadowAltText:(...e)=>Z(document.documentElement,e[0],e[1]),findAllByShadowAltText:(...e)=>v(document.documentElement,e[0],e[1],e[2]),findByShadowAltText:(...e)=>ee(document.documentElement,e[0],e[1],e[2]),queryAllByShadowTitle:(...e)=>B(document.documentElement,e[0],e[1]),queryByShadowTitle:(...e)=>te(document.documentElement,e[0],e[1]),getAllByShadowTitle:(...e)=>oe(document.documentElement,e[0],e[1]),getByShadowTitle:(...e)=>ne(document.documentElement,e[0],e[1]),findAllByShadowTitle:(...e)=>ae(document.documentElement,e[0],e[1],e[2]),findByShadowTitle:(...e)=>le(document.documentElement,e[0],e[1],e[2]),queryAllByShadowTestId:(...e)=>E(document.documentElement,e[0],e[1]),queryByShadowTestId:(...e)=>re(document.documentElement,e[0],e[1]),getAllByShadowTestId:(...e)=>de(document.documentElement,e[0],e[1]),getByShadowTestId:(...e)=>he(document.documentElement,e[0],e[1]),findAllByShadowTestId:(...e)=>se(document.documentElement,e[0],e[1],e[2]),findByShadowTestId:(...e)=>ce(document.documentElement,e[0],e[1],e[2])};function xe(){if(typeof ShadowRoot>"u")throw"Your environment does not support shadow roots.";ShadowRoot.prototype.matches==null&&Object.defineProperties(ShadowRoot.prototype,{matches:{get(){return function(e){return e.trim()==="*"?!0:this.querySelector(e)!=null}}}}),ShadowRoot.prototype.outerHTML==null&&Object.defineProperties(ShadowRoot.prototype,{outerHTML:{get(){return this.innerHTML}}})}xe();var ft={...St,...A};function Ft(e){return yt(e,ft)}export{we as debug,Re as deepQuerySelector,Se as deepQuerySelectorAll,v as findAllByShadowAltText,z as findAllByShadowDisplayValue,H as findAllByShadowLabelText,V as findAllByShadowPlaceholderText,L as findAllByShadowRole,se as findAllByShadowTestId,j as findAllByShadowText,ae as findAllByShadowTitle,ee as findByShadowAltText,Y as findByShadowDisplayValue,I as findByShadowLabelText,_ as findByShadowPlaceholderText,q as findByShadowRole,ce as findByShadowTestId,k as findByShadowText,le as findByShadowTitle,K as getAllByShadowAltText,W as getAllByShadowDisplayValue,D as getAllByShadowLabelText,N as getAllByShadowPlaceholderText,P as getAllByShadowRole,de as getAllByShadowTestId,F as getAllByShadowText,oe as getAllByShadowTitle,h as getAllElementsAndShadowRoots,Z as getByShadowAltText,X as getByShadowDisplayValue,b as getByShadowLabelText,C as getByShadowPlaceholderText,R as getByShadowRole,he as getByShadowTestId,U as getByShadowText,ne as getByShadowTitle,x as logShadowDOM,tt as prettyShadowDOM,M as queryAllByShadowAltText,p as queryAllByShadowDisplayValue,y as queryAllByShadowLabelText,f as queryAllByShadowPlaceholderText,S as queryAllByShadowRole,E as queryAllByShadowTestId,T as queryAllByShadowText,B as queryAllByShadowTitle,J as queryByShadowAltText,G as queryByShadowDisplayValue,Q as queryByShadowLabelText,O as queryByShadowPlaceholderText,g as queryByShadowRole,re as queryByShadowTestId,$ as queryByShadowText,te as queryByShadowTitle,wt as screen,A as shadowQueries,Ft as within}; | ||
var Pe=Object.defineProperty;var Re=(e,o)=>{for(var n in o)Pe(e,n,{get:o[n],enumerable:!0})};import{queries as Tt,within as Mt}from"@testing-library/dom";var x={};Re(x,{findAllByShadowAltText:()=>ee,findAllByShadowDisplayValue:()=>Y,findAllByShadowLabelText:()=>I,findAllByShadowPlaceholderText:()=>_,findAllByShadowRole:()=>q,findAllByShadowTestId:()=>se,findAllByShadowText:()=>j,findAllByShadowTitle:()=>le,findByShadowAltText:()=>te,findByShadowDisplayValue:()=>J,findByShadowLabelText:()=>N,findByShadowPlaceholderText:()=>$,findByShadowRole:()=>Q,findByShadowTestId:()=>ue,findByShadowText:()=>k,findByShadowTitle:()=>re,getAllByShadowAltText:()=>Z,getAllByShadowDisplayValue:()=>X,getAllByShadowLabelText:()=>b,getAllByShadowPlaceholderText:()=>C,getAllByShadowRole:()=>R,getAllByShadowTestId:()=>ce,getAllByShadowText:()=>U,getAllByShadowTitle:()=>ne,getByShadowAltText:()=>v,getByShadowDisplayValue:()=>z,getByShadowLabelText:()=>H,getByShadowPlaceholderText:()=>V,getByShadowRole:()=>L,getByShadowTestId:()=>he,getByShadowText:()=>W,getByShadowTitle:()=>ae,queryAllByShadowAltText:()=>E,queryAllByShadowDisplayValue:()=>M,queryAllByShadowLabelText:()=>f,queryAllByShadowPlaceholderText:()=>p,queryAllByShadowRole:()=>y,queryAllByShadowTestId:()=>B,queryAllByShadowText:()=>T,queryAllByShadowTitle:()=>A,queryByShadowAltText:()=>K,queryByShadowDisplayValue:()=>G,queryByShadowLabelText:()=>D,queryByShadowPlaceholderText:()=>O,queryByShadowRole:()=>P,queryByShadowTestId:()=>de,queryByShadowText:()=>F,queryByShadowTitle:()=>oe});import{buildQueries as u,queryAllByRole as be,queryAllByLabelText as He,queryAllByPlaceholderText as Ie,queryAllByText as Ne,queryAllByDisplayValue as Oe,queryAllByAltText as Ce,queryAllByTitle as Ve,queryAllByTestId as _e}from"@testing-library/dom";qe();function Le(){Qe()}function ye(){HTMLSlotElement.prototype.querySelectorAll=HTMLElement.prototype.querySelectorAll}function d(e){Le();try{let o=e();return typeof o=="object"&&"finally"in o&&typeof o.finally=="function"&&o.finally(()=>ye()),o}finally{ye()}}function qe(){if(typeof ShadowRoot>"u")throw"Your environment does not support shadow roots.";ShadowRoot.prototype.matches==null&&Object.defineProperties(ShadowRoot.prototype,{matches:{get(){return function(e){return e.trim()==="*"?!0:Boolean(this.querySelector(e))}}}}),ShadowRoot.prototype.outerHTML==null&&Object.defineProperties(ShadowRoot.prototype,{outerHTML:{get(){return this.innerHTML}}})}function Qe(){HTMLSlotElement.prototype.querySelectorAll=function(e){let o=HTMLElement.prototype.querySelectorAll,n=[];return this.assignedElements({flatten:!0}).forEach(t=>{let a=t,l=document.createElement("div");l.appendChild(a.cloneNode(!1)),l.querySelector(e)&&n.push(a),n=n.concat(Array.from(a.querySelectorAll(e)))}),n.length==0&&(n=Array.from(o.call(this,e))),[...new Set(n)]}}function De(e,o,n={shallow:!1}){let t=fe(e,o,n);return Array.isArray(t)&&t.length>0?t[0]:null}function fe(e,o,n={shallow:!1}){return d(()=>{let a=h(e,n).map(l=>Array.from(l.querySelectorAll(o))).flat(1/0);return[...new Set(a)]})}function h(e,o={shallow:!1}){return pe(e,"*",o)}function pe(e,o,n={shallow:!1},t=[],a=[]){return e instanceof Document&&(e=document.documentElement),t=[e],a.push(e),e instanceof HTMLElement&&e.shadowRoot!=null&&e.shadowRoot.mode!=="closed"&&(a.push(e.shadowRoot),t.push(e.shadowRoot)),t.forEach(l=>{l.querySelectorAll(o).forEach(r=>{if(r.shadowRoot==null||r.shadowRoot.mode==="closed"){a.push(r);return}if(a.push(r.shadowRoot),n.shallow===!0){r.shadowRoot.querySelectorAll(o).forEach(c=>{a.push(c)});return}r.shadowRoot.querySelectorAll(o).forEach(c=>{a.push(c),t.push(c)}),pe(r.shadowRoot,o,n,t,a)})}),[...new Set(a)]}function i(e){return e.map(o=>(...n)=>{let[t,a,l,...r]=n;return l==null&&(l={}),l.suggest=!1,o(t,a,l,...r)})}function y(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(d(()=>h(o,t).map(a=>be(a,n,t)).flat(1/0)))]}var $e=(e,o)=>`Found multiple elements with the role of: ${o}`,Fe=(e,o)=>`Unable to find an element with the role of: ${o}`,[P,R,L,q,Q]=i(u(y,$e,Fe));function f(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(d(()=>h(o,t).map(a=>He(a,n,t)).flat(1/0)))]}var Ue=(e,o)=>`Found multiple elements with the label text of: ${o}`,We=(e,o)=>`Unable to find an element with the label text of: ${o}`,[D,b,H,I,N]=i(u(f,Ue,We));function p(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(d(()=>h(o,t).map(a=>Ie(a,n,t)).flat(1/0)))]}var je=(e,o)=>`Found multiple elements with the placeholder text of: ${o}`,ke=(e,o)=>`Unable to find an element with the placeholder text of: ${o}`,[O,C,V,_,$]=i(u(p,je,ke));function T(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(d(()=>h(o,t).map(a=>Ne(a,n,t)).flat(1/0)))]}var Ge=(e,o)=>`Found multiple elements with the text of: ${o}`,Xe=(e,o)=>`Unable to find an element with the text of: ${o}`,[F,U,W,j,k]=i(u(T,Ge,Xe));function M(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(d(()=>h(o,t).map(a=>Oe(a,n,t)).flat(1/0)))]}var ze=(e,o)=>`Found multiple elements with the display value of: ${o}`,Ye=(e,o)=>`Unable to find an element with the display value of: ${o}`,[G,X,z,Y,J]=i(u(M,ze,Ye));function E(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(d(()=>h(o,t).map(a=>Ce(a,n,t)).flat(1/0)))]}var Je=(e,o)=>`Found multiple elements with the alt text of: ${o}`,Ke=(e,o)=>`Unable to find an element with the alt text of: ${o}`,[K,Z,v,ee,te]=i(u(E,Je,Ke));function A(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(d(()=>h(o,t).map(a=>Ve(a,n,t)).flat(1/0)))]}var Ze=(e,o)=>`Found multiple elements with the title of: ${o}`,ve=(e,o)=>`Unable to find an element with the title of: ${o}`,[oe,ne,ae,le,re]=i(u(A,Ze,ve));function B(...e){let[o,n,t]=e;return t==null&&(t={}),t.suggest=!1,[...new Set(d(()=>h(o,t).map(a=>_e(a,n,t)).flat(1/0)))]}var et=(e,o)=>`Found multiple elements with the test id of: ${o}`,tt=(e,o)=>`Unable to find an element with the test id of: ${o}`,[de,ce,he,se,ue]=i(u(B,et,tt));import{logDOM as yt}from"@testing-library/dom";import{prettyDOM as ot,getConfig as nt}from"@testing-library/dom";var Te=/([^\S\r\n]*[\f\n\r\t\v]+)/.source;function at(e){return e.replace(new RegExp(`${Te}.*${Te}{2,}`,"g"),"")}function lt(...e){let[o,n,t]=e,a=Se((t==null?void 0:t.filterNode)||ie);return t==null&&(t={}),t.plugins==null&&(t.plugins=[]),t.plugins.push(a),d(()=>ot(o,n,{...t,plugins:[a]}))}function Ee(e){return e.replace(/</g,"<").replace(/>/g,">")}function ie(e){return e.nodeType!==me&&(e.nodeType!==Be||!e.matches(nt().defaultIgnore))}var rt=(e,o,n,t,a,l,r)=>{let c=t+n.indent,s=n.colors;return e.map(m=>{let w=o[m],S=r(w,n,c,a,l);return typeof w!="string"&&(S.indexOf(` | ||
`)!==-1&&(S=n.spacingOuter+c+S+n.spacingOuter+t),S="{"+S+"}"),n.spacingInner+t+s.prop.open+m+s.prop.close+"="+s.value.open+S+s.value.close}).join("")},dt=3,ct=(e,o,n,t,a,l)=>at(e.map(r=>{let c=typeof r=="string"?Ae(r,o):l(r,o,n,t,a);return c===""&&typeof r=="object"&&r!=null&&r.nodeType!==dt?"":o.spacingOuter+n+c}).join("")),Ae=(e,o)=>{let n=o.colors.content;return n.open+Ee(e)+n.close},ht=(e,o)=>{let n=o.colors.comment;return n.open+"<!--"+Ee(e)+"-->"+n.close},st=(e,o,n,t,a)=>{let l=t.colors.tag;return l.open+"<"+e+(o&&l.close+o+t.spacingOuter+a+l.open)+(n?">"+l.close+n+t.spacingOuter+a+l.open+"</"+e:(o&&!t.min?"":" ")+"/")+">"+l.close},ut=(e,o)=>{let n=o.colors.tag;return n.open+"<"+e+n.close+" \u2026"+n.open+" />"+n.close},Be=1,xe=3,me=8,ge=11,it=/^((HTML|SVG)\w*)?Element$/,mt=e=>{var l;let o=((l=e==null?void 0:e.constructor)==null?void 0:l.name)||"",{nodeType:n,tagName:t}=e,a=typeof t=="string"&&t.includes("-")||typeof e.hasAttribute=="function"&&e.hasAttribute("is")||e instanceof HTMLElement;return n===Be&&(it.test(o)||a)||n===xe&&o==="Text"||n===me&&o==="Comment"||n===ge};function St(e){return e.nodeType===xe}function wt(e){return e.nodeType===me}function Me(e){return e.nodeType===ge}function Se(e){function o(n){let t=Array.prototype.slice.call(n.childNodes||n.children);return"shadowRoot"in n&&n.shadowRoot!=null&&n.shadowRoot.mode!=="closed"&&t.unshift(n.shadowRoot),t.filter(e)}return{test:n=>(n==null?void 0:n.constructor)&&mt(n),serialize:(n,t,a,l,r,c)=>{if(St(n))return Ae(n.data,t);if(wt(n))return ht(n.data,t);let s="DocumentFragment";return"tagName"in n&&n.tagName?s=n.tagName.toLowerCase():n instanceof ShadowRoot&&(s="ShadowRoot"),++l>t.maxDepth?ut(s,t):st(s,rt(Me(n)?[]:Array.from(n.attributes).map(m=>m.name).sort(),Me(n)?{}:Array.from(n.attributes).reduce((m,w)=>(m[w.name]=w.value,m),{}),t,a+t.indent,l,r,c),ct(o(n),t,a+t.indent,l,r,c),t,a)}}}function g(...e){let[o,n,t]=e,a=Se((t==null?void 0:t.filterNode)||ie);t==null&&(t={}),t.plugins==null&&(t.plugins=[]),t.plugins.push(a),d(()=>yt(o,n,t))}function we(...e){let[o,n,t]=e;Array.isArray(o)?o.forEach(a=>g(a,n,t)):g(o,n,t)}import{screen as ft}from"@testing-library/dom";var pt={...ft,debug:we,queryAllByShadowRole:(...e)=>y(document.documentElement,e[0],e[1]),queryByShadowRole:(...e)=>P(document.documentElement,e[0],e[1]),getAllByShadowRole:(...e)=>R(document.documentElement,e[0],e[1]),getByShadowRole:(...e)=>L(document.documentElement,e[0],e[1]),findAllByShadowRole:(...e)=>q(document.documentElement,e[0],e[1],e[2]),findByShadowRole:(...e)=>Q(document.documentElement,e[0],e[1],e[2]),queryAllByShadowLabelText:(...e)=>f(document.documentElement,e[0],e[1]),queryByShadowLabelText:(...e)=>D(document.documentElement,e[0],e[1]),getAllByShadowLabelText:(...e)=>b(document.documentElement,e[0],e[1]),getByShadowLabelText:(...e)=>H(document.documentElement,e[0],e[1]),findAllByShadowLabelText:(...e)=>I(document.documentElement,e[0],e[1],e[2]),findByShadowLabelText:(...e)=>N(document.documentElement,e[0],e[1],e[2]),queryAllByShadowPlaceholderText:(...e)=>p(document.documentElement,e[0],e[1]),queryByShadowPlaceholderText:(...e)=>O(document.documentElement,e[0],e[1]),getAllByShadowPlaceholderText:(...e)=>C(document.documentElement,e[0],e[1]),getByShadowPlaceholderText:(...e)=>V(document.documentElement,e[0],e[1]),findAllByShadowPlaceholderText:(...e)=>_(document.documentElement,e[0],e[1],e[2]),findByShadowPlaceholderText:(...e)=>$(document.documentElement,e[0],e[1],e[2]),queryAllByShadowText:(...e)=>T(document.documentElement,e[0],e[1]),queryByShadowText:(...e)=>F(document.documentElement,e[0],e[1]),getAllByShadowText:(...e)=>U(document.documentElement,e[0],e[1]),getByShadowText:(...e)=>W(document.documentElement,e[0],e[1]),findAllByShadowText:(...e)=>j(document.documentElement,e[0],e[1],e[2]),findByShadowText:(...e)=>k(document.documentElement,e[0],e[1],e[2]),queryAllByShadowDisplayValue:(...e)=>M(document.documentElement,e[0],e[1]),queryByShadowDisplayValue:(...e)=>G(document.documentElement,e[0],e[1]),getAllByShadowDisplayValue:(...e)=>X(document.documentElement,e[0],e[1]),getByShadowDisplayValue:(...e)=>z(document.documentElement,e[0],e[1]),findAllByShadowDisplayValue:(...e)=>Y(document.documentElement,e[0],e[1],e[2]),findByShadowDisplayValue:(...e)=>J(document.documentElement,e[0],e[1],e[2]),queryAllByShadowAltText:(...e)=>E(document.documentElement,e[0],e[1]),queryByShadowAltText:(...e)=>K(document.documentElement,e[0],e[1]),getAllByShadowAltText:(...e)=>Z(document.documentElement,e[0],e[1]),getByShadowAltText:(...e)=>v(document.documentElement,e[0],e[1]),findAllByShadowAltText:(...e)=>ee(document.documentElement,e[0],e[1],e[2]),findByShadowAltText:(...e)=>te(document.documentElement,e[0],e[1],e[2]),queryAllByShadowTitle:(...e)=>A(document.documentElement,e[0],e[1]),queryByShadowTitle:(...e)=>oe(document.documentElement,e[0],e[1]),getAllByShadowTitle:(...e)=>ne(document.documentElement,e[0],e[1]),getByShadowTitle:(...e)=>ae(document.documentElement,e[0],e[1]),findAllByShadowTitle:(...e)=>le(document.documentElement,e[0],e[1],e[2]),findByShadowTitle:(...e)=>re(document.documentElement,e[0],e[1],e[2]),queryAllByShadowTestId:(...e)=>B(document.documentElement,e[0],e[1]),queryByShadowTestId:(...e)=>de(document.documentElement,e[0],e[1]),getAllByShadowTestId:(...e)=>ce(document.documentElement,e[0],e[1]),getByShadowTestId:(...e)=>he(document.documentElement,e[0],e[1]),findAllByShadowTestId:(...e)=>se(document.documentElement,e[0],e[1],e[2]),findByShadowTestId:(...e)=>ue(document.documentElement,e[0],e[1],e[2])};var Et={...Tt,...x};function zt(e){return Mt(e,Et)}export{we as debug,De as deepQuerySelector,fe as deepQuerySelectorAll,ee as findAllByShadowAltText,Y as findAllByShadowDisplayValue,I as findAllByShadowLabelText,_ as findAllByShadowPlaceholderText,q as findAllByShadowRole,se as findAllByShadowTestId,j as findAllByShadowText,le as findAllByShadowTitle,te as findByShadowAltText,J as findByShadowDisplayValue,N as findByShadowLabelText,$ as findByShadowPlaceholderText,Q as findByShadowRole,ue as findByShadowTestId,k as findByShadowText,re as findByShadowTitle,Z as getAllByShadowAltText,X as getAllByShadowDisplayValue,b as getAllByShadowLabelText,C as getAllByShadowPlaceholderText,R as getAllByShadowRole,ce as getAllByShadowTestId,U as getAllByShadowText,ne as getAllByShadowTitle,h as getAllElementsAndShadowRoots,v as getByShadowAltText,z as getByShadowDisplayValue,H as getByShadowLabelText,V as getByShadowPlaceholderText,L as getByShadowRole,he as getByShadowTestId,W as getByShadowText,ae as getByShadowTitle,g as logShadowDOM,lt as prettyShadowDOM,E as queryAllByShadowAltText,M as queryAllByShadowDisplayValue,f as queryAllByShadowLabelText,p as queryAllByShadowPlaceholderText,y as queryAllByShadowRole,B as queryAllByShadowTestId,T as queryAllByShadowText,A as queryAllByShadowTitle,K as queryByShadowAltText,G as queryByShadowDisplayValue,D as queryByShadowLabelText,O as queryByShadowPlaceholderText,P as queryByShadowRole,de as queryByShadowTestId,F as queryByShadowText,oe as queryByShadowTitle,pt as screen,x as shadowQueries,zt as within}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,1 +0,1 @@ | ||
{"inputs":{"src/deep-query-selectors.ts":{"bytes":3555,"imports":[]},"src/shadow-queries.ts":{"bytes":10219,"imports":[{"path":"src/deep-query-selectors.ts","kind":"import-statement"}]},"src/pretty-shadow-dom.ts":{"bytes":8280,"imports":[]},"src/log-shadow-dom.ts":{"bytes":626,"imports":[{"path":"src/pretty-shadow-dom.ts","kind":"import-statement"}]},"src/debug.ts":{"bytes":407,"imports":[{"path":"src/log-shadow-dom.ts","kind":"import-statement"}]},"src/shadow-screen.ts":{"bytes":9324,"imports":[{"path":"src/debug.ts","kind":"import-statement"},{"path":"src/shadow-queries.ts","kind":"import-statement"}]},"src/trick-dom-testing-library.ts":{"bytes":1227,"imports":[]},"src/types.ts":{"bytes":2196,"imports":[]},"src/index.ts":{"bytes":842,"imports":[{"path":"src/shadow-queries.ts","kind":"import-statement"},{"path":"src/debug.ts","kind":"import-statement"},{"path":"src/log-shadow-dom.ts","kind":"import-statement"},{"path":"src/pretty-shadow-dom.ts","kind":"import-statement"},{"path":"src/shadow-screen.ts","kind":"import-statement"},{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"},{"path":"src/types.ts","kind":"import-statement"},{"path":"src/shadow-queries.ts","kind":"import-statement"},{"path":"src/deep-query-selectors.ts","kind":"import-statement"}]}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":57639},"dist/index.cjs":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":1712},"src/shadow-queries.ts":{"bytesInOutput":4042},"src/deep-query-selectors.ts":{"bytesInOutput":832},"src/log-shadow-dom.ts":{"bytesInOutput":196},"src/pretty-shadow-dom.ts":{"bytesInOutput":2522},"src/debug.ts":{"bytesInOutput":80},"src/shadow-screen.ts":{"bytesInOutput":3437},"src/trick-dom-testing-library.ts":{"bytesInOutput":395}},"bytes":14877}}} | ||
{"inputs":{"src/trick-dom-testing-library.ts":{"bytes":3555,"imports":[]},"src/deep-query-selectors.ts":{"bytes":3655,"imports":[{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"}]},"src/shadow-queries.ts":{"bytes":10587,"imports":[{"path":"src/deep-query-selectors.ts","kind":"import-statement"},{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"}]},"src/pretty-shadow-dom.ts":{"bytes":8367,"imports":[{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"}]},"src/log-shadow-dom.ts":{"bytes":700,"imports":[{"path":"src/pretty-shadow-dom.ts","kind":"import-statement"},{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"}]},"src/debug.ts":{"bytes":352,"imports":[{"path":"src/log-shadow-dom.ts","kind":"import-statement"}]},"src/shadow-screen.ts":{"bytes":9324,"imports":[{"path":"src/debug.ts","kind":"import-statement"},{"path":"src/shadow-queries.ts","kind":"import-statement"}]},"src/types.ts":{"bytes":2196,"imports":[]},"src/index.ts":{"bytes":802,"imports":[{"path":"src/shadow-queries.ts","kind":"import-statement"},{"path":"src/debug.ts","kind":"import-statement"},{"path":"src/log-shadow-dom.ts","kind":"import-statement"},{"path":"src/pretty-shadow-dom.ts","kind":"import-statement"},{"path":"src/shadow-screen.ts","kind":"import-statement"},{"path":"src/types.ts","kind":"import-statement"},{"path":"src/shadow-queries.ts","kind":"import-statement"},{"path":"src/deep-query-selectors.ts","kind":"import-statement"}]}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":61714},"dist/index.cjs":{"imports":[],"exports":[],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":1708},"src/shadow-queries.ts":{"bytesInOutput":4100},"src/trick-dom-testing-library.ts":{"bytesInOutput":1043},"src/deep-query-selectors.ts":{"bytesInOutput":848},"src/log-shadow-dom.ts":{"bytesInOutput":203},"src/pretty-shadow-dom.ts":{"bytesInOutput":2533},"src/debug.ts":{"bytesInOutput":80},"src/shadow-screen.ts":{"bytesInOutput":3438}},"bytes":15614}}} |
@@ -1,1 +0,1 @@ | ||
{"inputs":{"src/deep-query-selectors.ts":{"bytes":3555,"imports":[]},"src/shadow-queries.ts":{"bytes":10219,"imports":[{"path":"src/deep-query-selectors.ts","kind":"import-statement"}]},"src/pretty-shadow-dom.ts":{"bytes":8280,"imports":[]},"src/log-shadow-dom.ts":{"bytes":626,"imports":[{"path":"src/pretty-shadow-dom.ts","kind":"import-statement"}]},"src/debug.ts":{"bytes":407,"imports":[{"path":"src/log-shadow-dom.ts","kind":"import-statement"}]},"src/shadow-screen.ts":{"bytes":9324,"imports":[{"path":"src/debug.ts","kind":"import-statement"},{"path":"src/shadow-queries.ts","kind":"import-statement"}]},"src/trick-dom-testing-library.ts":{"bytes":1227,"imports":[]},"src/types.ts":{"bytes":2196,"imports":[]},"src/index.ts":{"bytes":842,"imports":[{"path":"src/shadow-queries.ts","kind":"import-statement"},{"path":"src/debug.ts","kind":"import-statement"},{"path":"src/log-shadow-dom.ts","kind":"import-statement"},{"path":"src/pretty-shadow-dom.ts","kind":"import-statement"},{"path":"src/shadow-screen.ts","kind":"import-statement"},{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"},{"path":"src/types.ts","kind":"import-statement"},{"path":"src/shadow-queries.ts","kind":"import-statement"},{"path":"src/deep-query-selectors.ts","kind":"import-statement"}]}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":56066},"dist/index.js":{"imports":[],"exports":["debug","deepQuerySelector","deepQuerySelectorAll","findAllByShadowAltText","findAllByShadowDisplayValue","findAllByShadowLabelText","findAllByShadowPlaceholderText","findAllByShadowRole","findAllByShadowTestId","findAllByShadowText","findAllByShadowTitle","findByShadowAltText","findByShadowDisplayValue","findByShadowLabelText","findByShadowPlaceholderText","findByShadowRole","findByShadowTestId","findByShadowText","findByShadowTitle","getAllByShadowAltText","getAllByShadowDisplayValue","getAllByShadowLabelText","getAllByShadowPlaceholderText","getAllByShadowRole","getAllByShadowTestId","getAllByShadowText","getAllByShadowTitle","getAllElementsAndShadowRoots","getByShadowAltText","getByShadowDisplayValue","getByShadowLabelText","getByShadowPlaceholderText","getByShadowRole","getByShadowTestId","getByShadowText","getByShadowTitle","logShadowDOM","prettyShadowDOM","queryAllByShadowAltText","queryAllByShadowDisplayValue","queryAllByShadowLabelText","queryAllByShadowPlaceholderText","queryAllByShadowRole","queryAllByShadowTestId","queryAllByShadowText","queryAllByShadowTitle","queryByShadowAltText","queryByShadowDisplayValue","queryByShadowLabelText","queryByShadowPlaceholderText","queryByShadowRole","queryByShadowTestId","queryByShadowText","queryByShadowTitle","screen","shadowQueries","within"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":117},"src/shadow-queries.ts":{"bytesInOutput":3944},"src/deep-query-selectors.ts":{"bytesInOutput":832},"src/log-shadow-dom.ts":{"bytesInOutput":193},"src/pretty-shadow-dom.ts":{"bytesInOutput":2525},"src/debug.ts":{"bytesInOutput":80},"src/shadow-screen.ts":{"bytesInOutput":3438},"src/trick-dom-testing-library.ts":{"bytesInOutput":395}},"bytes":13127}}} | ||
{"inputs":{"src/trick-dom-testing-library.ts":{"bytes":3555,"imports":[]},"src/deep-query-selectors.ts":{"bytes":3655,"imports":[{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"}]},"src/shadow-queries.ts":{"bytes":10587,"imports":[{"path":"src/deep-query-selectors.ts","kind":"import-statement"},{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"}]},"src/pretty-shadow-dom.ts":{"bytes":8367,"imports":[{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"}]},"src/log-shadow-dom.ts":{"bytes":700,"imports":[{"path":"src/pretty-shadow-dom.ts","kind":"import-statement"},{"path":"src/trick-dom-testing-library.ts","kind":"import-statement"}]},"src/debug.ts":{"bytes":352,"imports":[{"path":"src/log-shadow-dom.ts","kind":"import-statement"}]},"src/shadow-screen.ts":{"bytes":9324,"imports":[{"path":"src/debug.ts","kind":"import-statement"},{"path":"src/shadow-queries.ts","kind":"import-statement"}]},"src/types.ts":{"bytes":2196,"imports":[]},"src/index.ts":{"bytes":802,"imports":[{"path":"src/shadow-queries.ts","kind":"import-statement"},{"path":"src/debug.ts","kind":"import-statement"},{"path":"src/log-shadow-dom.ts","kind":"import-statement"},{"path":"src/pretty-shadow-dom.ts","kind":"import-statement"},{"path":"src/shadow-screen.ts","kind":"import-statement"},{"path":"src/types.ts","kind":"import-statement"},{"path":"src/shadow-queries.ts","kind":"import-statement"},{"path":"src/deep-query-selectors.ts","kind":"import-statement"}]}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":60168},"dist/index.js":{"imports":[],"exports":["debug","deepQuerySelector","deepQuerySelectorAll","findAllByShadowAltText","findAllByShadowDisplayValue","findAllByShadowLabelText","findAllByShadowPlaceholderText","findAllByShadowRole","findAllByShadowTestId","findAllByShadowText","findAllByShadowTitle","findByShadowAltText","findByShadowDisplayValue","findByShadowLabelText","findByShadowPlaceholderText","findByShadowRole","findByShadowTestId","findByShadowText","findByShadowTitle","getAllByShadowAltText","getAllByShadowDisplayValue","getAllByShadowLabelText","getAllByShadowPlaceholderText","getAllByShadowRole","getAllByShadowTestId","getAllByShadowText","getAllByShadowTitle","getAllElementsAndShadowRoots","getByShadowAltText","getByShadowDisplayValue","getByShadowLabelText","getByShadowPlaceholderText","getByShadowRole","getByShadowTestId","getByShadowText","getByShadowTitle","logShadowDOM","prettyShadowDOM","queryAllByShadowAltText","queryAllByShadowDisplayValue","queryAllByShadowLabelText","queryAllByShadowPlaceholderText","queryAllByShadowRole","queryAllByShadowTestId","queryAllByShadowText","queryAllByShadowTitle","queryByShadowAltText","queryByShadowDisplayValue","queryByShadowLabelText","queryByShadowPlaceholderText","queryByShadowRole","queryByShadowTestId","queryByShadowText","queryByShadowTitle","screen","shadowQueries","within"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":112},"src/shadow-queries.ts":{"bytesInOutput":4002},"src/trick-dom-testing-library.ts":{"bytesInOutput":1043},"src/deep-query-selectors.ts":{"bytesInOutput":848},"src/log-shadow-dom.ts":{"bytesInOutput":200},"src/pretty-shadow-dom.ts":{"bytesInOutput":2532},"src/debug.ts":{"bytesInOutput":80},"src/shadow-screen.ts":{"bytesInOutput":3439}},"bytes":13860}}} |
{ | ||
"name": "shadow-dom-testing-library", | ||
"version": "1.9.1", | ||
"version": "1.10.0", | ||
"description": "An extension of DOM-testing-library to provide hooks into the shadow dom", | ||
@@ -5,0 +5,0 @@ "type": "module", |
import { screen } from "@testing-library/dom"; | ||
import { logShadowDOM } from "./log-shadow-dom"; | ||
import { prettyShadowDOM } from "./pretty-shadow-dom"; | ||
@@ -5,0 +4,0 @@ export function debug(...args: Parameters<typeof screen.debug>) { |
@@ -0,1 +1,2 @@ | ||
import { patchWrap } from "./trick-dom-testing-library"; | ||
import { Container, ShadowOptions } from "./types"; | ||
@@ -34,8 +35,10 @@ | ||
): T[] { | ||
const elements = getAllElementsAndShadowRoots(container, options); | ||
return patchWrap(() => { | ||
const elements = getAllElementsAndShadowRoots(container, options); | ||
const queriedElements = elements | ||
.map((el) => Array.from(el.querySelectorAll<T>(selector))) | ||
.flat(Infinity) as T[]; | ||
return [...new Set(queriedElements)]; | ||
const queriedElements = elements | ||
.map((el) => Array.from(el.querySelectorAll<T>(selector))) | ||
.flat(Infinity) as T[]; | ||
return [...new Set(queriedElements)]; | ||
}); | ||
} | ||
@@ -42,0 +45,0 @@ |
@@ -8,6 +8,4 @@ import { queries, within } from "@testing-library/dom"; | ||
import { shadowScreen } from "./shadow-screen"; | ||
import { trickDOMTestingLibrary } from "./trick-dom-testing-library"; | ||
import { patchWrap } from "./trick-dom-testing-library"; | ||
trickDOMTestingLibrary(); | ||
const allQueries = { | ||
@@ -14,0 +12,0 @@ ...queries, |
@@ -7,2 +7,3 @@ import { logDOM } from "@testing-library/dom"; | ||
import type { NewPlugin } from "pretty-format"; | ||
import { patchWrap } from "./trick-dom-testing-library"; | ||
@@ -22,3 +23,3 @@ export function logShadowDOM( | ||
logDOM(dom, maxLength, options); | ||
patchWrap(() => logDOM(dom, maxLength, options)); | ||
} |
import { prettyDOM, getConfig } from "@testing-library/dom"; | ||
import type { Config, NewPlugin, Printer, Refs } from "pretty-format"; | ||
import { patchWrap } from "./trick-dom-testing-library"; | ||
@@ -29,6 +30,8 @@ // This regexp combo took way too long to figure out... | ||
return prettyDOM(dom, maxLength, { | ||
...options, | ||
plugins: [plugin], | ||
}); | ||
return patchWrap(() => | ||
prettyDOM(dom, maxLength, { | ||
...options, | ||
plugins: [plugin], | ||
}) | ||
); | ||
} | ||
@@ -35,0 +38,0 @@ |
@@ -16,2 +16,3 @@ import { | ||
import { getAllElementsAndShadowRoots } from "./deep-query-selectors"; | ||
import { patchWrap } from "./trick-dom-testing-library"; | ||
import { | ||
@@ -51,5 +52,7 @@ ScreenShadowMatcherParams, | ||
...new Set( | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByRole(el as HTMLElement, role, options)) | ||
.flat(Infinity) | ||
patchWrap(() => | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByRole(el as HTMLElement, role, options)) | ||
.flat(Infinity) | ||
) | ||
), | ||
@@ -92,5 +95,7 @@ ] as T[]; | ||
...new Set( | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByLabelText(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
patchWrap(() => | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByLabelText(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
) | ||
), | ||
@@ -133,5 +138,9 @@ ] as T[]; | ||
...new Set( | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByPlaceholderText(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
patchWrap(() => | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => | ||
queryAllByPlaceholderText(el as HTMLElement, id, options) | ||
) | ||
.flat(Infinity) | ||
) | ||
), | ||
@@ -174,5 +183,7 @@ ] as T[]; | ||
...new Set( | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByText(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
patchWrap(() => | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByText(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
) | ||
), | ||
@@ -215,5 +226,7 @@ ] as T[]; | ||
...new Set( | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByDisplayValue(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
patchWrap(() => | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByDisplayValue(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
) | ||
), | ||
@@ -256,5 +269,7 @@ ] as T[]; | ||
...new Set( | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByAltText(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
patchWrap(() => | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByAltText(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
) | ||
), | ||
@@ -297,5 +312,7 @@ ] as T[]; | ||
...new Set( | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByTitle(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
patchWrap(() => | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByTitle(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
) | ||
), | ||
@@ -338,5 +355,7 @@ ] as T[]; | ||
...new Set( | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByTestId(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
patchWrap(() => | ||
getAllElementsAndShadowRoots(container, options) | ||
.map((el) => queryAllByTestId(el as HTMLElement, id, options)) | ||
.flat(Infinity) | ||
) | ||
), | ||
@@ -343,0 +362,0 @@ ] as T[]; |
declare global { | ||
interface ShadowRoot { | ||
matches?: (this: ShadowRoot, string: string) => boolean; | ||
outerHTML?: string; | ||
matches?: typeof HTMLElement.prototype.matches; | ||
outerHTML?: typeof HTMLElement.prototype.outerHTML; | ||
} | ||
} | ||
// Okay. For some reason shadow root patches cant be part of patchDOM. Haven't figured out why. | ||
// Only reason I can come up with is the patchWrap() may be conflicting with internals of dom-testing-library? | ||
// I do know calling `.getByText(el.shadowRoot)` will fail without this patch. | ||
// outerHTML fails with some issue around "this". | ||
// IDK...but this is weird, no its not the most responsible patch, but it works. | ||
// Just dont go calling .matches() or .outerHTML() on shadowRoots in your code... | ||
// This previously existed in other version of SDTL so not a huge deal. | ||
patchShadowRoot(); | ||
// Amazingly fun hack to trick DOM testing libraries internal type checking logic. | ||
// https://github.com/testing-library/dom-testing-library/blob/73a5694529dbfff289f3d7a01470c45ef5c77715/src/queries/text.ts#L34-L36 | ||
// https://github.com/testing-library/dom-testing-library/blob/73a5694529dbfff289f3d7a01470c45ef5c77715/src/pretty-dom.js#L50-L54 | ||
export function trickDOMTestingLibrary() { | ||
export function patchDOM() { | ||
patchSlotElement(); | ||
} | ||
function removeDOMPatch() { | ||
HTMLSlotElement.prototype.querySelectorAll = | ||
HTMLElement.prototype.querySelectorAll; | ||
} | ||
export function patchWrap<T extends (...args: any) => any>( | ||
callback: T | ||
): ReturnType<T> { | ||
patchDOM(); | ||
try { | ||
const val = callback(); | ||
// We only wrap RTL functions, so I dont think anything returns a promise, but just in-case, | ||
// lets make sure we clean up. | ||
if ( | ||
typeof val === "object" && | ||
"finally" in val && | ||
typeof val.finally === "function" | ||
) { | ||
val.finally(() => removeDOMPatch()); | ||
} | ||
return val; | ||
} finally { | ||
removeDOMPatch(); | ||
} | ||
} | ||
function patchShadowRoot() { | ||
if (typeof ShadowRoot == "undefined") | ||
@@ -23,3 +65,3 @@ throw "Your environment does not support shadow roots."; | ||
return this.querySelector(string) != null ? true : false; | ||
return Boolean(this.querySelector(string)); | ||
}; | ||
@@ -41,1 +83,33 @@ }, | ||
} | ||
function patchSlotElement() { | ||
HTMLSlotElement.prototype.querySelectorAll = function (str: string) { | ||
const qsa = HTMLElement.prototype.querySelectorAll; | ||
let els: Element[] = []; | ||
this.assignedElements({ flatten: true }).forEach((_el) => { | ||
const el = _el as Element; | ||
// Clone it and make a scratch buffer because we need to check that _el | ||
// meets the criteria of the querySelector before we push it to "els" | ||
const scratch = document.createElement("div"); | ||
scratch.appendChild(el.cloneNode(false)); | ||
if (scratch.querySelector(str)) { | ||
els.push(el); | ||
} | ||
els = els.concat(Array.from(el.querySelectorAll(str))); | ||
}); | ||
// So because slots have fallback content, we want to only first query for slotted content. | ||
// If theres no slotted content, we fallback to using the default content. | ||
if (els.length == 0) { | ||
els = Array.from(qsa.call(this, str)); | ||
} | ||
return [...new Set(els)] as unknown as ReturnType< | ||
typeof HTMLSlotElement.prototype.querySelectorAll | ||
>; | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
270805
1934