33import path from 'path'
44import fs from 'fs'
55import { queries as baseQueries } from '@testing-library/dom'
6+ import 'simmerjs'
67
78import {
89 BrowserBase ,
@@ -29,17 +30,28 @@ const DOM_TESTING_LIBRARY_UMD = fs
2930 . readFileSync ( DOM_TESTING_LIBRARY_UMD_PATH )
3031 . toString ( )
3132
33+ const SIMMERJS = fs
34+ . readFileSync ( require . resolve ( 'simmerjs/dist/simmer.js' ) )
35+ . toString ( )
36+
3237let _config : Partial < Config >
3338
3439async function injectDOMTestingLibrary ( container : ElementBase ) {
3540 const shouldInject = await container . execute ( function ( ) {
36- return ! window . TestingLibraryDom
41+ return {
42+ domTestingLibrary : ! window . TestingLibraryDom ,
43+ simmer : ! window . Simmer ,
44+ }
3745 } )
3846
39- if ( shouldInject ) {
47+ if ( shouldInject . domTestingLibrary ) {
4048 await container . execute ( DOM_TESTING_LIBRARY_UMD )
4149 }
4250
51+ if ( shouldInject . simmer ) {
52+ await container . execute ( SIMMERJS )
53+ }
54+
4355 if ( _config ) {
4456 await container . execute ( function ( config : Config ) {
4557 window . TestingLibraryDom . configure ( config )
@@ -71,7 +83,7 @@ function executeQuery(
7183 container : HTMLElement ,
7284 ...args : any [ ]
7385) {
74- const done = args . pop ( ) as ( result : any ) => void ;
86+ const done = args . pop ( ) as ( result : any ) => void
7587
7688 // @ts -ignore
7789 function deserializeObject ( object ) {
@@ -104,25 +116,20 @@ function executeQuery(
104116 waitForOptions ,
105117 ) ,
106118 )
107- . then ( done )
119+ . then ( ( result ) => {
120+ if ( ! result ) {
121+ return done ( null )
122+ }
123+ if ( Array . isArray ( result ) ) {
124+ return done (
125+ result . map ( ( element ) => ( { selector : window . Simmer ( element ) } ) ) ,
126+ )
127+ }
128+ return done ( { selector : window . Simmer ( result ) } )
129+ } )
108130 . catch ( ( e ) => done ( e . message ) )
109131}
110132
111- /*
112- Always include element key "element-6066-11e4-a52e-4f735466cecf": WebdriverIO
113- checks whether this key is a string to determine if the selector is actually a
114- WebElement JSON. If the selector is a WebElement JSON it uses it to create a new
115- Element. There are valid WebElement JSONs that exclude the key but can be turned
116- into Elements, such as { ELEMENT: elementId }; this can happen in setups that
117- aren't generated by @wdio/cli.
118- */
119- function createElement ( container : ElementBase , elementValue : any ) {
120- return container . $ ( {
121- 'element-6066-11e4-a52e-4f735466cecf' : '' ,
122- ...elementValue ,
123- } )
124- }
125-
126133function createQuery ( element : ElementBase , queryName : string ) {
127134 return async ( ...args : any [ ] ) => {
128135 await injectDOMTestingLibrary ( element )
@@ -143,10 +150,10 @@ function createQuery(element: ElementBase, queryName: string) {
143150 }
144151
145152 if ( Array . isArray ( result ) ) {
146- return Promise . all ( result . map ( createElement . bind ( null , element ) ) )
153+ return Promise . all ( result . map ( ( { selector } ) => element . $ ( selector ) ) )
147154 }
148155
149- return createElement ( element , result )
156+ return element . $ ( result . selector )
150157 }
151158}
152159
0 commit comments