@lynx-js/react 0.110.0 → 0.111.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 +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/Page.js.map +1 -1
- 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/Page.ts +1 -1
- package/components/src/index.ts +1 -0
- package/package.json +1 -1
- package/refresh/.turbo/turbo-build.log +1 -1
- 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 +64 -41
- package/runtime/lib/backgroundSnapshot.js.map +1 -1
- package/runtime/lib/compat/initData.d.ts +7 -5
- package/runtime/lib/compat/initData.js +11 -2
- package/runtime/lib/compat/initData.js.map +1 -1
- package/runtime/lib/compat/lynxComponent.js +10 -12
- package/runtime/lib/compat/lynxComponent.js.map +1 -1
- package/runtime/lib/debug/profile.js +1 -0
- package/runtime/lib/debug/profile.js.map +1 -1
- package/runtime/lib/gesture/processGestureBagkround.d.ts +1 -1
- package/runtime/lib/gesture/processGestureBagkround.js +4 -1
- package/runtime/lib/gesture/processGestureBagkround.js.map +1 -1
- package/runtime/lib/gesture/types.js.map +1 -1
- package/runtime/lib/hooks/useLynxGlobalEventListener.d.ts +1 -1
- package/runtime/lib/hydrate.d.ts +1 -1
- package/runtime/lib/hydrate.js +5 -4
- package/runtime/lib/hydrate.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/internal.d.ts +3 -2
- package/runtime/lib/internal.js +3 -2
- package/runtime/lib/internal.js.map +1 -1
- package/runtime/lib/legacy-react-runtime/index.js +1 -1
- package/runtime/lib/legacy-react-runtime/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/snapshotPatchApply.js.map +1 -1
- package/runtime/lib/lifecycle/patch/updateMainThread.js +11 -12
- package/runtime/lib/lifecycle/patch/updateMainThread.js.map +1 -1
- package/runtime/lib/lifecycle/reload.js +1 -1
- package/runtime/lib/lifecycle/reload.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.d.ts +2 -46
- package/runtime/lib/list.js +124 -211
- package/runtime/lib/list.js.map +1 -1
- package/runtime/lib/listUpdateInfo.d.ts +38 -0
- package/runtime/lib/listUpdateInfo.js +152 -0
- package/runtime/lib/listUpdateInfo.js.map +1 -0
- package/runtime/lib/lynx/calledByNative.js +8 -11
- 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 +3 -0
- package/runtime/lib/lynx-api.js.map +1 -1
- package/runtime/lib/lynx.js +1 -0
- package/runtime/lib/lynx.js.map +1 -1
- package/runtime/lib/opcodes.js +2 -1
- package/runtime/lib/opcodes.js.map +1 -1
- package/runtime/lib/pendingListUpdates.d.ts +6 -0
- package/runtime/lib/pendingListUpdates.js +16 -0
- package/runtime/lib/pendingListUpdates.js.map +1 -0
- package/runtime/lib/renderToOpcodes/index.js +7 -7
- package/runtime/lib/renderToOpcodes/index.js.map +1 -1
- package/runtime/lib/snapshot/dynamicPartType.d.ts +12 -0
- package/runtime/lib/snapshot/dynamicPartType.js +17 -0
- package/runtime/lib/snapshot/dynamicPartType.js.map +1 -0
- package/runtime/lib/snapshot/gesture.js +3 -0
- package/runtime/lib/snapshot/gesture.js.map +1 -1
- package/runtime/lib/snapshot/list.d.ts +3 -0
- package/runtime/lib/snapshot/list.js +23 -0
- package/runtime/lib/snapshot/list.js.map +1 -0
- package/runtime/lib/snapshot/platformInfo.d.ts +10 -0
- package/runtime/lib/snapshot/platformInfo.js +6 -3
- package/runtime/lib/snapshot/platformInfo.js.map +1 -1
- package/runtime/lib/snapshot/ref.d.ts +3 -0
- package/runtime/lib/snapshot/ref.js.map +1 -1
- package/runtime/lib/snapshot/spread.d.ts +2 -2
- package/runtime/lib/snapshot/spread.js +4 -5
- package/runtime/lib/snapshot/spread.js.map +1 -1
- package/runtime/lib/snapshot/workletEvent.js +1 -1
- package/runtime/lib/snapshot/workletEvent.js.map +1 -1
- package/runtime/lib/snapshot/workletRef.d.ts +1 -1
- package/runtime/lib/snapshot/workletRef.js.map +1 -1
- package/runtime/lib/snapshot.d.ts +7 -14
- package/runtime/lib/snapshot.js +36 -31
- package/runtime/lib/snapshot.js.map +1 -1
- package/runtime/lib/snapshotInstanceHydrationMap.js.map +1 -1
- package/runtime/lib/utils.d.ts +1 -0
- package/runtime/lib/utils.js +7 -1
- package/runtime/lib/utils.js.map +1 -1
- package/runtime/src/backgroundSnapshot.ts +78 -63
- package/runtime/src/compat/initData.ts +20 -9
- package/runtime/src/compat/lynxComponent.ts +12 -13
- package/runtime/src/debug/profile.ts +1 -0
- package/runtime/src/gesture/processGestureBagkround.ts +5 -1
- package/runtime/src/gesture/types.ts +3 -0
- package/runtime/src/hooks/useLynxGlobalEventListener.ts +1 -1
- package/runtime/src/hydrate.ts +6 -4
- package/runtime/src/index.ts +2 -0
- package/runtime/src/internal.ts +3 -2
- package/runtime/src/legacy-react-runtime/index.ts +1 -1
- package/runtime/src/lifecycle/patch/commit.ts +5 -11
- package/runtime/src/lifecycle/patch/snapshotPatch.ts +9 -9
- package/runtime/src/lifecycle/patch/snapshotPatchApply.ts +1 -1
- package/runtime/src/lifecycle/patch/updateMainThread.ts +11 -12
- package/runtime/src/lifecycle/reload.ts +1 -1
- package/runtime/src/lifecycleConstant.ts +1 -0
- package/runtime/src/list.ts +143 -278
- package/runtime/src/listUpdateInfo.ts +221 -0
- package/runtime/src/lynx/calledByNative.ts +8 -10
- 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 +81 -2
- package/runtime/src/lynx.ts +1 -0
- package/runtime/src/opcodes.ts +2 -1
- package/runtime/src/pendingListUpdates.ts +18 -0
- package/runtime/src/renderToOpcodes/index.ts +7 -7
- package/runtime/src/snapshot/dynamicPartType.ts +16 -0
- package/runtime/src/snapshot/gesture.ts +3 -0
- package/runtime/src/snapshot/list.ts +36 -0
- package/runtime/src/snapshot/platformInfo.ts +19 -5
- package/runtime/src/snapshot/ref.ts +1 -0
- package/runtime/src/snapshot/spread.ts +42 -17
- package/runtime/src/snapshot/workletEvent.ts +1 -1
- package/runtime/src/snapshot/workletRef.ts +1 -1
- package/runtime/src/snapshot.ts +41 -34
- package/runtime/src/snapshotInstanceHydrationMap.ts +1 -1
- package/runtime/src/utils.ts +12 -3
- package/testing-library/dist/env/vitest.js +3 -3
- package/testing-library/dist/index.d.ts +4 -1
- package/testing-library/dist/pure.js +1 -1
- package/testing-library/dist/vitest.config.js +45 -8
- package/testing-library/types/entry.d.ts +3 -2
- package/transform/cjs/main.cjs +4 -0
- package/transform/dist/wasm.cjs +1 -1
- package/types/react.d.ts +21 -1
- package/types/react.docs.d.ts +1 -1
package/runtime/src/utils.ts
CHANGED
|
@@ -14,7 +14,7 @@ export function isDirectOrDeepEqual(a: any, b: any): boolean {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function isEmptyObject(obj?: object): obj is Record<string, never> {
|
|
17
|
-
for (
|
|
17
|
+
for (const _ in obj) return false;
|
|
18
18
|
return true;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -25,11 +25,20 @@ export function isSdkVersionGt(major: number, minor: number): boolean {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function pick<T extends object, K extends keyof T>(obj: T, keys: Iterable<K>): Pick<T, K> {
|
|
28
|
-
const result:
|
|
28
|
+
const result: Partial<Pick<T, K>> = {};
|
|
29
29
|
for (const key of keys) {
|
|
30
30
|
if (key in obj) {
|
|
31
31
|
result[key] = obj[key];
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
return result
|
|
34
|
+
return result as Pick<T, K>;
|
|
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
|
+
);
|
|
35
44
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { builtinEnvironments } from "vitest/environments";
|
|
2
|
-
import
|
|
2
|
+
import events from "events";
|
|
3
3
|
function util_define(object, properties) {
|
|
4
4
|
for (const name of Object.getOwnPropertyNames(properties)){
|
|
5
5
|
const propDesc = Object.getOwnPropertyDescriptor(properties, name);
|
|
@@ -321,7 +321,7 @@ function createPolyfills() {
|
|
|
321
321
|
]);
|
|
322
322
|
}
|
|
323
323
|
};
|
|
324
|
-
const ee = new
|
|
324
|
+
const ee = new events();
|
|
325
325
|
ee.dispatchEvent = ({ type, data })=>{
|
|
326
326
|
const isMainThread = __MAIN_THREAD__;
|
|
327
327
|
lynxTestingEnv.switchToBackgroundThread();
|
|
@@ -428,7 +428,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
|
|
|
428
428
|
updateData: {}
|
|
429
429
|
}
|
|
430
430
|
};
|
|
431
|
-
const globalEventEmitter = new
|
|
431
|
+
const globalEventEmitter = new events();
|
|
432
432
|
globalEventEmitter.trigger = globalEventEmitter.emit;
|
|
433
433
|
globalEventEmitter.toggle = globalEventEmitter.emit;
|
|
434
434
|
target.lynx = {
|
|
@@ -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
|
|
|
@@ -14725,4 +14725,4 @@ var __webpack_exports__waitForElementToBeRemoved = dom_esm.mz;
|
|
|
14725
14725
|
var __webpack_exports__within = dom_esm.uh;
|
|
14726
14726
|
var __webpack_exports__wrapAllByQueryWithSuggestion = dom_esm.bH;
|
|
14727
14727
|
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 };
|
|
14728
|
+
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 };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { defineConfig } from "vitest/config";
|
|
2
2
|
import { VitestPackageInstaller } from "vitest/node";
|
|
3
|
-
import
|
|
3
|
+
import path from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
import { createRequire } from "module";
|
|
6
6
|
const vitest_config_filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const vitest_config_dirname =
|
|
7
|
+
const vitest_config_dirname = path.dirname(vitest_config_filename);
|
|
8
8
|
const vitest_config_require = createRequire(import.meta.url);
|
|
9
9
|
async function ensurePackagesInstalled() {
|
|
10
10
|
const installer = new VitestPackageInstaller();
|
|
@@ -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',
|
|
@@ -28,8 +60,8 @@ const createVitestConfig = async (options)=>{
|
|
|
28
60
|
return '';
|
|
29
61
|
}
|
|
30
62
|
const { transformReactLynxSync } = vitest_config_require('@lynx-js/react/transform');
|
|
31
|
-
const relativePath = normalizeSlashes(
|
|
32
|
-
const basename =
|
|
63
|
+
const relativePath = normalizeSlashes(path.relative(vitest_config_dirname, sourcePath));
|
|
64
|
+
const basename = path.basename(sourcePath);
|
|
33
65
|
const result = transformReactLynxSync(sourceText, {
|
|
34
66
|
mode: 'test',
|
|
35
67
|
pluginName: '',
|
|
@@ -71,7 +103,7 @@ const createVitestConfig = async (options)=>{
|
|
|
71
103
|
server: {
|
|
72
104
|
fs: {
|
|
73
105
|
allow: [
|
|
74
|
-
|
|
106
|
+
path.join(vitest_config_dirname, '..')
|
|
75
107
|
]
|
|
76
108
|
}
|
|
77
109
|
},
|
|
@@ -82,12 +114,17 @@ const createVitestConfig = async (options)=>{
|
|
|
82
114
|
environment: vitest_config_require.resolve('./env/vitest'),
|
|
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
|
});
|
|
89
126
|
};
|
|
90
127
|
function normalizeSlashes(file) {
|
|
91
|
-
return file.replaceAll(
|
|
128
|
+
return file.replaceAll(path.win32.sep, '/');
|
|
92
129
|
}
|
|
93
130
|
export { createVitestConfig };
|
|
@@ -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>;
|
package/transform/cjs/main.cjs
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
2
2
|
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
3
3
|
// LICENSE file in the root directory of this source tree.
|
|
4
|
+
|
|
5
|
+
/* eslint-disable n/no-unpublished-require */
|
|
6
|
+
|
|
4
7
|
const { default: _exports } = require('../dist/wasm.cjs');
|
|
5
8
|
|
|
9
|
+
// eslint-disable-next-line n/no-missing-require
|
|
6
10
|
module.exports = process.env['USE_NAPI'] ? require('../index.cjs') : _exports;
|