@@ -149,99 +149,6 @@ function createEvaluator({ rootNode }) {
149149 return { context, evaluator, exec, wrap } ;
150150}
151151
152- function createSandbox ( { markup } ) {
153- // render the frame in a container, so we can set "display: none". If the
154- // hiding would be done in the frame itself, testing-library would mark the
155- // entire dom as being inaccessible. Now we don't have this problem :)
156- const container = document . createElement ( 'div' ) ;
157- container . setAttribute (
158- 'style' ,
159- 'width: 1px; height: 1px; overflow: hidden; display: none;' ,
160- ) ;
161-
162- const frame = document . createElement ( 'iframe' ) ;
163- frame . setAttribute ( 'security' , 'restricted' ) ;
164- frame . setAttribute ( 'scrolling' , 'no' ) ;
165- frame . setAttribute ( 'frameBorder' , '0' ) ;
166- frame . setAttribute ( 'allowTransparency' , 'true' ) ;
167- frame . setAttribute (
168- 'sandbox' ,
169- 'allow-same-origin allow-scripts allow-popups allow-forms' ,
170- ) ;
171- frame . setAttribute (
172- 'style' ,
173- 'width: 800px; height: 600px; top: 0; left: 0px; border: 3px solid red;' ,
174- ) ;
175- container . appendChild ( frame ) ;
176- document . body . appendChild ( container ) ;
177-
178- const sandbox = frame . contentDocument || frame . contentWindow . document ;
179- const { context, evaluator, wrap } = createEvaluator ( {
180- rootNode : sandbox . body ,
181- } ) ;
182-
183- const script = sandbox . createElement ( 'script' ) ;
184- script . setAttribute ( 'type' , 'text/javascript' ) ;
185- script . innerHTML = `
186- window.exec = function exec(context, expr) {
187- const evaluator = ${ evaluator } ;
188-
189- return evaluator.apply(null, [...Object.values(context), (expr || '').trim()]);
190- }
191- ` ;
192-
193- sandbox . head . appendChild ( script ) ;
194- sandbox . body . innerHTML = markup ;
195-
196- let body = markup ;
197-
198- // mock out userEvent in the fake sandbox
199- Object . keys ( context . userEvent ) . map ( ( x ) => {
200- context . userEvent [ x ] = ( ) => { } ;
201- } ) ;
202-
203- return {
204- rootNode : sandbox . body ,
205- ensureMarkup : ( html ) => {
206- if ( body !== html ) {
207- sandbox . body . innerHTML = html ;
208- body = html ;
209- }
210- } ,
211- eval : ( query ) =>
212- wrap ( ( ) => frame . contentWindow . exec ( context , query ) , { markup, query } ) ,
213- destroy : ( ) => document . body . removeChild ( container ) ,
214- } ;
215- }
216-
217- const sandboxes = { } ;
218-
219- /**
220- * runInSandbox
221- *
222- * Create a sandbox in which the body element is populated with the
223- * provided html `markup`. The javascript `query` is injected into
224- * the document for evaluation.
225- *
226- * By providing a `cacheId`, the sandbox can be persisted. This
227- * allows one to reuse an instance, and thereby speed up successive
228- * queries.
229- */
230- function runInSandbox ( { markup, query, cacheId } ) {
231- const sandbox = sandboxes [ cacheId ] || createSandbox ( { markup } ) ;
232- sandbox . ensureMarkup ( markup ) ;
233-
234- const result = sandbox . eval ( query ) ;
235-
236- if ( cacheId && ! sandboxes [ cacheId ] ) {
237- sandboxes [ cacheId ] = sandbox ;
238- } else {
239- sandbox . destroy ( ) ;
240- }
241-
242- return result ;
243- }
244-
245152function runUnsafe ( { rootNode, query } ) {
246153 const evaluator = createEvaluator ( { rootNode } ) ;
247154
@@ -260,14 +167,12 @@ function configure({ testIdAttribute }) {
260167 testingLibraryConfigure ( { testIdAttribute } ) ;
261168}
262169
263- function parse ( { rootNode, markup , query, cacheId , prevResult } ) {
264- if ( typeof markup !== 'string' && ! rootNode ) {
265- throw new Error ( 'either markup or rootNode should be provided' ) ;
170+ function parse ( { rootNode, query, prevResult } ) {
171+ if ( ! rootNode ) {
172+ throw new Error ( ` rootNode should be provided` ) ;
266173 }
267174
268- const result = rootNode
269- ? runUnsafe ( { rootNode, query } )
270- : runInSandbox ( { markup, query, cacheId } ) ;
175+ const result = runUnsafe ( { rootNode, query } ) ;
271176
272177 result . expression = getLastExpression ( query ) ;
273178
0 commit comments