@@ -84,6 +84,19 @@ def _install_packages(self: Any) -> None:
84
84
result = self .run_js (
85
85
f'await pyodide.loadPackage("http://{ testserver_http .http_host } :{ testserver_http .http_port } /dist/urllib3.whl")'
86
86
)
87
+ if not self .with_jspi :
88
+ # force Chrome to execute the current test without JSPI
89
+ # even though it is always enabled in
90
+ # chrome >= 137. We do this by monkeypatching
91
+ # pyodide.ffi.can_run_sync
92
+ self .run_async (
93
+ """
94
+ import pyodide.ffi
95
+ if pyodide.ffi.can_run_sync():
96
+ pyodide.ffi.can_run_sync = lambda: False
97
+ """
98
+ )
99
+
87
100
print ("Installed package:" , result )
88
101
self .run_js (
89
102
"""
@@ -128,11 +141,14 @@ def _install_packages(self: Any) -> None:
128
141
129
142
130
143
class ServerRunnerInfo :
131
- def __init__ (self , host : str , port : int , selenium : Any , dist_dir : Path ) -> None :
144
+ def __init__ (
145
+ self , host : str , port : int , selenium : Any , dist_dir : Path , has_jspi : bool
146
+ ) -> None :
132
147
self .host = host
133
148
self .port = port
134
149
self .selenium = selenium
135
150
self .dist_dir = dist_dir
151
+ self .has_jspi = has_jspi
136
152
137
153
def run_webworker (self , code : str ) -> Any :
138
154
if isinstance (code , str ) and code .startswith ("\n " ):
@@ -148,6 +164,19 @@ def run_webworker(self, code: str) -> Any:
148
164
"""
149
165
)
150
166
167
+ # Monkeypatch pyodide to force disable JSPI in newer chrome
168
+ # so those code paths get tested
169
+ if self .has_jspi is False :
170
+ jspi_fix_code = textwrap .dedent (
171
+ """
172
+ import pyodide.ffi
173
+ if pyodide.ffi.can_run_sync():
174
+ pyodide.ffi.can_run_sync = lambda: False
175
+ """
176
+ )
177
+ else :
178
+ jspi_fix_code = ""
179
+
151
180
coverage_end_code = textwrap .dedent (
152
181
"""
153
182
_coverage.stop()
@@ -164,7 +193,15 @@ def run_webworker(self, code: str) -> Any:
164
193
165
194
# the ordering of these code blocks is important - makes sure
166
195
# that the first thing that happens is our wheel is loaded
167
- code = coverage_init_code + "\n " + code + "\n " + coverage_end_code
196
+ code = (
197
+ coverage_init_code
198
+ + "\n "
199
+ + jspi_fix_code
200
+ + "\n "
201
+ + code
202
+ + "\n "
203
+ + coverage_end_code
204
+ )
168
205
169
206
if self .selenium .browser == "firefox" :
170
207
# running in worker is SLOW on firefox
@@ -232,6 +269,7 @@ def run_from_server(
232
269
testserver_http .https_port ,
233
270
selenium_coverage ,
234
271
dist_dir ,
272
+ selenium_coverage .with_jspi ,
235
273
)
236
274
237
275
0 commit comments