@lynx-js/react 0.117.1 → 0.119.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.
Files changed (217) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/package.json +37 -15
  3. package/refresh/.turbo/turbo-build.log +1 -1
  4. package/runtime/lib/alog/elementPAPICall.js +1 -0
  5. package/runtime/lib/alog/elementPAPICall.js.map +1 -1
  6. package/runtime/lib/debug/component-stack.d.ts +0 -6
  7. package/runtime/lib/debug/component-stack.js.map +1 -1
  8. package/runtime/lib/debug/profile.js +1 -2
  9. package/runtime/lib/debug/profile.js.map +1 -1
  10. package/runtime/lib/gesture/processGesture.js +103 -11
  11. package/runtime/lib/gesture/processGesture.js.map +1 -1
  12. package/runtime/lib/hooks/mainThread.d.ts +17 -0
  13. package/runtime/lib/hooks/mainThread.js +152 -0
  14. package/runtime/lib/hooks/mainThread.js.map +1 -0
  15. package/runtime/lib/hooks/react.js +3 -3
  16. package/runtime/lib/hooks/react.js.map +1 -1
  17. package/runtime/lib/{lifecycleConstant.js → lifecycle/constant.js} +1 -1
  18. package/runtime/lib/lifecycle/constant.js.map +1 -0
  19. package/runtime/lib/lifecycle/event/delayLifecycleEvents.d.ts +1 -1
  20. package/runtime/lib/lifecycle/event/jsReady.js +4 -2
  21. package/runtime/lib/lifecycle/event/jsReady.js.map +1 -1
  22. package/runtime/lib/lifecycle/patch/commit.js +1 -1
  23. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  24. package/runtime/lib/lifecycle/patch/updateMainThread.js +2 -2
  25. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  26. package/runtime/lib/lifecycle/reload.js +8 -8
  27. package/runtime/lib/lifecycle/reload.js.map +1 -1
  28. package/runtime/lib/lifecycle/render.js +2 -20
  29. package/runtime/lib/lifecycle/render.js.map +1 -1
  30. package/runtime/lib/{list.d.ts → list/list.d.ts} +1 -1
  31. package/runtime/lib/{list.js → list/list.js} +3 -3
  32. package/runtime/lib/list/list.js.map +1 -0
  33. package/runtime/lib/{listUpdateInfo.d.ts → list/listUpdateInfo.d.ts} +1 -1
  34. package/runtime/lib/{listUpdateInfo.js → list/listUpdateInfo.js} +2 -2
  35. package/runtime/lib/list/listUpdateInfo.js.map +1 -0
  36. package/runtime/lib/list/pendingListUpdates.js.map +1 -0
  37. package/runtime/lib/lynx/calledByNative.js +5 -5
  38. package/runtime/lib/lynx/calledByNative.js.map +1 -1
  39. package/runtime/lib/lynx/suspense.js +2 -2
  40. package/runtime/lib/lynx/suspense.js.map +1 -1
  41. package/runtime/lib/lynx/tt.js +1 -1
  42. package/runtime/lib/lynx/tt.js.map +1 -1
  43. package/runtime/lib/lynx-api.js +1 -1
  44. package/runtime/lib/lynx-api.js.map +1 -1
  45. package/runtime/lib/renderToOpcodes/constants.d.ts +1 -0
  46. package/runtime/lib/renderToOpcodes/constants.js +1 -0
  47. package/runtime/lib/renderToOpcodes/constants.js.map +1 -1
  48. package/runtime/lib/{hydrate.d.ts → renderToOpcodes/hydrate.d.ts} +2 -2
  49. package/runtime/lib/{hydrate.js → renderToOpcodes/hydrate.js} +6 -6
  50. package/runtime/lib/renderToOpcodes/hydrate.js.map +1 -0
  51. package/runtime/lib/renderToOpcodes/index.d.ts +2 -1
  52. package/runtime/lib/renderToOpcodes/index.js +82 -25
  53. package/runtime/lib/renderToOpcodes/index.js.map +1 -1
  54. package/runtime/lib/{opcodes.d.ts → renderToOpcodes/opcodes.d.ts} +1 -2
  55. package/runtime/lib/{opcodes.js → renderToOpcodes/opcodes.js} +54 -54
  56. package/runtime/lib/renderToOpcodes/opcodes.js.map +1 -0
  57. package/runtime/lib/snapshot/backgroundSnapshot.js +4 -4
  58. package/runtime/lib/snapshot/backgroundSnapshot.js.map +1 -1
  59. package/runtime/lib/snapshot/list.js +2 -2
  60. package/runtime/lib/snapshot/list.js.map +1 -1
  61. package/runtime/lib/snapshot/platformInfo.js +2 -2
  62. package/runtime/lib/snapshot/platformInfo.js.map +1 -1
  63. package/runtime/lib/snapshot/snapshot.d.ts +1 -0
  64. package/runtime/lib/snapshot/snapshot.js +17 -4
  65. package/runtime/lib/snapshot/snapshot.js.map +1 -1
  66. package/runtime/lib/snapshot/spread.js +2 -2
  67. package/runtime/lib/snapshot/spread.js.map +1 -1
  68. package/runtime/lib/tsconfig.tsbuildinfo +1 -0
  69. package/runtime/lib/utils.d.ts +1 -0
  70. package/runtime/lib/utils.js +3 -0
  71. package/runtime/lib/utils.js.map +1 -1
  72. package/runtime/lib/worklet/ref/updateInitValue.js +1 -1
  73. package/runtime/lib/worklet/ref/updateInitValue.js.map +1 -1
  74. package/runtime/lib/worklet-runtime/api/animation/animation.js.map +1 -0
  75. package/runtime/lib/worklet-runtime/api/animation/effect.js.map +1 -0
  76. package/runtime/lib/worklet-runtime/api/element.js.map +1 -0
  77. package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/lepusQuerySelector.js +10 -2
  78. package/runtime/lib/worklet-runtime/api/lepusQuerySelector.js.map +1 -0
  79. package/runtime/lib/worklet-runtime/api/lynxApi.js.map +1 -0
  80. package/runtime/lib/worklet-runtime/bindings/bindings.js.map +1 -0
  81. package/runtime/lib/worklet-runtime/bindings/events.js.map +1 -0
  82. package/runtime/lib/worklet-runtime/bindings/index.js.map +1 -0
  83. package/runtime/lib/worklet-runtime/bindings/loadRuntime.js.map +1 -0
  84. package/runtime/lib/worklet-runtime/bindings/observers.js.map +1 -0
  85. package/runtime/lib/worklet-runtime/bindings/types.js.map +1 -0
  86. package/runtime/lib/worklet-runtime/delayRunOnBackground.js.map +1 -0
  87. package/runtime/lib/worklet-runtime/delayWorkletEvent.js.map +1 -0
  88. package/runtime/lib/worklet-runtime/eomImpl.js.map +1 -0
  89. package/runtime/lib/worklet-runtime/eventPropagation.js.map +1 -0
  90. package/runtime/lib/worklet-runtime/global.js.map +1 -0
  91. package/runtime/lib/worklet-runtime/hydrate.js.map +1 -0
  92. package/runtime/lib/worklet-runtime/index.js.map +1 -0
  93. package/runtime/lib/worklet-runtime/jsFunctionLifecycle.js.map +1 -0
  94. package/runtime/lib/worklet-runtime/listeners.js.map +1 -0
  95. package/runtime/lib/worklet-runtime/runOnMainThread.js.map +1 -0
  96. package/runtime/lib/worklet-runtime/utils/mainThreadFlushLoopGuard.js.map +1 -0
  97. package/runtime/lib/worklet-runtime/utils/profile.js.map +1 -0
  98. package/runtime/lib/worklet-runtime/utils/version.js.map +1 -0
  99. package/runtime/lib/worklet-runtime/workletRef.js.map +1 -0
  100. package/runtime/lib/worklet-runtime/workletRuntime.js.map +1 -0
  101. package/{worklet-runtime/dist → runtime/worklet-runtime}/dev.js +7 -3
  102. package/{worklet-runtime/dist → runtime/worklet-runtime}/main.js +1 -1
  103. package/testing-library/README.md +48 -9
  104. package/testing-library/dist/0~123.js +43 -0
  105. package/testing-library/dist/881.js +1 -0
  106. package/testing-library/dist/entry.d.ts +1 -0
  107. package/testing-library/dist/env/index.d.ts +2 -0
  108. package/testing-library/dist/env/index.js +661 -0
  109. package/testing-library/dist/env/rstest.d.ts +1 -0
  110. package/testing-library/dist/env/rstest.js +6 -0
  111. package/testing-library/dist/env/vitest.d.ts +3 -0
  112. package/testing-library/dist/env/vitest.js +8 -662
  113. package/testing-library/dist/fire-event.d.ts +111 -0
  114. package/testing-library/dist/index.d.ts +18 -6
  115. package/testing-library/dist/plugins/index.d.ts +2 -0
  116. package/testing-library/dist/plugins/index.js +282 -0
  117. package/testing-library/dist/plugins/vitest.d.ts +26 -0
  118. package/testing-library/dist/pure.js +2 -2
  119. package/testing-library/dist/rstest-config.d.ts +25 -0
  120. package/testing-library/dist/rstest-config.js +61 -0
  121. package/testing-library/dist/setupFiles/common/bootstrap.js +2 -0
  122. package/testing-library/dist/{vitest-global-setup.js → setupFiles/common/runtime-setup.js} +25 -39
  123. package/testing-library/dist/setupFiles/inner/rstest.js +7 -0
  124. package/testing-library/dist/setupFiles/inner/vitest.js +11 -0
  125. package/testing-library/dist/setupFiles/rstest.js +21 -0
  126. package/testing-library/dist/setupFiles/vitest.js +20 -0
  127. package/testing-library/dist/vitest.config.d.ts +6 -0
  128. package/testing-library/dist/vitest.config.js +4 -257
  129. package/transform/dist/wasm.cjs +1 -1
  130. package/transform/index.d.ts +37 -1
  131. package/runtime/lib/hydrate.js.map +0 -1
  132. package/runtime/lib/lifecycleConstant.js.map +0 -1
  133. package/runtime/lib/list.js.map +0 -1
  134. package/runtime/lib/listUpdateInfo.js.map +0 -1
  135. package/runtime/lib/opcodes.js.map +0 -1
  136. package/runtime/lib/pendingListUpdates.js.map +0 -1
  137. package/testing-library/types/vitest-config.d.ts +0 -20
  138. package/worklet-runtime/lib/api/animation/animation.js.map +0 -1
  139. package/worklet-runtime/lib/api/animation/effect.js.map +0 -1
  140. package/worklet-runtime/lib/api/element.js.map +0 -1
  141. package/worklet-runtime/lib/api/lepusQuerySelector.js.map +0 -1
  142. package/worklet-runtime/lib/api/lynxApi.js.map +0 -1
  143. package/worklet-runtime/lib/bindings/bindings.js.map +0 -1
  144. package/worklet-runtime/lib/bindings/events.js.map +0 -1
  145. package/worklet-runtime/lib/bindings/index.js.map +0 -1
  146. package/worklet-runtime/lib/bindings/loadRuntime.js.map +0 -1
  147. package/worklet-runtime/lib/bindings/observers.js.map +0 -1
  148. package/worklet-runtime/lib/bindings/types.js.map +0 -1
  149. package/worklet-runtime/lib/delayRunOnBackground.js.map +0 -1
  150. package/worklet-runtime/lib/delayWorkletEvent.js.map +0 -1
  151. package/worklet-runtime/lib/eomImpl.js.map +0 -1
  152. package/worklet-runtime/lib/eventPropagation.js.map +0 -1
  153. package/worklet-runtime/lib/global.js.map +0 -1
  154. package/worklet-runtime/lib/hydrate.js.map +0 -1
  155. package/worklet-runtime/lib/index.js.map +0 -1
  156. package/worklet-runtime/lib/jsFunctionLifecycle.js.map +0 -1
  157. package/worklet-runtime/lib/listeners.js.map +0 -1
  158. package/worklet-runtime/lib/runOnMainThread.js.map +0 -1
  159. package/worklet-runtime/lib/utils/mainThreadFlushLoopGuard.js.map +0 -1
  160. package/worklet-runtime/lib/utils/profile.js.map +0 -1
  161. package/worklet-runtime/lib/utils/version.js.map +0 -1
  162. package/worklet-runtime/lib/workletRef.js.map +0 -1
  163. package/worklet-runtime/lib/workletRuntime.js.map +0 -1
  164. /package/runtime/lib/{lifecycleConstant.d.ts → lifecycle/constant.d.ts} +0 -0
  165. /package/runtime/lib/{pendingListUpdates.d.ts → list/pendingListUpdates.d.ts} +0 -0
  166. /package/runtime/lib/{pendingListUpdates.js → list/pendingListUpdates.js} +0 -0
  167. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/animation/animation.d.ts +0 -0
  168. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/animation/animation.js +0 -0
  169. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/animation/effect.d.ts +0 -0
  170. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/animation/effect.js +0 -0
  171. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/element.d.ts +0 -0
  172. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/element.js +0 -0
  173. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/lepusQuerySelector.d.ts +0 -0
  174. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/lynxApi.d.ts +0 -0
  175. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/api/lynxApi.js +0 -0
  176. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/bindings.d.ts +0 -0
  177. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/bindings.js +0 -0
  178. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/events.d.ts +0 -0
  179. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/events.js +0 -0
  180. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/index.d.ts +0 -0
  181. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/index.js +0 -0
  182. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/loadRuntime.d.ts +0 -0
  183. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/loadRuntime.js +0 -0
  184. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/observers.d.ts +0 -0
  185. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/observers.js +0 -0
  186. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/types.d.ts +0 -0
  187. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/bindings/types.js +0 -0
  188. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/delayRunOnBackground.d.ts +0 -0
  189. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/delayRunOnBackground.js +0 -0
  190. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/delayWorkletEvent.d.ts +0 -0
  191. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/delayWorkletEvent.js +0 -0
  192. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/eomImpl.d.ts +0 -0
  193. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/eomImpl.js +0 -0
  194. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/eventPropagation.d.ts +0 -0
  195. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/eventPropagation.js +0 -0
  196. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/global.d.ts +0 -0
  197. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/global.js +0 -0
  198. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/hydrate.d.ts +0 -0
  199. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/hydrate.js +0 -0
  200. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/index.d.ts +0 -0
  201. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/index.js +0 -0
  202. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/jsFunctionLifecycle.d.ts +0 -0
  203. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/jsFunctionLifecycle.js +0 -0
  204. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/listeners.d.ts +0 -0
  205. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/listeners.js +0 -0
  206. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/runOnMainThread.d.ts +0 -0
  207. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/runOnMainThread.js +0 -0
  208. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/mainThreadFlushLoopGuard.d.ts +0 -0
  209. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/mainThreadFlushLoopGuard.js +0 -0
  210. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/profile.d.ts +0 -0
  211. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/profile.js +0 -0
  212. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/version.d.ts +0 -0
  213. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/utils/version.js +0 -0
  214. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/workletRef.d.ts +0 -0
  215. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/workletRef.js +0 -0
  216. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/workletRuntime.d.ts +0 -0
  217. /package/{worklet-runtime/lib → runtime/lib/worklet-runtime}/workletRuntime.js +0 -0
