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 )
@@ -105,28 +117,23 @@ function executeQuery(
105117 waitForOptions ,
106118 ) ,
107119 )
108- . then ( done )
120+ . then ( ( result ) => {
121+ if ( ! result ) {
122+ return done ( null )
123+ }
124+ if ( Array . isArray ( result ) ) {
125+ return done (
126+ result . map ( ( element ) => ( { selector : window . Simmer ( element ) } ) ) ,
127+ )
128+ }
129+ return done ( { selector : window . Simmer ( result ) } )
130+ } )
109131 . catch ( ( e ) => done ( e . message ) )
110132 } catch ( e ) {
111133 done ( e . message )
112134 }
113135}
114136
115- /*
116- Always include element key "element-6066-11e4-a52e-4f735466cecf": WebdriverIO
117- checks whether this key is a string to determine if the selector is actually a
118- WebElement JSON. If the selector is a WebElement JSON it uses it to create a new
119- Element. There are valid WebElement JSONs that exclude the key but can be turned
120- into Elements, such as { ELEMENT: elementId }; this can happen in setups that
121- aren't generated by @wdio/cli.
122- */
123- function createElement ( container : ElementBase , elementValue : any ) {
124- return container . $ ( {
125- 'element-6066-11e4-a52e-4f735466cecf' : '' ,
126- ...elementValue ,
127- } )
128- }
129-
130137function createQuery ( element : ElementBase , queryName : string ) {
131138 return async ( ...args : any [ ] ) => {
132139 await injectDOMTestingLibrary ( element )
@@ -147,10 +154,10 @@ function createQuery(element: ElementBase, queryName: string) {
147154 }
148155
149156 if ( Array . isArray ( result ) ) {
150- return Promise . all ( result . map ( createElement . bind ( null , element ) ) )
157+ return Promise . all ( result . map ( ( { selector } ) => element . $ ( selector ) ) )
151158 }
152159
153- return createElement ( element , result )
160+ return element . $ ( result . selector )
154161 }
155162}
156163
0 commit comments