@lynx-js/react 0.106.4 → 0.107.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 (56) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/package.json +15 -2
  3. package/refresh/.turbo/turbo-build.log +1 -1
  4. package/refresh/package.json +1 -1
  5. package/runtime/jsx-dev-runtime/index.d.ts +12 -0
  6. package/runtime/jsx-runtime/index.d.ts +12 -0
  7. package/runtime/lib/index.js +7 -4
  8. package/runtime/lib/index.js.map +1 -1
  9. package/runtime/lib/lifecycle/patch/commit.d.ts +7 -1
  10. package/runtime/lib/lifecycle/patch/commit.js +44 -38
  11. package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
  12. package/runtime/lib/lifecycle/patch/updateMainThread.js +6 -4
  13. package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
  14. package/runtime/lib/list.d.ts +13 -6
  15. package/runtime/lib/list.js.map +1 -1
  16. package/runtime/lib/lynx/calledByNative.js +2 -2
  17. package/runtime/lib/lynx/calledByNative.js.map +1 -1
  18. package/runtime/lib/lynx/component.js +1 -1
  19. package/runtime/lib/lynx/component.js.map +1 -1
  20. package/runtime/lib/lynx/performance.d.ts +24 -14
  21. package/runtime/lib/lynx/performance.js +42 -23
  22. package/runtime/lib/lynx/performance.js.map +1 -1
  23. package/runtime/lib/lynx/runWithForce.d.ts +1 -0
  24. package/runtime/lib/lynx/runWithForce.js +45 -0
  25. package/runtime/lib/lynx/runWithForce.js.map +1 -0
  26. package/runtime/lib/lynx/tt.d.ts +2 -1
  27. package/runtime/lib/lynx/tt.js +33 -61
  28. package/runtime/lib/lynx/tt.js.map +1 -1
  29. package/runtime/lib/lynx.d.ts +1 -0
  30. package/runtime/lib/lynx.js +1 -0
  31. package/runtime/lib/lynx.js.map +1 -1
  32. package/runtime/src/index.ts +7 -4
  33. package/runtime/src/lifecycle/patch/commit.ts +54 -41
  34. package/runtime/src/lifecycle/patch/updateMainThread.ts +6 -4
  35. package/runtime/src/list.ts +18 -10
  36. package/runtime/src/lynx/calledByNative.ts +2 -2
  37. package/runtime/src/lynx/component.ts +1 -1
  38. package/runtime/src/lynx/performance.ts +48 -22
  39. package/runtime/src/lynx/runWithForce.ts +52 -0
  40. package/runtime/src/lynx/tt.ts +47 -70
  41. package/runtime/src/lynx.ts +1 -0
  42. package/testing-library/README.md +70 -0
  43. package/testing-library/dist/env/vitest.js +548 -0
  44. package/testing-library/dist/index.d.ts +1504 -0
  45. package/testing-library/dist/index.js +12 -0
  46. package/testing-library/dist/pure.js +14729 -0
  47. package/testing-library/dist/pure.js.LICENSE.txt +17 -0
  48. package/testing-library/dist/vitest-global-setup.js +115 -0
  49. package/testing-library/dist/vitest.config.js +90 -0
  50. package/testing-library/types/entry.d.ts +257 -0
  51. package/testing-library/types/index.d.ts +15 -0
  52. package/testing-library/types/pure.d.ts +2 -0
  53. package/testing-library/types/vitest-config.d.ts +12 -0
  54. package/transform/dist/wasm.cjs +1 -1
  55. package/types/react.d.ts +31 -0
  56. package/LICENSE +0 -202