@@ -1,35 +1,18 @@
1
1
  import { options } from "preact";
2
- import { expect } from "vitest";
3
- import { clearCommitTaskId, replaceCommitHook } from "../../runtime/lib/lifecycle/patch/commit.js";
4
- import { deinitGlobalSnapshotPatch } from "../../runtime/lib/lifecycle/patch/snapshotPatch.js";
5
- import { injectUpdateMainThread } from "../../runtime/lib/lifecycle/patch/updateMainThread.js";
6
- import { injectUpdateMTRefInitValue } from "../../runtime/lib/worklet/ref/updateInitValue.js";
7
- import { injectCalledByNative } from "../../runtime/lib/lynx/calledByNative.js";
8
- import { flushDelayedLifecycleEvents, injectTt } from "../../runtime/lib/lynx/tt.js";
9
- import { initElementPAPICallAlog } from "../../runtime/lib/alog/elementPAPICall.js";
10
- import { addCtxNotFoundEventListener } from "../../runtime/lib/lifecycle/patch/error.js";
11
- import { setRoot } from "../../runtime/lib/root.js";
12
- import { BackgroundSnapshotInstance, SnapshotInstance, backgroundSnapshotInstanceManager, snapshotInstanceManager } from "../../runtime/lib/snapshot/index.js";
13
- import { destroyWorklet } from "../../runtime/lib/worklet/destroy.js";
14
- import { initApiEnv } from "../../worklet-runtime/lib/api/lynxApi.js";
15
- import { initEventListeners } from "../../worklet-runtime/lib/listeners.js";
16
- import { initWorklet } from "../../worklet-runtime/lib/workletRuntime.js";
17
- expect.addSnapshotSerializer({
18
- test (val) {
19
- return Boolean(val && 'object' == typeof val && Array.isArray(val.refAttr) && Object.prototype.hasOwnProperty.call(val, 'task') && 'function' == typeof val.exec);
20
- },
21
- print (val, serialize) {
22
- const printed = serialize({
23
- refAttr: Array.isArray(val.refAttr) ? [
24
- ...val.refAttr
25
- ] : val.refAttr,
26
- task: val.task
27
- });
28
- if (printed.startsWith('Object')) return printed.replace(/^Object/, 'RefProxy');
29
- if (printed.startsWith('{')) return `RefProxy ${printed}`;
30
- return printed;
31
- }
32
- });
2
+ import { clearCommitTaskId, replaceCommitHook } from "../../../../runtime/lib/lifecycle/patch/commit.js";
3
+ import { deinitGlobalSnapshotPatch } from "../../../../runtime/lib/lifecycle/patch/snapshotPatch.js";
4
+ import { injectUpdateMainThread } from "../../../../runtime/lib/lifecycle/patch/updateMainThread.js";
5
+ import { injectUpdateMTRefInitValue } from "../../../../runtime/lib/worklet/ref/updateInitValue.js";
6
+ import { injectCalledByNative } from "../../../../runtime/lib/lynx/calledByNative.js";
7
+ import { flushDelayedLifecycleEvents, injectTt } from "../../../../runtime/lib/lynx/tt.js";
8
+ import { initElementPAPICallAlog } from "../../../../runtime/lib/alog/elementPAPICall.js";
9
+ import { addCtxNotFoundEventListener } from "../../../../runtime/lib/lifecycle/patch/error.js";
10
+ import { setRoot } from "../../../../runtime/lib/root.js";
11
+ import { BackgroundSnapshotInstance, SnapshotInstance, backgroundSnapshotInstanceManager, snapshotInstanceManager } from "../../../../runtime/lib/snapshot/index.js";
12
+ import { destroyWorklet } from "../../../../runtime/lib/worklet/destroy.js";
13
+ import { initApiEnv } from "../../../../runtime/lib/worklet-runtime/api/lynxApi.js";
14
+ import { initEventListeners } from "../../../../runtime/lib/worklet-runtime/listeners.js";
15
+ import { initWorklet } from "../../../../runtime/lib/worklet-runtime/workletRuntime.js";
33
16
  const { onInjectMainThreadGlobals, onInjectBackgroundThreadGlobals, onResetLynxTestingEnv, onSwitchedToMainThread, onSwitchedToBackgroundThread, onInitWorkletRuntime } = globalThis;
