@lynx-js/react 0.107.0 → 0.108.0
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 +46 -0
- package/README.md +4 -2
- package/package.json +3 -3
- package/refresh/.turbo/turbo-build.log +1 -1
- package/refresh/package.json +1 -1
- package/runtime/lazy/import.js +7 -1
- package/runtime/lepus/index.js +1 -1
- package/runtime/lepus/jsx-dev-runtime/index.js +1 -1
- package/runtime/lib/backgroundSnapshot.d.ts +1 -1
- package/runtime/lib/backgroundSnapshot.js +7 -4
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/document.d.ts +33 -2
- package/runtime/lib/document.js +9 -1
- package/runtime/lib/document.js.map +1 -1
- package/runtime/lib/hydrate.js +2 -1
- package/runtime/lib/hydrate.js.map +1 -1
- package/runtime/lib/lifecycle/delayUnmount.d.ts +1 -1
- package/runtime/lib/lifecycle/delayUnmount.js +1 -4
- package/runtime/lib/lifecycle/delayUnmount.js.map +1 -1
- package/runtime/lib/lifecycle/destroy.js +2 -2
- package/runtime/lib/lifecycle/destroy.js.map +1 -1
- package/runtime/lib/lifecycle/patch/commit.d.ts +21 -3
- package/runtime/lib/lifecycle/patch/commit.js +44 -56
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +5 -0
- package/runtime/lib/lifecycle/patch/snapshotPatch.js +5 -0
- package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.d.ts +5 -0
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js +21 -5
- package/runtime/lib/lifecycle/patch/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/lifecycle/reload.js +9 -4
- package/runtime/lib/lifecycle/reload.js.map +1 -1
- package/runtime/lib/lifecycle/render.d.ts +1 -3
- package/runtime/lib/lifecycle/render.js +4 -6
- package/runtime/lib/lifecycle/render.js.map +1 -1
- package/runtime/lib/list.d.ts +1 -1
- package/runtime/lib/list.js +60 -23
- package/runtime/lib/list.js.map +1 -1
- package/runtime/lib/lynx/env.d.ts +1 -1
- package/runtime/lib/lynx/env.js +1 -1
- package/runtime/lib/lynx/env.js.map +1 -1
- package/runtime/lib/lynx/performance.js +7 -1
- package/runtime/lib/lynx/performance.js.map +1 -1
- package/runtime/lib/lynx/runWithForce.js +12 -4
- package/runtime/lib/lynx/runWithForce.js.map +1 -1
- package/runtime/lib/lynx/tt.js +6 -8
- package/runtime/lib/lynx/tt.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +4 -4
- package/runtime/lib/lynx-api.js +5 -5
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +6 -5
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/opcodes.js +2 -2
- package/runtime/lib/opcodes.js.map +1 -1
- package/runtime/lib/renderToOpcodes/index.js +5 -1
- package/runtime/lib/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/root.d.ts +4 -0
- package/runtime/lib/root.js +6 -2
- package/runtime/lib/root.js.map +1 -1
- package/runtime/lib/snapshot/ref.d.ts +1 -1
- package/runtime/lib/snapshot/ref.js +1 -1
- package/runtime/lib/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/spread.d.ts +8 -2
- package/runtime/lib/snapshot/spread.js +12 -6
- package/runtime/lib/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot.d.ts +31 -5
- package/runtime/lib/snapshot.js +15 -3
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/src/backgroundSnapshot.ts +20 -13
- package/runtime/src/document.ts +33 -2
- package/runtime/src/hydrate.ts +3 -1
- package/runtime/src/lifecycle/delayUnmount.ts +2 -2
- package/runtime/src/lifecycle/destroy.ts +3 -2
- package/runtime/src/lifecycle/patch/commit.ts +75 -72
- package/runtime/src/lifecycle/patch/snapshotPatch.ts +9 -0
- package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +20 -5
- package/runtime/src/lifecycle/reload.ts +12 -4
- package/runtime/src/lifecycle/render.ts +6 -8
- package/runtime/src/list.ts +71 -23
- package/runtime/src/lynx/env.ts +1 -1
- package/runtime/src/lynx/performance.ts +6 -1
- package/runtime/src/lynx/runWithForce.ts +17 -6
- package/runtime/src/lynx/tt.ts +10 -17
- package/runtime/src/lynx-api.ts +7 -7
- package/runtime/src/lynx.ts +7 -6
- package/runtime/src/opcodes.ts +2 -2
- package/runtime/src/renderToOpcodes/index.ts +6 -1
- package/runtime/src/root.ts +6 -2
- package/runtime/src/snapshot/ref.ts +5 -5
- package/runtime/src/snapshot/spread.ts +14 -6
- package/runtime/src/snapshot.ts +35 -10
- package/testing-library/README.md +1 -1
- package/testing-library/dist/env/vitest.js +23 -23
- package/testing-library/dist/index.d.ts +24 -24
- package/testing-library/dist/index.js +2 -2
- package/testing-library/dist/pure.js +13 -15
- package/testing-library/dist/vitest-global-setup.js +13 -14
- package/testing-library/types/entry.d.ts +2 -2
- package/testing-library/types/index.d.ts +3 -3
- package/transform/dist/wasm.cjs +1 -1
|
@@ -41,11 +41,11 @@ const initElementTree = ()=>{
|
|
|
41
41
|
__CreatePage(_tag, parentComponentUniqueId) {
|
|
42
42
|
const page = this.__CreateElement('page', parentComponentUniqueId);
|
|
43
43
|
this.root = page;
|
|
44
|
-
|
|
44
|
+
lynxTestingEnv.jsdom.window.document.body.appendChild(page);
|
|
45
45
|
return page;
|
|
46
46
|
}
|
|
47
47
|
__CreateRawText(text) {
|
|
48
|
-
const element =
|
|
48
|
+
const element = lynxTestingEnv.jsdom.window.document.createTextNode(text);
|
|
49
49
|
this.countElement(element, 0);
|
|
50
50
|
return element;
|
|
51
51
|
}
|
|
@@ -57,7 +57,7 @@ const initElementTree = ()=>{
|
|
|
57
57
|
}
|
|
58
58
|
__CreateElement(tag, parentComponentUniqueId) {
|
|
59
59
|
if ('raw-text' === tag) return this.__CreateRawText('');
|
|
60
|
-
const element =
|
|
60
|
+
const element = lynxTestingEnv.jsdom.window.document.createElement(tag);
|
|
61
61
|
this.countElement(element, parentComponentUniqueId);
|
|
62
62
|
return element;
|
|
63
63
|
}
|
|
@@ -120,11 +120,11 @@ const initElementTree = ()=>{
|
|
|
120
120
|
const listener = (evt)=>{
|
|
121
121
|
if ('object' == typeof eventHandler && 'worklet' === eventHandler['type']) {
|
|
122
122
|
const isBackground = !__MAIN_THREAD__;
|
|
123
|
-
globalThis.
|
|
123
|
+
globalThis.lynxTestingEnv.switchToMainThread();
|
|
124
124
|
runWorklet(eventHandler.value, [
|
|
125
125
|
Object.assign({}, evt)
|
|
126
126
|
]);
|
|
127
|
-
if (isBackground) globalThis.
|
|
127
|
+
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
128
128
|
} else {
|
|
129
129
|
if ('catchEvent' === eventType || 'capture-catch' === eventType) evt.stopPropagation();
|
|
130
130
|
globalThis.lynxCoreInject.tt.publishEvent(eventHandler, evt);
|
|
@@ -269,9 +269,9 @@ function __injectElementApi(target) {
|
|
|
269
269
|
};
|
|
270
270
|
target.__OnLifecycleEvent = (...args)=>{
|
|
271
271
|
const isMainThread = __MAIN_THREAD__;
|
|
272
|
-
globalThis.
|
|
272
|
+
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
273
273
|
globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
|
|
274
|
-
if (isMainThread) globalThis.
|
|
274
|
+
if (isMainThread) globalThis.lynxTestingEnv.switchToMainThread();
|
|
275
275
|
};
|
|
276
276
|
target._ReportError = ()=>{};
|
|
277
277
|
}
|
|
@@ -279,12 +279,12 @@ function createPolyfills() {
|
|
|
279
279
|
const app = {
|
|
280
280
|
callLepusMethod: (...rLynxChange)=>{
|
|
281
281
|
const isBackground = !__MAIN_THREAD__;
|
|
282
|
-
globalThis.
|
|
282
|
+
globalThis.lynxTestingEnv.switchToMainThread();
|
|
283
283
|
globalThis[rLynxChange[0]](rLynxChange[1]);
|
|
284
|
-
globalThis.
|
|
284
|
+
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
285
285
|
rLynxChange[2]();
|
|
286
|
-
globalThis.
|
|
287
|
-
if (isBackground) globalThis.
|
|
286
|
+
globalThis.lynxTestingEnv.switchToMainThread();
|
|
287
|
+
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
288
288
|
},
|
|
289
289
|
markTiming: ()=>{},
|
|
290
290
|
createJSObjectDestructionObserver: ()=>({})
|
|
@@ -324,11 +324,11 @@ function createPolyfills() {
|
|
|
324
324
|
const ee = new __WEBPACK_EXTERNAL_MODULE_events__["default"]();
|
|
325
325
|
ee.dispatchEvent = ({ type, data })=>{
|
|
326
326
|
const isMainThread = __MAIN_THREAD__;
|
|
327
|
-
|
|
327
|
+
lynxTestingEnv.switchToBackgroundThread();
|
|
328
328
|
ee.emit(type, {
|
|
329
329
|
data: data
|
|
330
330
|
});
|
|
331
|
-
if (isMainThread)
|
|
331
|
+
if (isMainThread) lynxTestingEnv.switchToMainThread();
|
|
332
332
|
};
|
|
333
333
|
ee.addEventListener = ee.addListener;
|
|
334
334
|
ee.removeEventListener = ee.removeListener;
|
|
@@ -336,14 +336,14 @@ function createPolyfills() {
|
|
|
336
336
|
const JsContext = ee;
|
|
337
337
|
function __LoadLepusChunk(chunkName, options) {
|
|
338
338
|
const isBackground = !__MAIN_THREAD__;
|
|
339
|
-
globalThis.
|
|
339
|
+
globalThis.lynxTestingEnv.switchToMainThread();
|
|
340
340
|
if (process.env['DEBUG']) console.log('__LoadLepusChunk', chunkName, options);
|
|
341
341
|
let ans;
|
|
342
342
|
if ('worklet-runtime' === chunkName) {
|
|
343
343
|
var _globalThis_onInitWorkletRuntime, _globalThis;
|
|
344
344
|
ans = null == (_globalThis_onInitWorkletRuntime = (_globalThis = globalThis).onInitWorkletRuntime) ? void 0 : _globalThis_onInitWorkletRuntime.call(_globalThis);
|
|
345
345
|
} else throw new Error(`__LoadLepusChunk: Unknown chunk name: ${chunkName}`);
|
|
346
|
-
if (isBackground) globalThis.
|
|
346
|
+
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
347
347
|
return ans;
|
|
348
348
|
}
|
|
349
349
|
return {
|
|
@@ -467,7 +467,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
|
|
|
467
467
|
target.__LoadLepusChunk = __LoadLepusChunk;
|
|
468
468
|
null == (_globalThis_onInjectBackgroundThreadGlobals = (_globalThis = globalThis).onInjectBackgroundThreadGlobals) || _globalThis_onInjectBackgroundThreadGlobals.call(_globalThis, target);
|
|
469
469
|
}
|
|
470
|
-
class
|
|
470
|
+
class LynxTestingEnv {
|
|
471
471
|
injectGlobals() {
|
|
472
472
|
const polyfills = createPolyfills();
|
|
473
473
|
injectBackgroundThreadGlobals(this.backgroundThread.globalThis, polyfills);
|
|
@@ -500,12 +500,12 @@ class LynxEnv {
|
|
|
500
500
|
});
|
|
501
501
|
null == (_this_originals1 = this.originals) || _this_originals1.clear();
|
|
502
502
|
}
|
|
503
|
-
|
|
504
|
-
var
|
|
503
|
+
reset() {
|
|
504
|
+
var _globalThis_onResetLynxTestingEnv, _globalThis;
|
|
505
505
|
this.injectGlobals();
|
|
506
506
|
this.switchToMainThread();
|
|
507
507
|
this.switchToBackgroundThread();
|
|
508
|
-
null == (
|
|
508
|
+
null == (_globalThis_onResetLynxTestingEnv = (_globalThis = globalThis).onResetLynxTestingEnv) || _globalThis_onResetLynxTestingEnv.call(_globalThis);
|
|
509
509
|
}
|
|
510
510
|
constructor(){
|
|
511
511
|
dist_define_property(this, "originals", new Map());
|
|
@@ -527,17 +527,17 @@ class LynxEnv {
|
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
const env = {
|
|
530
|
-
name: '
|
|
530
|
+
name: 'lynxTestingEnv',
|
|
531
531
|
transformMode: 'web',
|
|
532
532
|
async setup (global1) {
|
|
533
533
|
const fakeGlobal = {};
|
|
534
534
|
await __WEBPACK_EXTERNAL_MODULE_vitest_environments_fd1a84b1__.builtinEnvironments.jsdom.setup(fakeGlobal, {});
|
|
535
535
|
global1.jsdom = fakeGlobal.jsdom;
|
|
536
|
-
const
|
|
537
|
-
global1.
|
|
536
|
+
const lynxTestingEnv1 = new LynxTestingEnv();
|
|
537
|
+
global1.lynxTestingEnv = lynxTestingEnv1;
|
|
538
538
|
return {
|
|
539
539
|
teardown (global1) {
|
|
540
|
-
delete global1.
|
|
540
|
+
delete global1.lynxTestingEnv;
|
|
541
541
|
delete global1.jsdom;
|
|
542
542
|
}
|
|
543
543
|
};
|
|
@@ -831,6 +831,19 @@ declare interface LynxElement extends HTMLElement {
|
|
|
831
831
|
parentNode: LynxElement;
|
|
832
832
|
}
|
|
833
833
|
|
|
834
|
+
/**
|
|
835
|
+
* The `globalThis` object of Lynx dual thread environment.
|
|
836
|
+
*
|
|
837
|
+
* @public
|
|
838
|
+
*/
|
|
839
|
+
declare interface LynxGlobalThis {
|
|
840
|
+
/**
|
|
841
|
+
* The globalThis object.
|
|
842
|
+
*/
|
|
843
|
+
globalThis: LynxGlobalThis;
|
|
844
|
+
[key: string]: any;
|
|
845
|
+
}
|
|
846
|
+
|
|
834
847
|
/**
|
|
835
848
|
* A pure-JavaScript implementation of the {@link https://lynxjs.org/guide/spec.html | Lynx Spec},
|
|
836
849
|
* notably the {@link https://lynxjs.org/api/engine/element-api | Element PAPI} and {@link https://lynxjs.org/guide/spec#dual-threaded-model | Dual-threaded Model} for use with Node.js.
|
|
@@ -838,11 +851,11 @@ declare interface LynxElement extends HTMLElement {
|
|
|
838
851
|
* @example
|
|
839
852
|
*
|
|
840
853
|
* ```ts
|
|
841
|
-
* import {
|
|
854
|
+
* import { LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
842
855
|
*
|
|
843
|
-
* const
|
|
856
|
+
* const lynxTestingEnv = new LynxTestingEnv();
|
|
844
857
|
*
|
|
845
|
-
*
|
|
858
|
+
* lynxTestingEnv.switchToMainThread();
|
|
846
859
|
* // use the main thread Element PAPI
|
|
847
860
|
* const page = __CreatePage('0', 0);
|
|
848
861
|
* const view = __CreateView(0);
|
|
@@ -852,7 +865,7 @@ declare interface LynxElement extends HTMLElement {
|
|
|
852
865
|
*
|
|
853
866
|
* @public
|
|
854
867
|
*/
|
|
855
|
-
export declare class
|
|
868
|
+
export declare class LynxTestingEnv {
|
|
856
869
|
private originals;
|
|
857
870
|
/**
|
|
858
871
|
* The global object for the background thread.
|
|
@@ -860,11 +873,11 @@ export declare class LynxEnv {
|
|
|
860
873
|
* @example
|
|
861
874
|
*
|
|
862
875
|
* ```ts
|
|
863
|
-
* import {
|
|
876
|
+
* import { LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
864
877
|
*
|
|
865
|
-
* const
|
|
878
|
+
* const lynxTestingEnv = new LynxTestingEnv();
|
|
866
879
|
*
|
|
867
|
-
*
|
|
880
|
+
* lynxTestingEnv.switchToBackgroundThread();
|
|
868
881
|
* // use the background thread global object
|
|
869
882
|
* globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
|
|
870
883
|
* ```
|
|
@@ -876,11 +889,11 @@ export declare class LynxEnv {
|
|
|
876
889
|
* @example
|
|
877
890
|
*
|
|
878
891
|
* ```ts
|
|
879
|
-
* import {
|
|
892
|
+
* import { LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
880
893
|
*
|
|
881
|
-
* const
|
|
894
|
+
* const lynxTestingEnv = new LynxTestingEnv();
|
|
882
895
|
*
|
|
883
|
-
*
|
|
896
|
+
* lynxTestingEnv.switchToMainThread();
|
|
884
897
|
* // use the main thread global object
|
|
885
898
|
* const page = globalThis.__CreatePage('0', 0);
|
|
886
899
|
* const view = globalThis.__CreateView(0);
|
|
@@ -894,20 +907,7 @@ export declare class LynxEnv {
|
|
|
894
907
|
switchToBackgroundThread(): void;
|
|
895
908
|
switchToMainThread(): void;
|
|
896
909
|
clearGlobal(): void;
|
|
897
|
-
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
/**
|
|
901
|
-
* The `globalThis` object of Lynx dual thread environment.
|
|
902
|
-
*
|
|
903
|
-
* @public
|
|
904
|
-
*/
|
|
905
|
-
declare interface LynxGlobalThis {
|
|
906
|
-
/**
|
|
907
|
-
* The globalThis object.
|
|
908
|
-
*/
|
|
909
|
-
globalThis: LynxGlobalThis;
|
|
910
|
-
[key: string]: any;
|
|
910
|
+
reset(): void;
|
|
911
911
|
}
|
|
912
912
|
|
|
913
913
|
export declare type Match = (
|
|
@@ -3,10 +3,10 @@ export * from "./pure.js";
|
|
|
3
3
|
if ('undefined' == typeof process || 'true' !== process.env.PTL_SKIP_AUTO_CLEANUP) {
|
|
4
4
|
if ('function' == typeof afterEach) afterEach(()=>{
|
|
5
5
|
(0, __WEBPACK_EXTERNAL_MODULE__pure_js_8326ae41__.cleanup)();
|
|
6
|
-
|
|
6
|
+
lynxTestingEnv.reset();
|
|
7
7
|
});
|
|
8
8
|
else if ('function' == typeof teardown) teardown(()=>{
|
|
9
9
|
(0, __WEBPACK_EXTERNAL_MODULE__pure_js_8326ae41__.cleanup)();
|
|
10
|
-
|
|
10
|
+
lynxTestingEnv.reset();
|
|
11
11
|
});
|
|
12
12
|
}
|
|
@@ -6,7 +6,6 @@ import * as __WEBPACK_EXTERNAL_MODULE_preact_test_utils_c2734169__ from "preact/
|
|
|
6
6
|
import * as __WEBPACK_EXTERNAL_MODULE__lynx_js_react_internal_08331b1f__ from "@lynx-js/react/internal";
|
|
7
7
|
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__ from "../../runtime/lib/lynx/tt.js";
|
|
8
8
|
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__ from "../../runtime/lib/snapshot.js";
|
|
9
|
-
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__ from "../../runtime/lib/lifecycle/patch/commit.js";
|
|
10
9
|
var __webpack_modules__ = {
|
|
11
10
|
"../../../node_modules/.pnpm/@testing-library+dom@10.4.0/node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js": function(module, __webpack_exports__, __webpack_require__) {
|
|
12
11
|
__webpack_require__.d(__webpack_exports__, {
|
|
@@ -14422,10 +14421,10 @@ function getElement(elemOrNodesRef) {
|
|
|
14422
14421
|
}
|
|
14423
14422
|
const fireEvent = (elemOrNodesRef, ...args)=>{
|
|
14424
14423
|
const isMainThread = __MAIN_THREAD__;
|
|
14425
|
-
|
|
14424
|
+
lynxTestingEnv.switchToBackgroundThread();
|
|
14426
14425
|
const elem = getElement(elemOrNodesRef);
|
|
14427
14426
|
let ans = (0, dom_esm.BX)(elem, ...args);
|
|
14428
|
-
if (isMainThread)
|
|
14427
|
+
if (isMainThread) lynxTestingEnv.switchToMainThread();
|
|
14429
14428
|
return ans;
|
|
14430
14429
|
};
|
|
14431
14430
|
const eventMap = {
|
|
@@ -14541,7 +14540,7 @@ const eventMap = {
|
|
|
14541
14540
|
Object.keys(eventMap).forEach((key)=>{
|
|
14542
14541
|
fireEvent[key] = (elemOrNodesRef, init = {})=>{
|
|
14543
14542
|
const isMainThread = __MAIN_THREAD__;
|
|
14544
|
-
|
|
14543
|
+
lynxTestingEnv.switchToBackgroundThread();
|
|
14545
14544
|
const elem = getElement(elemOrNodesRef);
|
|
14546
14545
|
const eventType = init?.['eventType'] || 'bindEvent';
|
|
14547
14546
|
init = {
|
|
@@ -14553,7 +14552,7 @@ Object.keys(eventMap).forEach((key)=>{
|
|
|
14553
14552
|
const event = (0, dom_esm.yM)(`${eventType}:${key}`, elem, init);
|
|
14554
14553
|
Object.assign(event, init);
|
|
14555
14554
|
const ans = (0, dom_esm.BX)(elem, event);
|
|
14556
|
-
if (isMainThread)
|
|
14555
|
+
if (isMainThread) lynxTestingEnv.switchToMainThread();
|
|
14557
14556
|
return ans;
|
|
14558
14557
|
};
|
|
14559
14558
|
});
|
|
@@ -14586,21 +14585,21 @@ function render(ui, { queries, wrapper: WrapperComponent, enableMainThread = fal
|
|
|
14586
14585
|
const comp = wrapUiIfNeeded(ui);
|
|
14587
14586
|
const compMainThread = (0, __WEBPACK_EXTERNAL_MODULE_preact__.cloneElement)(comp);
|
|
14588
14587
|
const compBackgroundThread = (0, __WEBPACK_EXTERNAL_MODULE_preact__.cloneElement)(comp);
|
|
14589
|
-
globalThis.
|
|
14588
|
+
globalThis.lynxTestingEnv.switchToMainThread();
|
|
14590
14589
|
__WEBPACK_EXTERNAL_MODULE__lynx_js_react_internal_08331b1f__.__root.__jsx = enableMainThread ? compMainThread : null;
|
|
14591
14590
|
renderPage();
|
|
14592
14591
|
if (enableBackgroundThread) {
|
|
14593
|
-
globalThis.
|
|
14592
|
+
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
14594
14593
|
(0, __WEBPACK_EXTERNAL_MODULE_preact_test_utils_c2734169__.act)(()=>{
|
|
14595
14594
|
(0, __WEBPACK_EXTERNAL_MODULE_preact__.render)(compBackgroundThread, __WEBPACK_EXTERNAL_MODULE__lynx_js_react_internal_08331b1f__.__root);
|
|
14596
14595
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__.flushDelayedLifecycleEvents)();
|
|
14597
14596
|
});
|
|
14598
14597
|
}
|
|
14599
14598
|
return {
|
|
14600
|
-
container:
|
|
14599
|
+
container: lynxTestingEnv.mainThread.elementTree.root,
|
|
14601
14600
|
unmount: cleanup,
|
|
14602
14601
|
rerender: (rerenderUi)=>{
|
|
14603
|
-
|
|
14602
|
+
lynxTestingEnv.reset();
|
|
14604
14603
|
return render(wrapUiIfNeeded(rerenderUi), {
|
|
14605
14604
|
queries,
|
|
14606
14605
|
wrapper: WrapperComponent,
|
|
@@ -14608,20 +14607,19 @@ function render(ui, { queries, wrapper: WrapperComponent, enableMainThread = fal
|
|
|
14608
14607
|
enableBackgroundThread
|
|
14609
14608
|
});
|
|
14610
14609
|
},
|
|
14611
|
-
...(0, dom_esm.W2)(
|
|
14610
|
+
...(0, dom_esm.W2)(lynxTestingEnv.mainThread.elementTree.root, queries)
|
|
14612
14611
|
};
|
|
14613
14612
|
}
|
|
14614
14613
|
function cleanup() {
|
|
14615
14614
|
const isMainThread = __MAIN_THREAD__;
|
|
14616
|
-
globalThis.
|
|
14615
|
+
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
14617
14616
|
(0, __WEBPACK_EXTERNAL_MODULE_preact_test_utils_c2734169__.act)(()=>{
|
|
14618
14617
|
(0, __WEBPACK_EXTERNAL_MODULE_preact__.render)(null, __WEBPACK_EXTERNAL_MODULE__lynx_js_react_internal_08331b1f__.__root);
|
|
14619
|
-
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__.commitToMainThread)();
|
|
14620
14618
|
});
|
|
14621
|
-
|
|
14619
|
+
lynxTestingEnv.mainThread.elementTree.root = void 0;
|
|
14622
14620
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.clearPage)();
|
|
14623
|
-
|
|
14624
|
-
if (isMainThread) globalThis.
|
|
14621
|
+
lynxTestingEnv.jsdom.window.document.body.innerHTML = '';
|
|
14622
|
+
if (isMainThread) globalThis.lynxTestingEnv.switchToMainThread();
|
|
14625
14623
|
}
|
|
14626
14624
|
function renderHook(renderCallback, options) {
|
|
14627
14625
|
const { initialProps, wrapper } = options || {};
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE_preact__ from "preact";
|
|
2
|
-
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__ from "../../runtime/lib/snapshot.js";
|
|
3
2
|
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_backgroundSnapshot_js_d70e0888__ from "../../runtime/lib/backgroundSnapshot.js";
|
|
4
|
-
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_calledByNative_js_f689039d__ from "../../runtime/lib/lynx/calledByNative.js";
|
|
5
|
-
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_updateMainThread_js_dca3a751__ from "../../runtime/lib/lifecycle/patch/updateMainThread.js";
|
|
6
3
|
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__ from "../../runtime/lib/lifecycle/patch/commit.js";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_snapshotPatch_js_c1ebb33c__ from "../../runtime/lib/lifecycle/patch/snapshotPatch.js";
|
|
5
|
+
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_updateMainThread_js_dca3a751__ from "../../runtime/lib/lifecycle/patch/updateMainThread.js";
|
|
6
|
+
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_calledByNative_js_f689039d__ from "../../runtime/lib/lynx/calledByNative.js";
|
|
7
7
|
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__ from "../../runtime/lib/lynx/tt.js";
|
|
8
8
|
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_root_js_27522aef__ from "../../runtime/lib/root.js";
|
|
9
|
-
import * as
|
|
9
|
+
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__ from "../../runtime/lib/snapshot.js";
|
|
10
|
+
import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_worklet_destroy_js_8a273fd1__ from "../../runtime/lib/worklet/destroy.js";
|
|
10
11
|
import * as __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_api_lynxApi_js_c6dc2d67__ from "../../worklet-runtime/lib/api/lynxApi.js";
|
|
11
12
|
import * as __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_listeners_js_9f7cd330__ from "../../worklet-runtime/lib/listeners.js";
|
|
12
13
|
import * as __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_workletRuntime_js_e9debbe1__ from "../../worklet-runtime/lib/workletRuntime.js";
|
|
13
|
-
|
|
14
|
-
const { onInjectMainThreadGlobals, onInjectBackgroundThreadGlobals, onResetLynxEnv, onSwitchedToMainThread, onSwitchedToBackgroundThread, onInitWorkletRuntime } = globalThis;
|
|
14
|
+
const { onInjectMainThreadGlobals, onInjectBackgroundThreadGlobals, onResetLynxTestingEnv, onSwitchedToMainThread, onSwitchedToBackgroundThread, onInitWorkletRuntime } = globalThis;
|
|
15
15
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_calledByNative_js_f689039d__.injectCalledByNative)();
|
|
16
16
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_updateMainThread_js_dca3a751__.injectUpdateMainThread)();
|
|
17
17
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__.replaceCommitHook)();
|
|
@@ -87,17 +87,16 @@ globalThis.onInjectBackgroundThreadGlobals = (target)=>{
|
|
|
87
87
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__.injectTt)();
|
|
88
88
|
globalThis.lynxCoreInject = oldLynxCoreInject;
|
|
89
89
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_snapshotPatch_js_c1ebb33c__.deinitGlobalSnapshotPatch)();
|
|
90
|
-
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__.clearPatchesToCommit)();
|
|
91
90
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__.clearCommitTaskId)();
|
|
92
91
|
};
|
|
93
|
-
globalThis.
|
|
94
|
-
if (
|
|
95
|
-
if (process.env.DEBUG) console.log('
|
|
92
|
+
globalThis.onResetLynxTestingEnv = ()=>{
|
|
93
|
+
if (onResetLynxTestingEnv) onResetLynxTestingEnv();
|
|
94
|
+
if (process.env.DEBUG) console.log('onResetLynxTestingEnv');
|
|
96
95
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__.flushDelayedLifecycleEvents)();
|
|
97
96
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_worklet_destroy_js_8a273fd1__.destroyWorklet)();
|
|
98
|
-
|
|
97
|
+
lynxTestingEnv.switchToMainThread();
|
|
99
98
|
(0, __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_listeners_js_9f7cd330__.initEventListeners)();
|
|
100
|
-
|
|
99
|
+
lynxTestingEnv.switchToBackgroundThread();
|
|
101
100
|
};
|
|
102
101
|
globalThis.onSwitchedToMainThread = ()=>{
|
|
103
102
|
if (onSwitchedToMainThread) onSwitchedToMainThread();
|
|
@@ -111,5 +110,5 @@ globalThis.onSwitchedToBackgroundThread = ()=>{
|
|
|
111
110
|
(0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_root_js_27522aef__.setRoot)(globalThis.__root);
|
|
112
111
|
__WEBPACK_EXTERNAL_MODULE_preact__.options.document = globalThis._document;
|
|
113
112
|
};
|
|
114
|
-
globalThis.onInjectMainThreadGlobals(globalThis.
|
|
115
|
-
globalThis.onInjectBackgroundThreadGlobals(globalThis.
|
|
113
|
+
globalThis.onInjectMainThreadGlobals(globalThis.lynxTestingEnv.mainThread.globalThis);
|
|
114
|
+
globalThis.onInjectBackgroundThreadGlobals(globalThis.lynxTestingEnv.backgroundThread.globalThis);
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { queries, Queries, BoundFunction } from '@testing-library/dom';
|
|
11
|
-
import { LynxElement, type ElementTree, type
|
|
11
|
+
import { LynxElement, type ElementTree, type LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
12
12
|
import { ComponentChild, ComponentType } from 'preact';
|
|
13
13
|
export * from '@testing-library/dom';
|
|
14
|
-
export { ElementTree,
|
|
14
|
+
export { ElementTree, LynxTestingEnv };
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* The options for {@link render}.
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
export * from '../dist/index.d.ts';
|
|
3
|
-
import { ElementTree,
|
|
3
|
+
import { ElementTree, LynxTestingEnv } from '../dist/index.d.ts';
|
|
4
4
|
|
|
5
5
|
declare global {
|
|
6
|
-
var
|
|
6
|
+
var lynxTestingEnv: LynxTestingEnv;
|
|
7
7
|
var elementTree: ElementTree;
|
|
8
8
|
|
|
9
9
|
function onInjectBackgroundThreadGlobals(globals: any): void;
|
|
10
10
|
function onInjectMainThreadGlobals(globals: any): void;
|
|
11
11
|
function onSwitchedToBackgroundThread(): void;
|
|
12
12
|
function onSwitchedToMainThread(): void;
|
|
13
|
-
function
|
|
13
|
+
function onResetLynxTestingEnv(): void;
|
|
14
14
|
function onInitWorkletRuntime(): void;
|
|
15
15
|
}
|