@lynx-js/react 0.110.1 → 0.111.1
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 +50 -0
- package/components/lib/DeferredListItem.d.ts +7 -0
- package/components/lib/DeferredListItem.jsx +40 -0
- package/components/lib/DeferredListItem.jsx.map +1 -0
- package/components/lib/index.d.ts +1 -0
- package/components/lib/index.js +1 -0
- package/components/lib/index.js.map +1 -1
- package/components/src/DeferredListItem.tsx +56 -0
- package/components/src/index.ts +1 -0
- package/package.json +1 -1
- package/refresh/.turbo/turbo-build.log +7 -3
- package/refresh/dist/index.js +223 -284
- package/refresh/package.json +3 -4
- package/refresh/rslib.config.ts +24 -0
- package/runtime/lazy/react-lepus.js +1 -0
- package/runtime/lazy/react.js +1 -0
- package/runtime/lepus/index.d.ts +1 -1
- package/runtime/lepus/index.js +44 -0
- package/runtime/lib/backgroundSnapshot.d.ts +2 -1
- package/runtime/lib/backgroundSnapshot.js +62 -40
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/compat/initData.js +10 -0
- package/runtime/lib/compat/initData.js.map +1 -1
- package/runtime/lib/index.d.ts +2 -2
- package/runtime/lib/index.js +2 -2
- package/runtime/lib/index.js.map +1 -1
- package/runtime/lib/lifecycle/patch/commit.js +5 -5
- package/runtime/lib/lifecycle/patch/commit.js.map +1 -1
- package/runtime/lib/lifecycle/patch/snapshotPatch.d.ts +9 -9
- package/runtime/lib/lifecycle/patch/snapshotPatch.js +9 -10
- package/runtime/lib/lifecycle/patch/snapshotPatch.js.map +1 -1
- package/runtime/lib/lifecycle/patch/updateMainThread.js +7 -8
- package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/lifecycleConstant.d.ts +2 -1
- package/runtime/lib/lifecycleConstant.js +1 -0
- package/runtime/lib/lifecycleConstant.js.map +1 -1
- package/runtime/lib/list.js +102 -12
- package/runtime/lib/list.js.map +1 -1
- package/runtime/lib/lynx/calledByNative.js +6 -9
- package/runtime/lib/lynx/calledByNative.js.map +1 -1
- package/runtime/lib/lynx/component.js +11 -14
- package/runtime/lib/lynx/component.js.map +1 -1
- package/runtime/lib/lynx/env.js +1 -2
- package/runtime/lib/lynx/env.js.map +1 -1
- package/runtime/lib/lynx/lazy-bundle.js +48 -21
- package/runtime/lib/lynx/lazy-bundle.js.map +1 -1
- package/runtime/lib/lynx/performance.d.ts +3 -19
- package/runtime/lib/lynx/performance.js +25 -26
- package/runtime/lib/lynx/performance.js.map +1 -1
- package/runtime/lib/lynx/tt.js +10 -5
- package/runtime/lib/lynx/tt.js.map +1 -1
- package/runtime/lib/lynx-api.d.ts +78 -1
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/snapshot.d.ts +2 -0
- package/runtime/lib/snapshot.js +19 -5
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/lib/utils.d.ts +1 -0
- package/runtime/lib/utils.js +6 -0
- package/runtime/lib/utils.js.map +1 -1
- package/runtime/src/backgroundSnapshot.ts +74 -55
- package/runtime/src/compat/initData.ts +10 -0
- package/runtime/src/index.ts +2 -0
- package/runtime/src/lifecycle/patch/commit.ts +5 -11
- package/runtime/src/lifecycle/patch/snapshotPatch.ts +9 -9
- package/runtime/src/lifecycle/patch/updateMainThread.ts +7 -8
- package/runtime/src/lifecycleConstant.ts +1 -0
- package/runtime/src/list.ts +118 -15
- package/runtime/src/lynx/calledByNative.ts +6 -8
- package/runtime/src/lynx/component.ts +17 -29
- package/runtime/src/lynx/env.ts +1 -2
- package/runtime/src/lynx/lazy-bundle.ts +55 -20
- package/runtime/src/lynx/performance.ts +26 -27
- package/runtime/src/lynx/tt.ts +10 -11
- package/runtime/src/lynx-api.ts +77 -1
- package/runtime/src/snapshot.ts +20 -5
- package/runtime/src/utils.ts +9 -0
- package/testing-library/dist/env/vitest.js +6 -3
- package/testing-library/dist/index.d.ts +4 -1
- package/testing-library/dist/pure.js +4 -2
- package/testing-library/dist/vitest-global-setup.js +2 -2
- package/testing-library/dist/vitest.config.js +38 -1
- package/testing-library/types/entry.d.ts +3 -2
- package/transform/dist/wasm.cjs +1 -1
- package/types/react.d.ts +21 -1
- package/types/react.docs.d.ts +1 -1
- package/worklet-runtime/dist/dev.js +403 -506
- package/worklet-runtime/dist/main.js +1 -517
- package/worklet-runtime/lib/workletRuntime.js +5 -5
- package/worklet-runtime/lib/workletRuntime.js.map +1 -1
package/runtime/src/lynx/tt.ts
CHANGED
|
@@ -5,13 +5,7 @@ import { render } from 'preact';
|
|
|
5
5
|
|
|
6
6
|
import { LifecycleConstant, NativeUpdateDataType } from '../lifecycleConstant.js';
|
|
7
7
|
import type { FirstScreenData } from '../lifecycleConstant.js';
|
|
8
|
-
import {
|
|
9
|
-
PerformanceTimingFlags,
|
|
10
|
-
PerformanceTimingKeys,
|
|
11
|
-
PipelineOrigins,
|
|
12
|
-
beginPipeline,
|
|
13
|
-
markTiming,
|
|
14
|
-
} from './performance.js';
|
|
8
|
+
import { PerformanceTimingFlags, PipelineOrigins, beginPipeline, markTiming } from './performance.js';
|
|
15
9
|
import { BackgroundSnapshotInstance, hydrate } from '../backgroundSnapshot.js';
|
|
16
10
|
import { runWithForce } from './runWithForce.js';
|
|
17
11
|
import { destroyBackground } from '../lifecycle/destroy.js';
|
|
@@ -80,10 +74,10 @@ function onLifecycleEventImpl(type: LifecycleConstant, data: unknown): void {
|
|
|
80
74
|
console.profile('hydrate');
|
|
81
75
|
}
|
|
82
76
|
beginPipeline(true, PipelineOrigins.reactLynxHydrate, PerformanceTimingFlags.reactLynxHydrate);
|
|
83
|
-
markTiming(
|
|
77
|
+
markTiming('hydrateParseSnapshotStart');
|
|
84
78
|
const before = JSON.parse(lepusSide) as SerializedSnapshotInstance;
|
|
85
|
-
markTiming(
|
|
86
|
-
markTiming(
|
|
79
|
+
markTiming('hydrateParseSnapshotEnd');
|
|
80
|
+
markTiming('diffVdomStart');
|
|
87
81
|
const snapshotPatch = hydrate(
|
|
88
82
|
before,
|
|
89
83
|
__root as BackgroundSnapshotInstance,
|
|
@@ -91,7 +85,7 @@ function onLifecycleEventImpl(type: LifecycleConstant, data: unknown): void {
|
|
|
91
85
|
if (__PROFILE__) {
|
|
92
86
|
console.profileEnd();
|
|
93
87
|
}
|
|
94
|
-
markTiming(
|
|
88
|
+
markTiming('diffVdomEnd');
|
|
95
89
|
|
|
96
90
|
// TODO: It seems `delayedEvents` and `delayedLifecycleEvents` should be merged into one array to ensure the proper order of events.
|
|
97
91
|
flushDelayedLifecycleEvents();
|
|
@@ -141,6 +135,11 @@ function onLifecycleEventImpl(type: LifecycleConstant, data: unknown): void {
|
|
|
141
135
|
lynx.getJSModule('GlobalEventEmitter').trigger(eventName, params);
|
|
142
136
|
break;
|
|
143
137
|
}
|
|
138
|
+
case LifecycleConstant.publishEvent: {
|
|
139
|
+
const { handlerName, data: d } = data as { handlerName: string; data: unknown };
|
|
140
|
+
lynxCoreInject.tt.publishEvent(handlerName, d);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
144
143
|
}
|
|
145
144
|
}
|
|
146
145
|
|
package/runtime/src/lynx-api.ts
CHANGED
|
@@ -218,6 +218,82 @@ export interface InitData {}
|
|
|
218
218
|
|
|
219
219
|
export { withInitDataInState };
|
|
220
220
|
|
|
221
|
+
/**
|
|
222
|
+
* The data processors that registered with {@link Lynx.registerDataProcessors}.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
*
|
|
226
|
+
* Extending `dataProcessors` interface
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* import type { DataProcessors as WellKnownDataProcessors } from '@lynx-js/react';
|
|
230
|
+
*
|
|
231
|
+
* declare module '@lynx-js/react' {
|
|
232
|
+
* interface DataProcessors extends WellKnownDataProcessors {
|
|
233
|
+
* foo(bar: string): number;
|
|
234
|
+
* }
|
|
235
|
+
* }
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* Then you can use `lynx.registerDataProcessors` with types.
|
|
239
|
+
*
|
|
240
|
+
* ```js
|
|
241
|
+
* lynx.registerDataProcessors({
|
|
242
|
+
* dataProcessors: {
|
|
243
|
+
* foo(bar) {
|
|
244
|
+
* return 1;
|
|
245
|
+
* }
|
|
246
|
+
* }
|
|
247
|
+
* })
|
|
248
|
+
* ```
|
|
249
|
+
*
|
|
250
|
+
* @public
|
|
251
|
+
*/
|
|
252
|
+
export interface DataProcessors {
|
|
253
|
+
/**
|
|
254
|
+
* Optional processor to override screen metrics used by the app
|
|
255
|
+
*
|
|
256
|
+
* @param metrics - The physical screen dimensions in pixels
|
|
257
|
+
*
|
|
258
|
+
* @returns New screen dimensions to be used by the app
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
*
|
|
262
|
+
* ```ts
|
|
263
|
+
* lynx.registerDataProcessors({
|
|
264
|
+
* dataProcessors: {
|
|
265
|
+
* getScreenMetricsOverride: (metrics) => {
|
|
266
|
+
* // Force a specific aspect ratio
|
|
267
|
+
* return {
|
|
268
|
+
* width: metrics.width,
|
|
269
|
+
* height: metrics.width * (16/9)
|
|
270
|
+
* };
|
|
271
|
+
* }
|
|
272
|
+
* }
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
getScreenMetricsOverride?(metrics: {
|
|
277
|
+
/**
|
|
278
|
+
* The physical pixel width of the screen
|
|
279
|
+
*/
|
|
280
|
+
width: number;
|
|
281
|
+
/**
|
|
282
|
+
* The physical pixel height of the screen
|
|
283
|
+
*/
|
|
284
|
+
height: number;
|
|
285
|
+
}): { width: number; height: number };
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Custom unknown data processors.
|
|
289
|
+
*
|
|
290
|
+
* @remarks
|
|
291
|
+
*
|
|
292
|
+
* You may extends the `DataProcessors` interface for better TypeScript types. See {@link DataProcessors}.
|
|
293
|
+
*/
|
|
294
|
+
[processorName: string]: (...args: any[]) => any;
|
|
295
|
+
}
|
|
296
|
+
|
|
221
297
|
/**
|
|
222
298
|
* Definition of DataProcessor(s)
|
|
223
299
|
* @public
|
|
@@ -238,7 +314,7 @@ export interface DataProcessorDefinition {
|
|
|
238
314
|
*
|
|
239
315
|
* @public
|
|
240
316
|
*/
|
|
241
|
-
dataProcessors?:
|
|
317
|
+
dataProcessors?: DataProcessors;
|
|
242
318
|
}
|
|
243
319
|
|
|
244
320
|
/**
|
package/runtime/src/snapshot.ts
CHANGED
|
@@ -165,10 +165,17 @@ export const backgroundSnapshotInstanceManager: {
|
|
|
165
165
|
return null;
|
|
166
166
|
}
|
|
167
167
|
const spreadKey = res[2];
|
|
168
|
-
if (
|
|
169
|
-
|
|
168
|
+
if (res[1] === '__extraProps') {
|
|
169
|
+
if (spreadKey) {
|
|
170
|
+
return ctx.__extraProps![spreadKey];
|
|
171
|
+
}
|
|
172
|
+
throw new Error('unreachable');
|
|
170
173
|
} else {
|
|
171
|
-
|
|
174
|
+
if (spreadKey) {
|
|
175
|
+
return (ctx.__values![expIndex] as { [spreadKey]: unknown })[spreadKey];
|
|
176
|
+
} else {
|
|
177
|
+
return ctx.__values![expIndex];
|
|
178
|
+
}
|
|
172
179
|
}
|
|
173
180
|
},
|
|
174
181
|
};
|
|
@@ -241,6 +248,7 @@ export interface SerializedSnapshotInstance {
|
|
|
241
248
|
id: number;
|
|
242
249
|
type: string;
|
|
243
250
|
values?: any[] | undefined;
|
|
251
|
+
extraProps?: Record<string, unknown> | undefined;
|
|
244
252
|
children?: SerializedSnapshotInstance[] | undefined;
|
|
245
253
|
}
|
|
246
254
|
|
|
@@ -263,6 +271,7 @@ export class SnapshotInstance {
|
|
|
263
271
|
__current_slot_index = 0;
|
|
264
272
|
__worklet_ref_set?: Set<WorkletRefImpl<any> | Worklet>;
|
|
265
273
|
__listItemPlatformInfo?: PlatformInfo;
|
|
274
|
+
__extraProps?: Record<string, unknown> | undefined;
|
|
266
275
|
|
|
267
276
|
constructor(public type: string, id?: number) {
|
|
268
277
|
this.__snapshot_def = snapshotManager.values.get(type)!;
|
|
@@ -596,9 +605,14 @@ export class SnapshotInstance {
|
|
|
596
605
|
return;
|
|
597
606
|
}
|
|
598
607
|
|
|
599
|
-
|
|
608
|
+
if (typeof key === 'string') {
|
|
609
|
+
// for more flexible usage, we allow setting non-indexed attributes
|
|
610
|
+
(this.__extraProps ??= {})[key] = value;
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
|
|
600
614
|
this.__values ??= [];
|
|
601
|
-
this.callUpdateIfNotDirectOrDeepEqual(
|
|
615
|
+
this.callUpdateIfNotDirectOrDeepEqual(key, this.__values[key], this.__values[key] = value);
|
|
602
616
|
}
|
|
603
617
|
|
|
604
618
|
toJSON(): Omit<SerializedSnapshotInstance, 'children'> & { children: SnapshotInstance[] | undefined } {
|
|
@@ -606,6 +620,7 @@ export class SnapshotInstance {
|
|
|
606
620
|
id: this.__id,
|
|
607
621
|
type: this.type,
|
|
608
622
|
values: this.__values,
|
|
623
|
+
extraProps: this.__extraProps,
|
|
609
624
|
children: this.__firstChild ? this.childNodes : undefined,
|
|
610
625
|
};
|
|
611
626
|
}
|
package/runtime/src/utils.ts
CHANGED
|
@@ -33,3 +33,12 @@ export function pick<T extends object, K extends keyof T>(obj: T, keys: Iterable
|
|
|
33
33
|
}
|
|
34
34
|
return result as Pick<T, K>;
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
export function maybePromise<T>(value: unknown): value is Promise<T> {
|
|
38
|
+
return (
|
|
39
|
+
typeof value === 'object'
|
|
40
|
+
&& value !== null
|
|
41
|
+
// @ts-expect-error the check is safe
|
|
42
|
+
&& typeof value.then === 'function'
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -171,9 +171,12 @@ const initElementTree = ()=>{
|
|
|
171
171
|
}
|
|
172
172
|
__RemoveElement(parent, child) {
|
|
173
173
|
let ch = parent.firstChild;
|
|
174
|
-
while(ch)
|
|
175
|
-
|
|
176
|
-
|
|
174
|
+
while(ch){
|
|
175
|
+
if (ch === child) {
|
|
176
|
+
parent.removeChild(ch);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
ch = ch.nextSibling;
|
|
177
180
|
}
|
|
178
181
|
}
|
|
179
182
|
__InsertElementBefore(parent, child, ref) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { act } from 'preact/test-utils';
|
|
1
2
|
import { ARIARole } from 'aria-query';
|
|
2
3
|
import { ComponentChild } from 'preact';
|
|
3
4
|
import { ComponentType } from 'preact';
|
|
@@ -5,6 +6,8 @@ import { JSDOM } from 'jsdom';
|
|
|
5
6
|
import { OptionsReceived } from 'pretty-format';
|
|
6
7
|
import * as prettyFormat from 'pretty-format';
|
|
7
8
|
|
|
9
|
+
export { act }
|
|
10
|
+
|
|
8
11
|
export declare type AllByAttribute = (
|
|
9
12
|
attribute: string,
|
|
10
13
|
container: HTMLElement,
|
|
@@ -1493,7 +1496,7 @@ export declare interface waitForOptions {
|
|
|
1493
1496
|
*
|
|
1494
1497
|
* It will be useful when you want to wait for the next event loop to finish.
|
|
1495
1498
|
*
|
|
1496
|
-
* @
|
|
1499
|
+
* @deprecated Please use `act` instead
|
|
1497
1500
|
*/
|
|
1498
1501
|
export declare function waitSchedule(): Promise<void>;
|
|
1499
1502
|
|
|
@@ -14588,7 +14588,9 @@ function pure_render(ui, { queries, wrapper: WrapperComponent, enableMainThread
|
|
|
14588
14588
|
const compBackgroundThread = cloneElement(comp);
|
|
14589
14589
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
14590
14590
|
__root.__jsx = enableMainThread ? compMainThread : null;
|
|
14591
|
-
|
|
14591
|
+
act(()=>{
|
|
14592
|
+
renderPage();
|
|
14593
|
+
});
|
|
14592
14594
|
if (enableBackgroundThread) {
|
|
14593
14595
|
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
14594
14596
|
act(()=>{
|
|
@@ -14725,4 +14727,4 @@ var __webpack_exports__waitForElementToBeRemoved = dom_esm.mz;
|
|
|
14725
14727
|
var __webpack_exports__within = dom_esm.uh;
|
|
14726
14728
|
var __webpack_exports__wrapAllByQueryWithSuggestion = dom_esm.bH;
|
|
14727
14729
|
var __webpack_exports__wrapSingleQueryWithSuggestion = dom_esm.kG;
|
|
14728
|
-
export { cleanup, fireEvent, pure_render as render, renderHook, waitSchedule, __webpack_exports__buildQueries as buildQueries, __webpack_exports__configure as configure, __webpack_exports__createEvent as createEvent, __webpack_exports__findAllByAltText as findAllByAltText, __webpack_exports__findAllByDisplayValue as findAllByDisplayValue, __webpack_exports__findAllByLabelText as findAllByLabelText, __webpack_exports__findAllByPlaceholderText as findAllByPlaceholderText, __webpack_exports__findAllByRole as findAllByRole, __webpack_exports__findAllByTestId as findAllByTestId, __webpack_exports__findAllByText as findAllByText, __webpack_exports__findAllByTitle as findAllByTitle, __webpack_exports__findByAltText as findByAltText, __webpack_exports__findByDisplayValue as findByDisplayValue, __webpack_exports__findByLabelText as findByLabelText, __webpack_exports__findByPlaceholderText as findByPlaceholderText, __webpack_exports__findByRole as findByRole, __webpack_exports__findByTestId as findByTestId, __webpack_exports__findByText as findByText, __webpack_exports__findByTitle as findByTitle, __webpack_exports__getAllByAltText as getAllByAltText, __webpack_exports__getAllByDisplayValue as getAllByDisplayValue, __webpack_exports__getAllByLabelText as getAllByLabelText, __webpack_exports__getAllByPlaceholderText as getAllByPlaceholderText, __webpack_exports__getAllByRole as getAllByRole, __webpack_exports__getAllByTestId as getAllByTestId, __webpack_exports__getAllByText as getAllByText, __webpack_exports__getAllByTitle as getAllByTitle, __webpack_exports__getByAltText as getByAltText, __webpack_exports__getByDisplayValue as getByDisplayValue, __webpack_exports__getByLabelText as getByLabelText, __webpack_exports__getByPlaceholderText as getByPlaceholderText, __webpack_exports__getByRole as getByRole, __webpack_exports__getByTestId as getByTestId, __webpack_exports__getByText as getByText, __webpack_exports__getByTitle as getByTitle, __webpack_exports__getConfig as getConfig, __webpack_exports__getDefaultNormalizer as getDefaultNormalizer, __webpack_exports__getElementError as getElementError, __webpack_exports__getMultipleElementsFoundError as getMultipleElementsFoundError, __webpack_exports__getNodeText as getNodeText, __webpack_exports__getQueriesForElement as getQueriesForElement, __webpack_exports__getRoles as getRoles, __webpack_exports__getSuggestedQuery as getSuggestedQuery, __webpack_exports__isInaccessible as isInaccessible, __webpack_exports__logDOM as logDOM, __webpack_exports__logRoles as logRoles, __webpack_exports__makeFindQuery as makeFindQuery, __webpack_exports__makeGetAllQuery as makeGetAllQuery, __webpack_exports__makeSingleQuery as makeSingleQuery, __webpack_exports__prettyDOM as prettyDOM, __webpack_exports__prettyFormat as prettyFormat, __webpack_exports__queries as queries, __webpack_exports__queryAllByAltText as queryAllByAltText, __webpack_exports__queryAllByAttribute as queryAllByAttribute, __webpack_exports__queryAllByDisplayValue as queryAllByDisplayValue, __webpack_exports__queryAllByLabelText as queryAllByLabelText, __webpack_exports__queryAllByPlaceholderText as queryAllByPlaceholderText, __webpack_exports__queryAllByRole as queryAllByRole, __webpack_exports__queryAllByTestId as queryAllByTestId, __webpack_exports__queryAllByText as queryAllByText, __webpack_exports__queryAllByTitle as queryAllByTitle, __webpack_exports__queryByAltText as queryByAltText, __webpack_exports__queryByAttribute as queryByAttribute, __webpack_exports__queryByDisplayValue as queryByDisplayValue, __webpack_exports__queryByLabelText as queryByLabelText, __webpack_exports__queryByPlaceholderText as queryByPlaceholderText, __webpack_exports__queryByRole as queryByRole, __webpack_exports__queryByTestId as queryByTestId, __webpack_exports__queryByText as queryByText, __webpack_exports__queryByTitle as queryByTitle, __webpack_exports__queryHelpers as queryHelpers, __webpack_exports__screen as screen, __webpack_exports__waitFor as waitFor, __webpack_exports__waitForElementToBeRemoved as waitForElementToBeRemoved, __webpack_exports__within as within, __webpack_exports__wrapAllByQueryWithSuggestion as wrapAllByQueryWithSuggestion, __webpack_exports__wrapSingleQueryWithSuggestion as wrapSingleQueryWithSuggestion };
|
|
14730
|
+
export { act, cleanup, fireEvent, pure_render as render, renderHook, waitSchedule, __webpack_exports__buildQueries as buildQueries, __webpack_exports__configure as configure, __webpack_exports__createEvent as createEvent, __webpack_exports__findAllByAltText as findAllByAltText, __webpack_exports__findAllByDisplayValue as findAllByDisplayValue, __webpack_exports__findAllByLabelText as findAllByLabelText, __webpack_exports__findAllByPlaceholderText as findAllByPlaceholderText, __webpack_exports__findAllByRole as findAllByRole, __webpack_exports__findAllByTestId as findAllByTestId, __webpack_exports__findAllByText as findAllByText, __webpack_exports__findAllByTitle as findAllByTitle, __webpack_exports__findByAltText as findByAltText, __webpack_exports__findByDisplayValue as findByDisplayValue, __webpack_exports__findByLabelText as findByLabelText, __webpack_exports__findByPlaceholderText as findByPlaceholderText, __webpack_exports__findByRole as findByRole, __webpack_exports__findByTestId as findByTestId, __webpack_exports__findByText as findByText, __webpack_exports__findByTitle as findByTitle, __webpack_exports__getAllByAltText as getAllByAltText, __webpack_exports__getAllByDisplayValue as getAllByDisplayValue, __webpack_exports__getAllByLabelText as getAllByLabelText, __webpack_exports__getAllByPlaceholderText as getAllByPlaceholderText, __webpack_exports__getAllByRole as getAllByRole, __webpack_exports__getAllByTestId as getAllByTestId, __webpack_exports__getAllByText as getAllByText, __webpack_exports__getAllByTitle as getAllByTitle, __webpack_exports__getByAltText as getByAltText, __webpack_exports__getByDisplayValue as getByDisplayValue, __webpack_exports__getByLabelText as getByLabelText, __webpack_exports__getByPlaceholderText as getByPlaceholderText, __webpack_exports__getByRole as getByRole, __webpack_exports__getByTestId as getByTestId, __webpack_exports__getByText as getByText, __webpack_exports__getByTitle as getByTitle, __webpack_exports__getConfig as getConfig, __webpack_exports__getDefaultNormalizer as getDefaultNormalizer, __webpack_exports__getElementError as getElementError, __webpack_exports__getMultipleElementsFoundError as getMultipleElementsFoundError, __webpack_exports__getNodeText as getNodeText, __webpack_exports__getQueriesForElement as getQueriesForElement, __webpack_exports__getRoles as getRoles, __webpack_exports__getSuggestedQuery as getSuggestedQuery, __webpack_exports__isInaccessible as isInaccessible, __webpack_exports__logDOM as logDOM, __webpack_exports__logRoles as logRoles, __webpack_exports__makeFindQuery as makeFindQuery, __webpack_exports__makeGetAllQuery as makeGetAllQuery, __webpack_exports__makeSingleQuery as makeSingleQuery, __webpack_exports__prettyDOM as prettyDOM, __webpack_exports__prettyFormat as prettyFormat, __webpack_exports__queries as queries, __webpack_exports__queryAllByAltText as queryAllByAltText, __webpack_exports__queryAllByAttribute as queryAllByAttribute, __webpack_exports__queryAllByDisplayValue as queryAllByDisplayValue, __webpack_exports__queryAllByLabelText as queryAllByLabelText, __webpack_exports__queryAllByPlaceholderText as queryAllByPlaceholderText, __webpack_exports__queryAllByRole as queryAllByRole, __webpack_exports__queryAllByTestId as queryAllByTestId, __webpack_exports__queryAllByText as queryAllByText, __webpack_exports__queryAllByTitle as queryAllByTitle, __webpack_exports__queryByAltText as queryByAltText, __webpack_exports__queryByAttribute as queryByAttribute, __webpack_exports__queryByDisplayValue as queryByDisplayValue, __webpack_exports__queryByLabelText as queryByLabelText, __webpack_exports__queryByPlaceholderText as queryByPlaceholderText, __webpack_exports__queryByRole as queryByRole, __webpack_exports__queryByTestId as queryByTestId, __webpack_exports__queryByText as queryByText, __webpack_exports__queryByTitle as queryByTitle, __webpack_exports__queryHelpers as queryHelpers, __webpack_exports__screen as screen, __webpack_exports__waitFor as waitFor, __webpack_exports__waitForElementToBeRemoved as waitForElementToBeRemoved, __webpack_exports__within as within, __webpack_exports__wrapAllByQueryWithSuggestion as wrapAllByQueryWithSuggestion, __webpack_exports__wrapSingleQueryWithSuggestion as wrapSingleQueryWithSuggestion };
|
|
@@ -28,7 +28,7 @@ globalThis.onInitWorkletRuntime = ()=>{
|
|
|
28
28
|
return true;
|
|
29
29
|
};
|
|
30
30
|
globalThis.onInjectMainThreadGlobals = (target)=>{
|
|
31
|
-
if (onInjectMainThreadGlobals) onInjectMainThreadGlobals();
|
|
31
|
+
if (onInjectMainThreadGlobals) onInjectMainThreadGlobals(target);
|
|
32
32
|
if (process.env.DEBUG) console.log('onInjectMainThreadGlobals');
|
|
33
33
|
snapshotInstanceManager.clear();
|
|
34
34
|
snapshotInstanceManager.nextId = 0;
|
|
@@ -56,7 +56,7 @@ globalThis.onInjectMainThreadGlobals = (target)=>{
|
|
|
56
56
|
target.globalPipelineOptions = void 0;
|
|
57
57
|
};
|
|
58
58
|
globalThis.onInjectBackgroundThreadGlobals = (target)=>{
|
|
59
|
-
if (onInjectBackgroundThreadGlobals) onInjectBackgroundThreadGlobals();
|
|
59
|
+
if (onInjectBackgroundThreadGlobals) onInjectBackgroundThreadGlobals(target);
|
|
60
60
|
if (process.env.DEBUG) console.log('onInjectBackgroundThreadGlobals');
|
|
61
61
|
backgroundSnapshotInstanceManager.clear();
|
|
62
62
|
backgroundSnapshotInstanceManager.nextId = 0;
|
|
@@ -16,7 +16,39 @@ async function ensurePackagesInstalled() {
|
|
|
16
16
|
}
|
|
17
17
|
const createVitestConfig = async (options)=>{
|
|
18
18
|
await ensurePackagesInstalled();
|
|
19
|
-
const
|
|
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
|
+
]
|
|
26
|
+
}));
|
|
27
|
+
const preactDir = path.dirname(vitest_config_require.resolve('preact/package.json', {
|
|
28
|
+
paths: [
|
|
29
|
+
runtimeOSSDir
|
|
30
|
+
]
|
|
31
|
+
}));
|
|
32
|
+
const generateAlias = (pkgName, pkgDir, resolveDir)=>{
|
|
33
|
+
const pkgExports = vitest_config_require(path.join(pkgDir, 'package.json')).exports;
|
|
34
|
+
const pkgAlias = [];
|
|
35
|
+
Object.keys(pkgExports).forEach((key)=>{
|
|
36
|
+
const name = path.posix.join(pkgName, key);
|
|
37
|
+
pkgAlias.push({
|
|
38
|
+
find: new RegExp('^' + name + '$'),
|
|
39
|
+
replacement: vitest_config_require.resolve(name, {
|
|
40
|
+
paths: [
|
|
41
|
+
resolveDir
|
|
42
|
+
]
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return pkgAlias;
|
|
47
|
+
};
|
|
48
|
+
const runtimeOSSAlias = generateAlias(runtimeOSSPkgName, runtimeOSSDir, runtimeDir);
|
|
49
|
+
let runtimeAlias = [];
|
|
50
|
+
if (runtimePkgName !== runtimeOSSPkgName) runtimeAlias = generateAlias(runtimePkgName, runtimeDir, vitest_config_dirname);
|
|
51
|
+
const preactAlias = generateAlias('preact', preactDir, runtimeOSSDir);
|
|
20
52
|
function transformReactLynxPlugin() {
|
|
21
53
|
return {
|
|
22
54
|
name: 'transformReactLynxPlugin',
|
|
@@ -83,6 +115,11 @@ const createVitestConfig = async (options)=>{
|
|
|
83
115
|
globals: true,
|
|
84
116
|
setupFiles: [
|
|
85
117
|
path.join(vitest_config_dirname, 'vitest-global-setup')
|
|
118
|
+
],
|
|
119
|
+
alias: [
|
|
120
|
+
...runtimeOSSAlias,
|
|
121
|
+
...runtimeAlias,
|
|
122
|
+
...preactAlias
|
|
86
123
|
]
|
|
87
124
|
}
|
|
88
125
|
});
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
import { queries, Queries, BoundFunction } from '@testing-library/dom';
|
|
11
11
|
import { LynxElement, type ElementTree, type LynxTestingEnv } from '@lynx-js/testing-environment';
|
|
12
12
|
import { ComponentChild, ComponentType } from 'preact';
|
|
13
|
+
import { act } from 'preact/test-utils';
|
|
13
14
|
export * from '@testing-library/dom';
|
|
14
|
-
export { ElementTree, LynxTestingEnv };
|
|
15
|
+
export { ElementTree, LynxTestingEnv, act };
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* The options for {@link render}.
|
|
@@ -252,6 +253,6 @@ export function renderHook<Result, Props>(
|
|
|
252
253
|
*
|
|
253
254
|
* It will be useful when you want to wait for the next event loop to finish.
|
|
254
255
|
*
|
|
255
|
-
* @
|
|
256
|
+
* @deprecated Please use `act` instead
|
|
256
257
|
*/
|
|
257
258
|
export function waitSchedule(): Promise<void>;
|