34
17
  injectCalledByNative();
35
18
  injectUpdateMainThread();
@@ -72,7 +55,10 @@ globalThis.onInjectMainThreadGlobals = (target)=>{
72
55
  }
73
56
  target._document = setupDocument({});
74
57
  target.globalPipelineOptions = void 0;
75
- if ("u" > typeof __ALOG_ELEMENT_API__ && __ALOG_ELEMENT_API__) initElementPAPICallAlog(target);
58
+ if (void 0 !== target.__ALOG_ELEMENT_API__ && target.__ALOG_ELEMENT_API__ && !target.__initElementPAPICallAlogInjected) {
59
+ initElementPAPICallAlog(target);
60
+ target.__initElementPAPICallAlogInjected = true;
61
+ }
76
62
  };
77
63
  globalThis.onInjectBackgroundThreadGlobals = (target)=>{
78
64
  if (onInjectBackgroundThreadGlobals) onInjectBackgroundThreadGlobals(target);
@@ -100,13 +86,13 @@ globalThis.onInjectBackgroundThreadGlobals = (target)=>{
100
86
  }
101
87
  target._document = setupBackgroundDocument({});
102
88
  target.globalPipelineOptions = void 0;
103
- target.lynx.requireModuleAsync = async (url, callback)=>{
104
- try {
105
- callback(null, await __vite_ssr_dynamic_import__(url));
106
- } catch (err) {
107
- callback(err, null);
108
- }
109
- };
89
+ const oldLynxCoreInject = globalThis.lynxCoreInject;
90
+ globalThis.lynxCoreInject = target.lynxCoreInject;
91
+ try {
92
+ injectTt();
93
+ } finally{
94
+ globalThis.lynxCoreInject = oldLynxCoreInject;
95
+ }
110
96
  deinitGlobalSnapshotPatch();
111
97
  clearCommitTaskId();
112
98
  };
