@lynx-js/testing-environment 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +11 -19
- package/dist/index.js +11 -19
- package/dist/lynx/ElementPAPI.cjs +2 -4
- package/dist/lynx/ElementPAPI.js +2 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -72,12 +72,11 @@ function __injectElementApi(target) {
|
|
|
72
72
|
function createPolyfills() {
|
|
73
73
|
const app = {
|
|
74
74
|
callLepusMethod: (...rLynxChange)=>{
|
|
75
|
-
var _rLynxChange_;
|
|
76
75
|
const isBackground = !__MAIN_THREAD__;
|
|
77
76
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
78
77
|
globalThis[rLynxChange[0]](rLynxChange[1]);
|
|
79
78
|
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
80
|
-
|
|
79
|
+
rLynxChange[2]?.();
|
|
81
80
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
82
81
|
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
83
82
|
},
|
|
@@ -118,6 +117,7 @@ function createPolyfills() {
|
|
|
118
117
|
};
|
|
119
118
|
const ee = new (external_events_default())();
|
|
120
119
|
ee.dispatchEvent = ({ type, data })=>{
|
|
120
|
+
if (!globalThis.lynxTestingEnv) return;
|
|
121
121
|
const origin = __MAIN_THREAD__ ? 'CoreContext' : 'JSContext';
|
|
122
122
|
if ('CoreContext' === origin) lynxTestingEnv.switchToBackgroundThread();
|
|
123
123
|
else lynxTestingEnv.switchToMainThread();
|
|
@@ -136,10 +136,8 @@ function createPolyfills() {
|
|
|
136
136
|
const isBackground = !__MAIN_THREAD__;
|
|
137
137
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
138
138
|
let ans;
|
|
139
|
-
if ('worklet-runtime' === chunkName)
|
|
140
|
-
|
|
141
|
-
ans = null == (_globalThis_onInitWorkletRuntime = (_globalThis = globalThis).onInitWorkletRuntime) ? void 0 : _globalThis_onInitWorkletRuntime.call(_globalThis);
|
|
142
|
-
} else throw new Error(`__LoadLepusChunk: Unknown chunk name: ${chunkName}`);
|
|
139
|
+
if ('worklet-runtime' === chunkName) ans = globalThis.onInitWorkletRuntime?.();
|
|
140
|
+
else throw new Error(`__LoadLepusChunk: Unknown chunk name: ${chunkName}`);
|
|
143
141
|
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
144
142
|
return ans;
|
|
145
143
|
}
|
|
@@ -159,7 +157,6 @@ function createPreconfiguredConsole() {
|
|
|
159
157
|
return console1;
|
|
160
158
|
}
|
|
161
159
|
function injectMainThreadGlobals(target, polyfills) {
|
|
162
|
-
var _globalThis_onInjectMainThreadGlobals, _globalThis;
|
|
163
160
|
__injectElementApi(target);
|
|
164
161
|
const { performance, CoreContext, JsContext, __LoadLepusChunk } = polyfills || {};
|
|
165
162
|
if (void 0 === target) target = globalThis;
|
|
@@ -187,7 +184,7 @@ function injectMainThreadGlobals(target, polyfills) {
|
|
|
187
184
|
target.cancelAnimationFrame = clearTimeout;
|
|
188
185
|
target.console = createPreconfiguredConsole();
|
|
189
186
|
target.__LoadLepusChunk = __LoadLepusChunk;
|
|
190
|
-
|
|
187
|
+
globalThis.onInjectMainThreadGlobals?.(target);
|
|
191
188
|
}
|
|
192
189
|
const IGNORE_LIST_GLOBALS = [
|
|
193
190
|
'globalThis',
|
|
@@ -220,7 +217,6 @@ class NodesRef {
|
|
|
220
217
|
}
|
|
221
218
|
}
|
|
222
219
|
function injectBackgroundThreadGlobals(target, polyfills) {
|
|
223
|
-
var _globalThis_onInjectBackgroundThreadGlobals, _globalThis;
|
|
224
220
|
const { app, performance, CoreContext, JsContext, __LoadLepusChunk } = polyfills || {};
|
|
225
221
|
if (void 0 === target) target = globalThis;
|
|
226
222
|
target.__DEV__ = true;
|
|
@@ -283,7 +279,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
|
|
|
283
279
|
lynxSdkVersion: '3.0'
|
|
284
280
|
};
|
|
285
281
|
target.__LoadLepusChunk = __LoadLepusChunk;
|
|
286
|
-
|
|
282
|
+
globalThis.onInjectBackgroundThreadGlobals?.(target);
|
|
287
283
|
}
|
|
288
284
|
class LynxTestingEnv {
|
|
289
285
|
injectGlobals() {
|
|
@@ -292,38 +288,34 @@ class LynxTestingEnv {
|
|
|
292
288
|
injectMainThreadGlobals(this.mainThread.globalThis, polyfills);
|
|
293
289
|
}
|
|
294
290
|
switchToBackgroundThread() {
|
|
295
|
-
var _globalThis_onSwitchedToBackgroundThread, _globalThis;
|
|
296
291
|
this.originals = new Map();
|
|
297
292
|
Object.getOwnPropertyNames(this.backgroundThread.globalThis).forEach((key)=>{
|
|
298
293
|
if (IGNORE_LIST_GLOBALS.includes(key)) return;
|
|
299
294
|
this.originals.set(key, global[key]);
|
|
300
295
|
global[key] = this.backgroundThread.globalThis[key];
|
|
301
296
|
});
|
|
302
|
-
|
|
297
|
+
globalThis?.onSwitchedToBackgroundThread?.();
|
|
303
298
|
}
|
|
304
299
|
switchToMainThread() {
|
|
305
|
-
var _globalThis_onSwitchedToMainThread, _globalThis;
|
|
306
300
|
this.originals = new Map();
|
|
307
301
|
Object.getOwnPropertyNames(this.mainThread.globalThis).forEach((key)=>{
|
|
308
302
|
if (IGNORE_LIST_GLOBALS.includes(key)) return;
|
|
309
303
|
this.originals.set(key, global[key]);
|
|
310
304
|
global[key] = this.mainThread.globalThis[key];
|
|
311
305
|
});
|
|
312
|
-
|
|
306
|
+
globalThis?.onSwitchedToMainThread?.();
|
|
313
307
|
}
|
|
314
308
|
clearGlobal() {
|
|
315
|
-
|
|
316
|
-
null == (_this_originals = this.originals) || _this_originals.forEach((v, k)=>{
|
|
309
|
+
this.originals?.forEach((v, k)=>{
|
|
317
310
|
global[k] = v;
|
|
318
311
|
});
|
|
319
|
-
|
|
312
|
+
this.originals?.clear();
|
|
320
313
|
}
|
|
321
314
|
reset() {
|
|
322
|
-
var _globalThis_onResetLynxTestingEnv, _globalThis;
|
|
323
315
|
this.injectGlobals();
|
|
324
316
|
this.switchToMainThread();
|
|
325
317
|
this.switchToBackgroundThread();
|
|
326
|
-
|
|
318
|
+
globalThis.onResetLynxTestingEnv?.();
|
|
327
319
|
}
|
|
328
320
|
constructor(jsdom){
|
|
329
321
|
_define_property(this, "originals", new Map());
|
package/dist/index.js
CHANGED
|
@@ -33,12 +33,11 @@ function __injectElementApi(target) {
|
|
|
33
33
|
function createPolyfills() {
|
|
34
34
|
const app = {
|
|
35
35
|
callLepusMethod: (...rLynxChange)=>{
|
|
36
|
-
var _rLynxChange_;
|
|
37
36
|
const isBackground = !__MAIN_THREAD__;
|
|
38
37
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
39
38
|
globalThis[rLynxChange[0]](rLynxChange[1]);
|
|
40
39
|
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
41
|
-
|
|
40
|
+
rLynxChange[2]?.();
|
|
42
41
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
43
42
|
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
44
43
|
},
|
|
@@ -79,6 +78,7 @@ function createPolyfills() {
|
|
|
79
78
|
};
|
|
80
79
|
const ee = new events();
|
|
81
80
|
ee.dispatchEvent = ({ type, data })=>{
|
|
81
|
+
if (!globalThis.lynxTestingEnv) return;
|
|
82
82
|
const origin = __MAIN_THREAD__ ? 'CoreContext' : 'JSContext';
|
|
83
83
|
if ('CoreContext' === origin) lynxTestingEnv.switchToBackgroundThread();
|
|
84
84
|
else lynxTestingEnv.switchToMainThread();
|
|
@@ -97,10 +97,8 @@ function createPolyfills() {
|
|
|
97
97
|
const isBackground = !__MAIN_THREAD__;
|
|
98
98
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
99
99
|
let ans;
|
|
100
|
-
if ('worklet-runtime' === chunkName)
|
|
101
|
-
|
|
102
|
-
ans = null == (_globalThis_onInitWorkletRuntime = (_globalThis = globalThis).onInitWorkletRuntime) ? void 0 : _globalThis_onInitWorkletRuntime.call(_globalThis);
|
|
103
|
-
} else throw new Error(`__LoadLepusChunk: Unknown chunk name: ${chunkName}`);
|
|
100
|
+
if ('worklet-runtime' === chunkName) ans = globalThis.onInitWorkletRuntime?.();
|
|
101
|
+
else throw new Error(`__LoadLepusChunk: Unknown chunk name: ${chunkName}`);
|
|
104
102
|
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
105
103
|
return ans;
|
|
106
104
|
}
|
|
@@ -120,7 +118,6 @@ function createPreconfiguredConsole() {
|
|
|
120
118
|
return console1;
|
|
121
119
|
}
|
|
122
120
|
function injectMainThreadGlobals(target, polyfills) {
|
|
123
|
-
var _globalThis_onInjectMainThreadGlobals, _globalThis;
|
|
124
121
|
__injectElementApi(target);
|
|
125
122
|
const { performance, CoreContext, JsContext, __LoadLepusChunk } = polyfills || {};
|
|
126
123
|
if (void 0 === target) target = globalThis;
|
|
@@ -148,7 +145,7 @@ function injectMainThreadGlobals(target, polyfills) {
|
|
|
148
145
|
target.cancelAnimationFrame = clearTimeout;
|
|
149
146
|
target.console = createPreconfiguredConsole();
|
|
150
147
|
target.__LoadLepusChunk = __LoadLepusChunk;
|
|
151
|
-
|
|
148
|
+
globalThis.onInjectMainThreadGlobals?.(target);
|
|
152
149
|
}
|
|
153
150
|
const IGNORE_LIST_GLOBALS = [
|
|
154
151
|
'globalThis',
|
|
@@ -181,7 +178,6 @@ class NodesRef {
|
|
|
181
178
|
}
|
|
182
179
|
}
|
|
183
180
|
function injectBackgroundThreadGlobals(target, polyfills) {
|
|
184
|
-
var _globalThis_onInjectBackgroundThreadGlobals, _globalThis;
|
|
185
181
|
const { app, performance, CoreContext, JsContext, __LoadLepusChunk } = polyfills || {};
|
|
186
182
|
if (void 0 === target) target = globalThis;
|
|
187
183
|
target.__DEV__ = true;
|
|
@@ -244,7 +240,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
|
|
|
244
240
|
lynxSdkVersion: '3.0'
|
|
245
241
|
};
|
|
246
242
|
target.__LoadLepusChunk = __LoadLepusChunk;
|
|
247
|
-
|
|
243
|
+
globalThis.onInjectBackgroundThreadGlobals?.(target);
|
|
248
244
|
}
|
|
249
245
|
class LynxTestingEnv {
|
|
250
246
|
injectGlobals() {
|
|
@@ -253,38 +249,34 @@ class LynxTestingEnv {
|
|
|
253
249
|
injectMainThreadGlobals(this.mainThread.globalThis, polyfills);
|
|
254
250
|
}
|
|
255
251
|
switchToBackgroundThread() {
|
|
256
|
-
var _globalThis_onSwitchedToBackgroundThread, _globalThis;
|
|
257
252
|
this.originals = new Map();
|
|
258
253
|
Object.getOwnPropertyNames(this.backgroundThread.globalThis).forEach((key)=>{
|
|
259
254
|
if (IGNORE_LIST_GLOBALS.includes(key)) return;
|
|
260
255
|
this.originals.set(key, global[key]);
|
|
261
256
|
global[key] = this.backgroundThread.globalThis[key];
|
|
262
257
|
});
|
|
263
|
-
|
|
258
|
+
globalThis?.onSwitchedToBackgroundThread?.();
|
|
264
259
|
}
|
|
265
260
|
switchToMainThread() {
|
|
266
|
-
var _globalThis_onSwitchedToMainThread, _globalThis;
|
|
267
261
|
this.originals = new Map();
|
|
268
262
|
Object.getOwnPropertyNames(this.mainThread.globalThis).forEach((key)=>{
|
|
269
263
|
if (IGNORE_LIST_GLOBALS.includes(key)) return;
|
|
270
264
|
this.originals.set(key, global[key]);
|
|
271
265
|
global[key] = this.mainThread.globalThis[key];
|
|
272
266
|
});
|
|
273
|
-
|
|
267
|
+
globalThis?.onSwitchedToMainThread?.();
|
|
274
268
|
}
|
|
275
269
|
clearGlobal() {
|
|
276
|
-
|
|
277
|
-
null == (_this_originals = this.originals) || _this_originals.forEach((v, k)=>{
|
|
270
|
+
this.originals?.forEach((v, k)=>{
|
|
278
271
|
global[k] = v;
|
|
279
272
|
});
|
|
280
|
-
|
|
273
|
+
this.originals?.clear();
|
|
281
274
|
}
|
|
282
275
|
reset() {
|
|
283
|
-
var _globalThis_onResetLynxTestingEnv, _globalThis;
|
|
284
276
|
this.injectGlobals();
|
|
285
277
|
this.switchToMainThread();
|
|
286
278
|
this.switchToBackgroundThread();
|
|
287
|
-
|
|
279
|
+
globalThis.onResetLynxTestingEnv?.();
|
|
288
280
|
}
|
|
289
281
|
constructor(jsdom){
|
|
290
282
|
_define_property(this, "originals", new Map());
|
|
@@ -117,8 +117,7 @@ const initElementTree = ()=>{
|
|
|
117
117
|
e.setAttribute(key, JSON.stringify(value));
|
|
118
118
|
}
|
|
119
119
|
__AddEvent(e, eventType, eventName, eventHandler) {
|
|
120
|
-
|
|
121
|
-
if (null == (_e_eventMap = e.eventMap) ? void 0 : _e_eventMap[`${eventType}:${eventName}`]) {
|
|
120
|
+
if (e.eventMap?.[`${eventType}:${eventName}`]) {
|
|
122
121
|
e.removeEventListener(`${eventType}:${eventName}`, e.eventMap[`${eventType}:${eventName}`]);
|
|
123
122
|
delete e.eventMap[`${eventType}:${eventName}`];
|
|
124
123
|
}
|
|
@@ -144,8 +143,7 @@ const initElementTree = ()=>{
|
|
|
144
143
|
});
|
|
145
144
|
}
|
|
146
145
|
__GetEvent(e, eventType, eventName) {
|
|
147
|
-
|
|
148
|
-
const jsFunction = null == (_e_eventMap = e.eventMap) ? void 0 : _e_eventMap[`${eventType}:${eventName}`];
|
|
146
|
+
const jsFunction = e.eventMap?.[`${eventType}:${eventName}`];
|
|
149
147
|
if (void 0 !== jsFunction) return {
|
|
150
148
|
type: eventType,
|
|
151
149
|
name: eventName,
|
package/dist/lynx/ElementPAPI.js
CHANGED
|
@@ -89,8 +89,7 @@ const initElementTree = ()=>{
|
|
|
89
89
|
e.setAttribute(key, JSON.stringify(value));
|
|
90
90
|
}
|
|
91
91
|
__AddEvent(e, eventType, eventName, eventHandler) {
|
|
92
|
-
|
|
93
|
-
if (null == (_e_eventMap = e.eventMap) ? void 0 : _e_eventMap[`${eventType}:${eventName}`]) {
|
|
92
|
+
if (e.eventMap?.[`${eventType}:${eventName}`]) {
|
|
94
93
|
e.removeEventListener(`${eventType}:${eventName}`, e.eventMap[`${eventType}:${eventName}`]);
|
|
95
94
|
delete e.eventMap[`${eventType}:${eventName}`];
|
|
96
95
|
}
|
|
@@ -116,8 +115,7 @@ const initElementTree = ()=>{
|
|
|
116
115
|
});
|
|
117
116
|
}
|
|
118
117
|
__GetEvent(e, eventType, eventName) {
|
|
119
|
-
|
|
120
|
-
const jsFunction = null == (_e_eventMap = e.eventMap) ? void 0 : _e_eventMap[`${eventType}:${eventName}`];
|
|
118
|
+
const jsFunction = e.eventMap?.[`${eventType}:${eventName}`];
|
|
121
119
|
if (void 0 !== jsFunction) return {
|
|
122
120
|
type: eventType,
|
|
123
121
|
name: eventName,
|