@@ -0,0 +1,17 @@
1
+ /** @license React v17.0.2
2
+ * react-is.development.js
3
+ *
4
+ * Copyright (c) Facebook, Inc. and its affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+ /** @license React v17.0.2
11
+ * react-is.production.min.js
12
+ *
13
+ * Copyright (c) Facebook, Inc. and its affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ */
@@ -0,0 +1,115 @@
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
+ 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
+ import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__ from "../../runtime/lib/lifecycle/patch/commit.js";
7
+ import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__ from "../../runtime/lib/lynx/tt.js";
8
+ import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_root_js_27522aef__ from "../../runtime/lib/root.js";
9
+ import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_snapshotPatch_js_c1ebb33c__ from "../../runtime/lib/lifecycle/patch/snapshotPatch.js";
10
+ import * as __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_api_lynxApi_js_c6dc2d67__ from "../../worklet-runtime/lib/api/lynxApi.js";
11
+ import * as __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_listeners_js_9f7cd330__ from "../../worklet-runtime/lib/listeners.js";
12
+ import * as __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_workletRuntime_js_e9debbe1__ from "../../worklet-runtime/lib/workletRuntime.js";
13
+ import * as __WEBPACK_EXTERNAL_MODULE__runtime_lib_worklet_destroy_js_8a273fd1__ from "../../runtime/lib/worklet/destroy.js";
14
+ const { onInjectMainThreadGlobals, onInjectBackgroundThreadGlobals, onResetLynxEnv, onSwitchedToMainThread, onSwitchedToBackgroundThread, onInitWorkletRuntime } = globalThis;
15
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_calledByNative_js_f689039d__.injectCalledByNative)();
16
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_updateMainThread_js_dca3a751__.injectUpdateMainThread)();
17
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__.replaceCommitHook)();
18
+ globalThis.onInitWorkletRuntime = ()=>{
19
+ if (onInitWorkletRuntime) onInitWorkletRuntime();
20
+ if (process.env.DEBUG) console.log('initWorkletRuntime');
21
+ lynx.setTimeout = setTimeout;
22
+ lynx.setInterval = setInterval;
23
+ lynx.clearTimeout = clearTimeout;
24
+ lynx.clearInterval = clearInterval;
25
+ (0, __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_workletRuntime_js_e9debbe1__.initWorklet)();
26
+ (0, __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_api_lynxApi_js_c6dc2d67__.initApiEnv)();
27
+ (0, __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_listeners_js_9f7cd330__.initEventListeners)();
28
+ return true;
29
+ };
30
+ globalThis.onInjectMainThreadGlobals = (target)=>{
31
+ if (onInjectMainThreadGlobals) onInjectMainThreadGlobals();
32
+ if (process.env.DEBUG) console.log('onInjectMainThreadGlobals');
33
+ __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.snapshotInstanceManager.clear();
34
+ __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.snapshotInstanceManager.nextId = 0;
35
+ target.__root = new __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.SnapshotInstance('root');
36
+ function setupDocument(document) {
37
+ document.createElement = function(type) {
38
+ return new __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.SnapshotInstance(type);
39
+ };
40
+ document.createElementNS = function(_ns, type) {
41
+ return new __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.SnapshotInstance(type);
42
+ };
43
+ document.createTextNode = function(text) {
44
+ const i = new __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.SnapshotInstance(null);
45
+ i.setAttribute(0, text);
46
+ Object.defineProperty(i, 'data', {
47
+ set (v) {
48
+ i.setAttribute(0, v);
49
+ }
50
+ });
51
+ return i;
52
+ };
53
+ return document;
54
+ }
55
+ target._document = setupDocument({});
56
+ target.globalPipelineOptions = void 0;
57
+ };
58
+ globalThis.onInjectBackgroundThreadGlobals = (target)=>{
59
+ if (onInjectBackgroundThreadGlobals) onInjectBackgroundThreadGlobals();
60
+ if (process.env.DEBUG) console.log('onInjectBackgroundThreadGlobals');
61
+ __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.backgroundSnapshotInstanceManager.clear();
62
+ __WEBPACK_EXTERNAL_MODULE__runtime_lib_snapshot_js_675dfde4__.backgroundSnapshotInstanceManager.nextId = 0;
63
+ target.__root = new __WEBPACK_EXTERNAL_MODULE__runtime_lib_backgroundSnapshot_js_d70e0888__.BackgroundSnapshotInstance('root');
64
+ function setupBackgroundDocument(document) {
65
+ document.createElement = function(type) {
66
+ return new __WEBPACK_EXTERNAL_MODULE__runtime_lib_backgroundSnapshot_js_d70e0888__.BackgroundSnapshotInstance(type);
67
+ };
68
+ document.createElementNS = function(_ns, type) {
69
+ return new __WEBPACK_EXTERNAL_MODULE__runtime_lib_backgroundSnapshot_js_d70e0888__.BackgroundSnapshotInstance(type);
70
+ };
71
+ document.createTextNode = function(text) {
72
+ const i = new __WEBPACK_EXTERNAL_MODULE__runtime_lib_backgroundSnapshot_js_d70e0888__.BackgroundSnapshotInstance(null);
73
+ i.setAttribute(0, text);
74
+ Object.defineProperty(i, 'data', {
75
+ set (v) {
76
+ i.setAttribute(0, v);
77
+ }
78
+ });
79
+ return i;
80
+ };
81
+ return document;
82
+ }
83
+ target._document = setupBackgroundDocument({});
84
+ target.globalPipelineOptions = void 0;
85
+ const oldLynxCoreInject = globalThis.lynxCoreInject;
86
+ globalThis.lynxCoreInject = target.lynxCoreInject;
87
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__.injectTt)();
88
+ globalThis.lynxCoreInject = oldLynxCoreInject;
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
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lifecycle_patch_commit_js_9adc7328__.clearCommitTaskId)();
92
+ };
93
+ globalThis.onResetLynxEnv = ()=>{
94
+ if (onResetLynxEnv) onResetLynxEnv();
95
+ if (process.env.DEBUG) console.log('onResetLynxEnv');
96
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_lynx_tt_js_37d9bcb1__.flushDelayedLifecycleEvents)();
97
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_worklet_destroy_js_8a273fd1__.destroyWorklet)();
98
+ lynxEnv.switchToMainThread();
99
+ (0, __WEBPACK_EXTERNAL_MODULE__worklet_runtime_lib_listeners_js_9f7cd330__.initEventListeners)();
100
+ lynxEnv.switchToBackgroundThread();
101
+ };
102
+ globalThis.onSwitchedToMainThread = ()=>{
103
+ if (onSwitchedToMainThread) onSwitchedToMainThread();
104
+ if (process.env.DEBUG) console.log('onSwitchedToMainThread');
105
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_root_js_27522aef__.setRoot)(globalThis.__root);
106
+ __WEBPACK_EXTERNAL_MODULE_preact__.options.document = globalThis._document;
107
+ };
108
+ globalThis.onSwitchedToBackgroundThread = ()=>{
109
+ if (onSwitchedToBackgroundThread) onSwitchedToBackgroundThread();
110
+ if (process.env.DEBUG) console.log('onSwitchedToBackgroundThread');
111
+ (0, __WEBPACK_EXTERNAL_MODULE__runtime_lib_root_js_27522aef__.setRoot)(globalThis.__root);
112
+ __WEBPACK_EXTERNAL_MODULE_preact__.options.document = globalThis._document;
113
+ };
114
+ globalThis.onInjectMainThreadGlobals(globalThis.lynxEnv.mainThread.globalThis);
115
+ globalThis.onInjectBackgroundThreadGlobals(globalThis.lynxEnv.backgroundThread.globalThis);
@@ -0,0 +1,90 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_vitest_config_02c5e5a4__ from "vitest/config";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_vitest_node_ace4f808__ from "vitest/node";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_url__ from "url";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_module__ from "module";
6
+ const vitest_config_filename = (0, __WEBPACK_EXTERNAL_MODULE_url__.fileURLToPath)(import.meta.url);
7
+ const vitest_config_dirname = __WEBPACK_EXTERNAL_MODULE_path__["default"].dirname(vitest_config_filename);
8
+ const vitest_config_require = (0, __WEBPACK_EXTERNAL_MODULE_module__.createRequire)(import.meta.url);
9
+ async function ensurePackagesInstalled() {
10
+ const installer = new __WEBPACK_EXTERNAL_MODULE_vitest_node_ace4f808__.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 runtimePkgName = options?.runtimePkgName ?? '@lynx-js/react';
20
+ function transformReactLynxPlugin() {
21
+ return {
22
+ name: 'transformReactLynxPlugin',
23
+ enforce: 'pre',
24
+ transform (sourceText, sourcePath) {
25
+ const id = sourcePath;
26
+ if (id.endsWith('.css') || id.endsWith('.less') || id.endsWith('.scss')) {
27
+ if (process.env['DEBUG']) console.log('ignoring css file', id);
28
+ return '';
29
+ }
30
+ const { transformReactLynxSync } = vitest_config_require('@lynx-js/react/transform');
31
+ const relativePath = __WEBPACK_EXTERNAL_MODULE_path__["default"].relative(vitest_config_dirname, sourcePath);
32
+ const basename = __WEBPACK_EXTERNAL_MODULE_path__["default"].basename(sourcePath);
33
+ const result = transformReactLynxSync(sourceText, {
34
+ mode: 'test',
35
+ pluginName: '',
36
+ filename: basename,
37
+ sourcemap: true,
38
+ snapshot: {
39
+ preserveJsx: false,
40
+ runtimePkg: `${runtimePkgName}/internal`,
41
+ jsxImportSource: runtimePkgName,
42
+ filename: relativePath,
43
+ target: 'MIXED'
44
+ },
45
+ directiveDCE: false,
46
+ defineDCE: false,
47
+ shake: false,
48
+ compat: false,
49
+ worklet: {
50
+ filename: relativePath,
51
+ runtimePkg: `${runtimePkgName}/internal`,
52
+ target: 'MIXED'
53
+ },
54
+ refresh: false,
55
+ cssScope: false
56
+ });
57
+ if (result.errors.length > 0) result.errors.forEach((error)=>{
58
+ this.error(error.text, error.location);
59
+ });
60
+ if (result.warnings.length > 0) result.warnings.forEach((warning)=>{
61
+ this.warn(warning.text, warning.location);
62
+ });
63
+ return {
64
+ code: result.code,
65
+ map: result.map
66
+ };
67
+ }
68
+ };
69
+ }
70
+ return (0, __WEBPACK_EXTERNAL_MODULE_vitest_config_02c5e5a4__.defineConfig)({
71
+ server: {
72
+ fs: {
73
+ allow: [
74
+ __WEBPACK_EXTERNAL_MODULE_path__["default"].join(vitest_config_dirname, '..')
75
+ ]
76
+ }
77
+ },
78
+ plugins: [
79
+ transformReactLynxPlugin()
80
+ ],
81
+ test: {
82
+ environment: vitest_config_require.resolve('./env/vitest'),
83
+ globals: true,
84
+ setupFiles: [
85
+ __WEBPACK_EXTERNAL_MODULE_path__["default"].join(vitest_config_dirname, 'vitest-global-setup')
86
+ ]
87
+ }
88
+ });
89
+ };
90
+ export { createVitestConfig };
@@ -0,0 +1,257 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * ReactLynx Testing Library is a simple and complete ReactLynx
5
+ * unit testing library that encourages good testing practices.
6
+ *
7
+ * Inspired by {@link https://testing-library.com/docs/react-testing-library/intro | React Testing Library} and {@link https://github.com/jsdom/jsdom | jsdom}.
8
+ */
9
+
10
+ import { queries, Queries, BoundFunction } from '@testing-library/dom';
11
+ import { LynxElement, type ElementTree, type LynxEnv } from '@lynx-js/test-environment';
12
+ import { ComponentChild, ComponentType } from 'preact';
13
+ export * from '@testing-library/dom';
14
+ export { ElementTree, LynxEnv };
15
+
16
+ /**
17
+ * The options for {@link render}.
18
+ *
19
+ * @public
20
+ */
21
+ export interface RenderOptions<Q extends Queries = typeof queries> {
22
+ /**
23
+ * Queries to bind. Overrides the default set from DOM Testing Library unless merged.
24
+ *
25
+ * @example
26
+ *
27
+ * ```ts
28
+ * // Example, a function to traverse table contents
29
+ * import * as tableQueries from 'my-table-query-library'
30
+ * import { queries } from '@lynx-js/react/testing-library'
31
+ *
32
+ * const { getByRowColumn, getByText } = render(<MyTable />, {
33
+ * queries: {...queries, ...tableQueries},
34
+ * })
35
+ *
36
+ * ```
37
+ */
38
+ queries?: Q;
39
+ /**
40
+ * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
41
+ * reusable custom render functions for common data providers. See setup for examples.
42
+ *
43
+ * @example
44
+ *
45
+ * ```ts
46
+ * import { render } from '@lynx-js/react/testing-library'
47
+ * import { ThemeProvider } from 'my-ui-lib'
48
+ * import { TranslationProvider } from 'my-i18n-lib'
49
+ * import defaultStrings from 'i18n/en-x-default'
50
+ *
51
+ * const AllTheProviders = ({children}) => {
52
+ * return (
53
+ * <ThemeProvider theme="light">
54
+ * <TranslationProvider messages={defaultStrings}>
55
+ * {children}
56
+ * </TranslationProvider>
57
+ * </ThemeProvider>
58
+ * )
59
+ * }
60
+ *
61
+ * const customRender = (ui, options) =>
62
+ * render(ui, { wrapper: AllTheProviders, ...options })
63
+ *
64
+ * // re-export everything
65
+ * export * from '@lynx-js/react/testing-library'
66
+ *
67
+ * // override render method
68
+ * export { customRender as render }
69
+ * ```
70
+ */
71
+ wrapper?: ComponentChild;
72
+ /**
73
+ * Render your component in the main thread or not.
74
+ *
75
+ * It is recommended to use this option only when you need to test the {@link https://lynxjs.org/zh/guide/interaction/ifr.html | IFR} behavior.
76
+ *
77
+ * @defaultValue false
78
+ */
79
+ enableMainThread?: boolean;
80
+ /**
81
+ * Render your component in the background thread or not.
82
+ *
83
+ * Note that all user code in the top level will be executed in the background thread by default. (eg. `__BACKGROUND__` is `true` in the top level)
84
+ *
85
+ * @defaultValue true
86
+ */
87
+ enableBackgroundThread?: boolean;
88
+ }
89
+
90
+ /**
91
+ * The result of {@link render}
92
+ *
93
+ * @public
94
+ */
95
+ export type RenderResult<Q extends Queries = typeof queries> = {
96
+ container: LynxElement;
97
+ rerender: (ui: ComponentChild) => void;
98
+ unmount: () => boolean;
99
+ } & { [P in keyof Q]: BoundFunction<Q[P]> };
100
+
101
+ /**
102
+ * Render into the page. It should be used with cleanup.
103
+ *
104
+ * @example
105
+ *
106
+ * ```ts
107
+ * import { render} from '@lynx-js/react/testing-library'
108
+ *
109
+ * const WrapperComponent = ({ children }) => (
110
+ * <view data-testid='wrapper'>{children}</view>
111
+ * );
112
+ * const Comp = () => {
113
+ * return <view data-testid='inner' style="background-color: yellow;" />;
114
+ * };
115
+ * const { container, getByTestId } = render(<Comp />, {
116
+ * wrapper: WrapperComponent,
117
+ * });
118
+ * expect(getByTestId('wrapper')).toBeInTheDocument();
119
+ * expect(container.firstChild).toMatchInlineSnapshot(`
120
+ * <view
121
+ * data-testid="wrapper"
122
+ * >
123
+ * <view
124
+ * data-testid="inner"
125
+ * style="background-color: yellow;"
126
+ * />
127
+ * </view>
128
+ * `);
129
+ * ```
130
+ *
131
+ * @public
132
+ */
133
+ export function render<Q extends Queries>(
134
+ ui: ComponentChild,
135
+ options?: RenderOptions<Q>,
136
+ ): RenderResult<Q>;
137
+ /**
138
+ * Cleanup elements rendered to the page and Preact trees that were mounted with render.
139
+ *
140
+ * @public
141
+ */
142
+ export function cleanup(): void;
143
+
144
+ /**
145
+ * The result of {@link renderHook}
146
+ *
147
+ * @public
148
+ */
149
+
150
+ export interface RenderHookResult<Result, Props> {
151
+ /**
152
+ * Triggers a re-render. The props will be passed to your renderHook callback.
153
+ */
154
+ rerender: (props?: Props) => void;
155
+ /**
156
+ * This is a stable reference to the latest value returned by your renderHook
157
+ * callback
158
+ */
159
+ result: {
160
+ /**
161
+ * The value returned by your renderHook callback
162
+ */
163
+ current: Result;
164
+ };
165
+ /**
166
+ * Unmounts the test component. This is useful for when you need to test
167
+ * any cleanup your useEffects have.
168
+ */
169
+ unmount: () => void;
170
+ }
171
+
172
+ /**
173
+ * The options for {@link renderHook}
174
+ *
175
+ * @public
176
+ */
177
+ export interface RenderHookOptions<Props> {
178
+ /**
179
+ * The argument passed to the renderHook callback. Can be useful if you plan
180
+ * to use the rerender utility to change the values passed to your hook.
181
+ */
182
+ initialProps?: Props;
183
+ /**
184
+ * Pass a React Component as the wrapper option to have it rendered around the inner element. This is most useful for creating
185
+ * reusable custom render functions for common data providers. See setup for examples.
186
+ *
187
+ * @example
188
+ *
189
+ * ```ts
190
+ * import { renderHook } from '@lynx-js/react/testing-library'
191
+ * import { ThemeProvider } from 'my-ui-lib'
192
+ * import { TranslationProvider } from 'my-i18n-lib'
193
+ * import defaultStrings from 'i18n/en-x-default'
194
+ *
195
+ * const AllTheProviders = ({children}) => {
196
+ * return (
197
+ * <ThemeProvider theme="light">
198
+ * <TranslationProvider messages={defaultStrings}>
199
+ * {children}
200
+ * </TranslationProvider>
201
+ * </ThemeProvider>
202
+ * )
203
+ * }
204
+ *
205
+ * const customRenderHook = (ui, options) =>
206
+ * renderHook(ui, { wrapper: AllTheProviders, ...options })
207
+ *
208
+ * // re-export everything
209
+ * export * from '@lynx-js/react/testing-library'
210
+ *
211
+ * // override renderHook method
212
+ * export { customRender as renderHook }
213
+ * ```
214
+ */
215
+ wrapper?: ComponentType<{ children: LynxElement }>;
216
+ }
217
+
218
+ /**
219
+ * Allows you to render a hook within a test React component without having to
220
+ * create that component yourself.
221
+ *
222
+ * @example
223
+ *
224
+ * ```ts
225
+ * import { renderHook } from '@lynx-js/react/testing-library'
226
+ *
227
+ * const Context = createContext('default');
228
+ * function Wrapper({ children }) {
229
+ * return <Context.Provider value='provided'>{children}</Context.Provider>;
230
+ * }
231
+ * const { result } = renderHook(
232
+ * () => {
233
+ * return useContext(Context);
234
+ * },
235
+ * {
236
+ * wrapper: Wrapper,
237
+ * },
238
+ * );
239
+ *
240
+ * expect(result.current).toEqual('provided');
241
+ * ```
242
+ *
243
+ * @public
244
+ */
245
+ export function renderHook<Result, Props>(
246
+ render: (initialProps: Props) => Result,
247
+ options?: RenderHookOptions<Props>,
248
+ ): RenderHookResult<Result, Props>;
249
+
250
+ /**
251
+ * Wait for the next event loop.
252
+ *
253
+ * It will be useful when you want to wait for the next event loop to finish.
254
+ *
255
+ * @public
256
+ */
257
+ export function waitSchedule(): Promise<void>;
@@ -0,0 +1,15 @@
1
+ // @ts-nocheck
2
+ export * from '../dist/index.d.ts';
3
+ import { ElementTree, LynxEnv } from '../dist/index.d.ts';
4
+
5
+ declare global {
6
+ var lynxEnv: LynxEnv;
7
+ var elementTree: ElementTree;
8
+
9
+ function onInjectBackgroundThreadGlobals(globals: any): void;
10
+ function onInjectMainThreadGlobals(globals: any): void;
11
+ function onSwitchedToBackgroundThread(): void;
12
+ function onSwitchedToMainThread(): void;
13
+ function onResetLynxEnv(): void;
14
+ function onInitWorkletRuntime(): void;
15
+ }
@@ -0,0 +1,2 @@
1
+ // @ts-nocheck
2
+ export * from './index.d.ts';
@@ -0,0 +1,12 @@
1
+ import type { ViteUserConfig } from 'vitest/config.js';
2
+
3
+ export interface CreateVitestConfigOptions {
4
+ /**
5
+ * The package name of the ReactLynx runtime package.
6
+ *
7
+ * @default `@lynx-js/react`
8
+ */
9
+ runtimePkgName?: string;
10
+ }
11
+
12
+ export function createVitestConfig(options?: CreateVitestConfigOptions): Promise<ViteUserConfig>;