@@ -0,0 +1,7 @@
1
+ const { onInjectBackgroundThreadGlobals } = globalThis;
2
+ globalThis.onInjectBackgroundThreadGlobals = (target)=>{
3
+ if (onInjectBackgroundThreadGlobals) onInjectBackgroundThreadGlobals(target);
4
+ target.lynx.requireModuleAsync = async (url, _callback)=>{
5
+ throw new Error('lynx.requireModuleAsync not implemented for rstest');
6
+ };
7
+ };
@@ -0,0 +1,11 @@
1
+ const { onInjectBackgroundThreadGlobals } = globalThis;
2
+ globalThis.onInjectBackgroundThreadGlobals = (target)=>{
3
+ if (onInjectBackgroundThreadGlobals) onInjectBackgroundThreadGlobals(target);
4
+ target.lynx.requireModuleAsync = async (url, callback)=>{
5
+ try {
6
+ callback(null, await __vite_ssr_dynamic_import__(url));
7
+ } catch (err) {
8
+ callback(err, null);
9
+ }
10
+ };
11
+ };
@@ -0,0 +1,21 @@
1
+ import "../env/rstest.js";
2
+ import "./common/runtime-setup.js";
3
+ import "./inner/rstest.js";
4
+ import "./common/bootstrap.js";
5
+ import { expect } from "@rstest/core";
6
+ expect.addSnapshotSerializer({
7
+ test (val) {
8
+ return Boolean(val && 'object' == typeof val && Array.isArray(val.refAttr) && Object.prototype.hasOwnProperty.call(val, 'task') && 'function' == typeof val.exec);
9
+ },
10
+ print (val, serialize) {
11
+ const printed = serialize({
12
+ refAttr: Array.isArray(val.refAttr) ? [
13
+ ...val.refAttr
14
+ ] : val.refAttr,
15
+ task: val.task
16
+ });
17
+ if (printed.startsWith('Object')) return printed.replace(/^Object/, 'RefProxy');
18
+ if (printed.startsWith('{')) return `RefProxy ${printed}`;
19
+ return printed;
20
+ }
21
+ });
@@ -0,0 +1,20 @@
1
+ import "./common/runtime-setup.js";
2
+ import "./inner/vitest.js";
3
+ import "./common/bootstrap.js";
4
+ import { expect } from "vitest";
5
+ expect.addSnapshotSerializer({
6
+ test (val) {
7
+ return Boolean(val && 'object' == typeof val && Array.isArray(val.refAttr) && Object.prototype.hasOwnProperty.call(val, 'task') && 'function' == typeof val.exec);
8
+ },
9
+ print (val, serialize) {
10
+ const printed = serialize({
11
+ refAttr: Array.isArray(val.refAttr) ? [
12
+ ...val.refAttr
13
+ ] : val.refAttr,
14
+ task: val.task
15
+ });
16
+ if (printed.startsWith('Object')) return printed.replace(/^Object/, 'RefProxy');
17
+ if (printed.startsWith('{')) return `RefProxy ${printed}`;
18
+ return printed;
19
+ }
20
+ });
@@ -0,0 +1,6 @@
1
+ import { type ViteUserConfig } from 'vitest/config';
2
+ import type { TestingLibraryOptions } from './plugins/index.js';
3
+ /**
4
+ * @deprecated Use `vitestTestingLibraryPlugin` from `@lynx-js/react/testing-library/plugins` instead.
5
+ */
6
+ export declare function createVitestConfig(options?: TestingLibraryOptions): ViteUserConfig;
@@ -1,263 +1,10 @@
1
1
  import { defineConfig } from "vitest/config";
