3
3
import path from 'path'
4
4
import fs from 'fs'
5
5
import { queries as baseQueries } from '@testing-library/dom'
6
+ import 'simmerjs'
6
7
7
8
import {
8
9
BrowserBase ,
@@ -29,17 +30,28 @@ const DOM_TESTING_LIBRARY_UMD = fs
29
30
. readFileSync ( DOM_TESTING_LIBRARY_UMD_PATH )
30
31
. toString ( )
31
32
33
+ const SIMMERJS = fs
34
+ . readFileSync ( require . resolve ( 'simmerjs/dist/simmer.js' ) )
35
+ . toString ( )
36
+
32
37
let _config : Partial < Config >
33
38
34
39
async function injectDOMTestingLibrary ( container : ElementBase ) {
35
40
const shouldInject = await container . execute ( function ( ) {
36
- return ! window . TestingLibraryDom
41
+ return {
42
+ domTestingLibrary : ! window . TestingLibraryDom ,
43
+ simmer : ! window . Simmer ,
44
+ }
37
45
} )
38
46
39
- if ( shouldInject ) {
47
+ if ( shouldInject . domTestingLibrary ) {
40
48
await container . execute ( DOM_TESTING_LIBRARY_UMD )
41
49
}
42
50
51
+ if ( shouldInject . simmer ) {
52
+ await container . execute ( SIMMERJS )
53
+ }
54
+
43
55
if ( _config ) {
44
56
await container . execute ( function ( config : Config ) {
45
57
window . TestingLibraryDom . configure ( config )
@@ -71,7 +83,7 @@ function executeQuery(
71
83
container : HTMLElement ,
72
84
...args : any [ ]
73
85
) {
74
- const done = args . pop ( ) as ( result : any ) => void ;
86
+ const done = args . pop ( ) as ( result : any ) => void
75
87
76
88
// @ts -ignore
77
89
function deserializeObject ( object ) {
@@ -104,25 +116,20 @@ function executeQuery(
104
116
waitForOptions ,
105
117
) ,
106
118
)
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
+ } )
108
130
. catch ( ( e ) => done ( e . message ) )
109
131
}
110
132
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
-
126
133
function createQuery ( element : ElementBase , queryName : string ) {
127
134
return async ( ...args : any [ ] ) => {
128
135
await injectDOMTestingLibrary ( element )
@@ -143,10 +150,10 @@ function createQuery(element: ElementBase, queryName: string) {
143
150
}
144
151
145
152
if ( Array . isArray ( result ) ) {
146
- return Promise . all ( result . map ( createElement . bind ( null , element ) ) )
153
+ return Promise . all ( result . map ( ( { selector } ) => element . $ ( selector ) ) )
147
154
}
148
155
149
- return createElement ( element , result )
156
+ return element . $ ( result . selector )
150
157
}
151
158
}
152
159
0 commit comments