2
- import { VitestPackageInstaller } from "vitest/node";
3
- import path from "path";
4
- import { fileURLToPath } from "url";
5
- import { createRequire } from "module";
6
- const vitest_config_filename = fileURLToPath(import.meta.url);
7
- const vitest_config_dirname = path.dirname(vitest_config_filename);
8
- const vitest_config_require = createRequire(import.meta.url);
9
- async function ensurePackagesInstalled() {
10
- const installer = new VitestPackageInstaller();
11
- const installed = await installer.ensureInstalled('jsdom', process.cwd());
12
- if (!installed) {
13
- console.log('ReactLynx Testing Library requires jsdom to be installed.');
14
- process.exit(1);
15
- }
16
- }
17
- const createVitestConfig = async (options)=>{
18
- await ensurePackagesInstalled();
19
- const runtimeOSSPkgName = '@lynx-js/react';
20
- const runtimePkgName = options?.runtimePkgName ?? runtimeOSSPkgName;
21
- const runtimeDir = path.dirname(vitest_config_require.resolve(`${runtimePkgName}/package.json`));
22
- const runtimeOSSDir = path.dirname(vitest_config_require.resolve(`${runtimeOSSPkgName}/package.json`, {
23
- paths: [
24
- runtimeDir,
25
- vitest_config_dirname
26
- ]
27
- }));
28
- const preactDir = path.dirname(vitest_config_require.resolve('preact/package.json', {
29
- paths: [
30
- runtimeOSSDir
31
- ]
32
- }));
33
- const generateAlias = (pkgName, pkgDir, resolveDir)=>{
34
- const pkgExports = vitest_config_require(path.join(pkgDir, 'package.json')).exports;
35
- const pkgAlias = [];
36
- Object.keys(pkgExports).forEach((key)=>{
37
- const name = path.posix.join(pkgName, key);
38
- pkgAlias.push({
39
- find: new RegExp('^' + name + '$'),
40
- replacement: vitest_config_require.resolve(name, {
41
- paths: [
42
- resolveDir,
43
- vitest_config_dirname
44
- ]
45
- })
46
- });
47
- });
48
- return pkgAlias;
49
- };
50
- const runtimeOSSAlias = generateAlias(runtimeOSSPkgName, runtimeOSSDir, runtimeDir);
51
- let runtimeAlias = [];
52
- if (runtimePkgName !== runtimeOSSPkgName) runtimeAlias = generateAlias(runtimePkgName, runtimeDir, vitest_config_dirname);
53
- const preactAlias = generateAlias('preact', preactDir, runtimeOSSDir);
54
- preactAlias.forEach((alias)=>{
55
- alias.replacement = alias.replacement.replace(/\.js$/, '.mjs');
56
- });
57
- const reactAlias = [
58
- {
59
- find: /^react$/,
60
- replacement: vitest_config_require.resolve(runtimeOSSPkgName, {
61
- paths: [
62
- runtimeDir,
63
- vitest_config_dirname
64
- ]
65
- })
66
- },
67
- {
68
- find: /^react\/jsx-runtime$/,
69
- replacement: vitest_config_require.resolve(path.posix.join(runtimeOSSPkgName, 'jsx-runtime'), {
70
- paths: [
71
- runtimeDir,
72
- vitest_config_dirname
73
- ]
74
- })
75
- },
76
- {
77
- find: /^react\/jsx-dev-runtime$/,
78
- replacement: vitest_config_require.resolve(path.posix.join(runtimeOSSPkgName, 'jsx-dev-runtime'), {
79
- paths: [
80
- runtimeDir,
81
- vitest_config_dirname
82
- ]
83
- })
84
- }
85
- ];
86
- function transformReactCompilerPlugin() {
87
- let rootContext, compilerDeps, babel;
88
- function resolveCompilerDeps(rootContext) {
89
- const missingBabelPackages = [];
90
- const [babelPath, babelPluginReactCompilerPath, babelPluginSyntaxJsxPath, babelPluginSyntaxTypescriptPath] = [
91
- '@babel/core',
92
- 'babel-plugin-react-compiler',
93
- '@babel/plugin-syntax-jsx',
94
- "@babel/plugin-syntax-typescript"
95
- ].map((name)=>{
96
- try {
97
- return vitest_config_require.resolve(name, {
98
- paths: [
99
- rootContext
100
- ]
101
- });
102
- } catch {
103
- missingBabelPackages.push(name);
104
- }
105
- return '';
106
- });
107
- if (missingBabelPackages.length > 0) throw new Error(`With \`experimental_enableReactCompiler\` enabled, you need to install \`${missingBabelPackages.join('`, `')}\` in your project root to use React Compiler.`);
108
- return {
109
- babelPath,
110
- babelPluginReactCompilerPath,
111
- babelPluginSyntaxJsxPath,
112
- babelPluginSyntaxTypescriptPath
113
- };
114
- }
115
- return {
116
- name: 'transformReactCompilerPlugin',
117
- enforce: 'pre',
118
- config (config) {
119
- rootContext = config.root;
120
- const reactCompilerRuntimeAlias = [];
121
- try {
122
- reactCompilerRuntimeAlias.push({
123
- find: /^react-compiler-runtime$/,
124
- replacement: path.join(path.dirname(vitest_config_require.resolve('react-compiler-runtime/package.json', {
125
- paths: [
126
- rootContext
127
- ]
128
- })), 'src', 'index.ts')
129
- });
130
- } catch (e) {}
131
- config.test.alias.push(...reactCompilerRuntimeAlias);
132
- compilerDeps = resolveCompilerDeps(rootContext);
133
- const { babelPath } = compilerDeps;
134
- babel = vitest_config_require(babelPath);
135
- },
136
- async transform (sourceText, sourcePath) {
137
- if (/\.(?:jsx|tsx)$/.test(sourcePath)) {
138
- const { babelPluginReactCompilerPath, babelPluginSyntaxJsxPath, babelPluginSyntaxTypescriptPath } = compilerDeps;
139
- const isTSX = sourcePath.endsWith('.tsx');
140
- try {
141
- const result = babel.transformSync(sourceText, {
142
- plugins: [
143
- [
144
- babelPluginReactCompilerPath,
145
- {
146
- target: '17'
147
- }
148
- ],
149
- babelPluginSyntaxJsxPath,
150
- isTSX ? [
151
- babelPluginSyntaxTypescriptPath,
152
- {
153
- isTSX: true
154
- }
155
- ] : null
156
- ].filter(Boolean),
157
- filename: sourcePath,
158
- ast: false,
159
- sourceMaps: true
160
- });
161
- if (result?.code != null && result?.map != null) return {
162
- code: result.code,
163
- map: result.map
164
- };
165
- this.error(`babel-plugin-react-compiler transform failed for ${sourcePath}: ${result ? 'missing code or map' : 'no result'}`);
166
- } catch (e) {
167
- this.error(e);
168
- }
169
- }
170
- return null;
171
- }
172
- };
173
- }
174
- function transformReactLynxPlugin() {
175
- return {
176
- name: 'transformReactLynxPlugin',
177
- enforce: 'pre',
178
- transform (sourceText, sourcePath) {
179
- const id = sourcePath;
180
- const regex = /\.(?:js|jsx|mjs|cjs|ts|tsx|mts|cts)(\?.*)?$/;
181
- if (!regex.test(id)) return null;
182
- const { transformReactLynxSync } = vitest_config_require('@lynx-js/react/transform');
183
- const relativePath = normalizeSlashes(path.relative(vitest_config_dirname, sourcePath));
184
- const basename = path.basename(sourcePath);
185
- const result = transformReactLynxSync(sourceText, {
186
- mode: 'test',
187
- pluginName: '',
188
- filename: basename,
189
- sourcemap: true,
190
- snapshot: {
191
- preserveJsx: false,
192
- runtimePkg: `${runtimePkgName}/internal`,
193
- jsxImportSource: runtimePkgName,
194
- filename: relativePath,
195
- target: 'MIXED'
196
- },
197
- engineVersion: options?.engineVersion ?? '',
198
- dynamicImport: {
199
- injectLazyBundle: false,
200
- layer: 'test',
201
- runtimePkg: `${runtimePkgName}/internal`
202
- },
203
- directiveDCE: false,
204
- defineDCE: false,
205
- shake: false,
206
- compat: false,
207
- worklet: {
208
- filename: relativePath,
209
- runtimePkg: `${runtimePkgName}/internal`,
210
- target: 'MIXED'
211
- },
212
- refresh: false,
213
- cssScope: false
214
- });
215
- if (result.errors.length > 0) result.errors.forEach((error)=>{
216
- this.error(error.text, error.location);
217
- });
218
- if (result.warnings.length > 0) result.warnings.forEach((warning)=>{
219
- this.warn(warning.text, warning.location);
220
- });
221
- return {
222
- code: result.code,
223
- map: result.map
224
- };
225
- }
226
- };
227
- }
2
+ import { vitestTestingLibraryPlugin } from "./plugins/index.js";
3
+ function createVitestConfig(options) {
228
4
  return defineConfig({
229
- server: {
230
- fs: {
231
- allow: [
232
- path.join(vitest_config_dirname, '..')
233
- ]
234
- }
235
- },
236
5
  plugins: [
237
- ...options?.experimental_enableReactCompiler ? [
238
- transformReactCompilerPlugin()
239
- ] : [],
240
- transformReactLynxPlugin()
241
- ],
242
- test: {
243
- environment: vitest_config_require.resolve('./env/vitest'),
244
- globals: true,
245
- setupFiles: [
246
- path.join(vitest_config_dirname, 'vitest-global-setup')
247
- ],
248
- alias: [
249
- ...runtimeOSSAlias,
250
- ...runtimeAlias,
251
- ...preactAlias,
252
- ...reactAlias
253
- ],
254
- include: options?.include ?? [
255
- 'src/**/*.test.{js,jsx,ts,tsx}'
256
- ]
257
- }
6
+ vitestTestingLibraryPlugin(options)
7
+ ]
258
8
  });
259
- };
260
- function normalizeSlashes(file) {
261
- return file.replaceAll(path.win32.sep, '/');
262
9
  }
263
10
  export { createVitestConfig };