From f4cfb70606d46cd4017254c326095432f9c6bcb8 Mon Sep 17 00:00:00 2001
From: Sherry <37186915+Sherry-hue@users.noreply.github.com>
Date: Wed, 7 May 2025 11:50:47 +0800
Subject: [PATCH 1/2] feat(web): support for using lynx.queueMicrotask. (#702)
## Summary
feat: support for using `lynx.queueMicrotask`.
## Checklist
- [x] Tests updated (or not required).
- [x] Documentation updated (or not required).
---
.changeset/cuddly-beans-enter.md | 5 ++++
cspell.jsonc | 1 +
.../web-tests/tests/react.spec.ts | 9 +++++++
.../tests/react/api-queueMicrotask/index.jsx | 26 +++++++++++++++++++
.../background-apis/createBackgroundLynx.ts | 3 +++
5 files changed, 44 insertions(+)
create mode 100644 .changeset/cuddly-beans-enter.md
create mode 100644 packages/web-platform/web-tests/tests/react/api-queueMicrotask/index.jsx
diff --git a/.changeset/cuddly-beans-enter.md b/.changeset/cuddly-beans-enter.md
new file mode 100644
index 0000000000..1fcff226cc
--- /dev/null
+++ b/.changeset/cuddly-beans-enter.md
@@ -0,0 +1,5 @@
+---
+"@lynx-js/web-worker-runtime": patch
+---
+
+feat: support for using `lynx.queueMicrotask`.
diff --git a/cspell.jsonc b/cspell.jsonc
index c656c84e0c..eed288d644 100644
--- a/cspell.jsonc
+++ b/cspell.jsonc
@@ -135,6 +135,7 @@
// lighthouse CI
"lhci",
"lh",
+ "queueMicrotask",
],
// Glob
"ignorePaths": [
diff --git a/packages/web-platform/web-tests/tests/react.spec.ts b/packages/web-platform/web-tests/tests/react.spec.ts
index 1bcf3b78aa..d8a0c072b4 100644
--- a/packages/web-platform/web-tests/tests/react.spec.ts
+++ b/packages/web-platform/web-tests/tests/react.spec.ts
@@ -956,6 +956,15 @@ test.describe('reactlynx3 tests', () => {
await wait(100);
await expect(result).toHaveCSS('background-color', 'rgb(0, 128, 0)'); // green
});
+ test(
+ 'api-queueMicrotask',
+ async ({ page }, { title }) => {
+ await goto(page, title);
+ await wait(200);
+ const target = page.locator('#target');
+ await expect(target).toHaveCSS('background-color', 'rgb(0, 128, 0)'); // green
+ },
+ );
});
test.describe('configs', () => {
diff --git a/packages/web-platform/web-tests/tests/react/api-queueMicrotask/index.jsx b/packages/web-platform/web-tests/tests/react/api-queueMicrotask/index.jsx
new file mode 100644
index 0000000000..8dc1035585
--- /dev/null
+++ b/packages/web-platform/web-tests/tests/react/api-queueMicrotask/index.jsx
@@ -0,0 +1,26 @@
+// Copyright 2023 The Lynx Authors. All rights reserved.
+// Licensed under the Apache License Version 2.0 that can be found in the
+// LICENSE file in the root directory of this source tree.
+import { root, useEffect, useState } from '@lynx-js/react';
+
+function App() {
+ const [color, setColor] = useState('pink');
+ useEffect(() => {
+ lynx.queueMicrotask(() => {
+ setColor('green');
+ });
+ }, []);
+
+ return (
+
+ );
+}
+
+root.render();
diff --git a/packages/web-platform/web-worker-runtime/src/backgroundThread/background-apis/createBackgroundLynx.ts b/packages/web-platform/web-worker-runtime/src/backgroundThread/background-apis/createBackgroundLynx.ts
index e99bd23934..508454c640 100644
--- a/packages/web-platform/web-worker-runtime/src/backgroundThread/background-apis/createBackgroundLynx.ts
+++ b/packages/web-platform/web-worker-runtime/src/backgroundThread/background-apis/createBackgroundLynx.ts
@@ -43,5 +43,8 @@ export function createBackgroundLynx(
mainThreadRpc,
config.customSections,
),
+ queueMicrotask: (callback: () => void) => {
+ queueMicrotask(callback);
+ },
};
}
From 0a616c9d22613666455e9e6e8660a8f5b481adcf Mon Sep 17 00:00:00 2001
From: Yiming Li
Date: Wed, 7 May 2025 14:43:09 +0800
Subject: [PATCH 2/2] feat(testing-library): renaming for better docs (#704)
## Summary
In this PR, we refine our documentation of testing library.
- rename `@lynx-js/test-environment` to `@lynx-js/testing-environment`
- rename `LynxEnv` to `LynxTestingEnv`
- rename `react-lynx-testing-library` to `reactlynx-testing-library`
See also: https://github.com/lynx-family/lynx-website/pull/141
## Checklist
- [ ] Tests updated (or **not required**).
- [x] Documentation updated (or not required).
---
.changeset/fluffy-insects-eat.md | 6 +++
.changeset/young-seals-train.md | 2 +-
packages/react/runtime/src/lynx.ts | 4 +-
packages/react/runtime/src/lynx/env.ts | 2 +-
packages/react/testing-library/README.md | 2 +-
.../react/testing-library/api-extractor.json | 15 ------
.../etc/react-lynx-testing-library.api.md | 8 ++--
packages/react/testing-library/package.json | 5 +-
.../src/__tests__/end-to-end.test.jsx | 6 +--
.../src/__tests__/rerender.test.jsx | 2 +-
.../react/testing-library/src/env/vitest.ts | 2 +-
.../react/testing-library/src/fire-event.ts | 8 ++--
packages/react/testing-library/src/index.jsx | 4 +-
packages/react/testing-library/src/pure.jsx | 18 +++----
.../src/vitest-global-setup.js | 20 ++++----
packages/react/testing-library/turbo.json | 2 +-
.../react/testing-library/types/entry.d.ts | 4 +-
.../react/testing-library/types/index.d.ts | 6 +--
packages/react/turbo.json | 4 +-
packages/testing-library/README.md | 2 +-
.../CHANGELOG.md | 2 +-
.../README.md | 24 +++++-----
.../api-extractor.json | 0
.../etc/test-environment.api.md | 6 +--
.../package.json | 2 +-
.../rslib.config.ts | 0
.../src/__tests__/basic.test.js | 6 +--
.../__tests__/to-have-text-content.test.js | 36 +++++++-------
.../src/env/vitest/index.ts | 10 ++--
.../src/index.ts | 48 +++++++++----------
.../src/lynx/ElementPAPI.ts | 20 ++++----
.../src/lynx/GlobalThis.ts | 0
.../src/util.ts | 0
.../tsconfig.json | 0
.../turbo.json | 0
.../vitest.config.mts | 0
pnpm-lock.yaml | 6 +--
37 files changed, 137 insertions(+), 145 deletions(-)
create mode 100644 .changeset/fluffy-insects-eat.md
delete mode 100644 packages/react/testing-library/api-extractor.json
rename packages/testing-library/{test-environment => testing-environment}/CHANGELOG.md (80%)
rename packages/testing-library/{test-environment => testing-environment}/README.md (54%)
rename packages/testing-library/{test-environment => testing-environment}/api-extractor.json (100%)
rename packages/testing-library/{test-environment => testing-environment}/etc/test-environment.api.md (97%)
rename packages/testing-library/{test-environment => testing-environment}/package.json (97%)
rename packages/testing-library/{test-environment => testing-environment}/rslib.config.ts (100%)
rename packages/testing-library/{test-environment => testing-environment}/src/__tests__/basic.test.js (97%)
rename packages/testing-library/{test-environment => testing-environment}/src/__tests__/to-have-text-content.test.js (91%)
rename packages/testing-library/{test-environment => testing-environment}/src/env/vitest/index.ts (63%)
rename packages/testing-library/{test-environment => testing-environment}/src/index.ts (90%)
rename packages/testing-library/{test-environment => testing-environment}/src/lynx/ElementPAPI.ts (96%)
rename packages/testing-library/{test-environment => testing-environment}/src/lynx/GlobalThis.ts (100%)
rename packages/testing-library/{test-environment => testing-environment}/src/util.ts (100%)
rename packages/testing-library/{test-environment => testing-environment}/tsconfig.json (100%)
rename packages/testing-library/{test-environment => testing-environment}/turbo.json (100%)
rename packages/testing-library/{test-environment => testing-environment}/vitest.config.mts (100%)
diff --git a/.changeset/fluffy-insects-eat.md b/.changeset/fluffy-insects-eat.md
new file mode 100644
index 0000000000..c95e7c11b2
--- /dev/null
+++ b/.changeset/fluffy-insects-eat.md
@@ -0,0 +1,6 @@
+---
+"@lynx-js/testing-environment": patch
+"@lynx-js/react": patch
+---
+
+rename @lynx-js/test-environment to @lynx-js/testing-environment
diff --git a/.changeset/young-seals-train.md b/.changeset/young-seals-train.md
index 048920de7e..2cce760f2f 100644
--- a/.changeset/young-seals-train.md
+++ b/.changeset/young-seals-train.md
@@ -1,5 +1,5 @@
---
-"@lynx-js/test-environment": minor
+"@lynx-js/testing-environment": minor
---
Switch to ESM package format by setting `"type": "module"`.
diff --git a/packages/react/runtime/src/lynx.ts b/packages/react/runtime/src/lynx.ts
index 87f241e0a7..7ad7474499 100644
--- a/packages/react/runtime/src/lynx.ts
+++ b/packages/react/runtime/src/lynx.ts
@@ -11,7 +11,7 @@ import { initDelayUnmount } from './lifecycle/delayUnmount.js';
import { replaceCommitHook, replaceRequestAnimationFrame } from './lifecycle/patch/commit.js';
import { injectUpdateMainThread } from './lifecycle/patch/updateMainThread.js';
import { injectCalledByNative } from './lynx/calledByNative.js';
-import { setupLynxEnv } from './lynx/env.js';
+import { setupLynxTestingEnv } from './lynx/env.js';
import { injectLepusMethods } from './lynx/injectLepusMethods.js';
import { initTimingAPI } from './lynx/performance.js';
import { injectTt } from './lynx/tt.js';
@@ -53,4 +53,4 @@ if (__JS__) {
}
}
-setupLynxEnv();
+setupLynxTestingEnv();
diff --git a/packages/react/runtime/src/lynx/env.ts b/packages/react/runtime/src/lynx/env.ts
index a2ba5a91a0..f86a0e6e2f 100644
--- a/packages/react/runtime/src/lynx/env.ts
+++ b/packages/react/runtime/src/lynx/env.ts
@@ -3,7 +3,7 @@
// LICENSE file in the root directory of this source tree.
import type { DataProcessorDefinition } from '../lynx-api.js';
-export function setupLynxEnv(): void {
+export function setupLynxTestingEnv(): void {
if (!__LEPUS__) {
const { initData, updateData } = lynxCoreInject.tt._params;
// @ts-ignore
diff --git a/packages/react/testing-library/README.md b/packages/react/testing-library/README.md
index 2e4f006ea3..b14b28d9e6 100644
--- a/packages/react/testing-library/README.md
+++ b/packages/react/testing-library/README.md
@@ -58,7 +58,7 @@ test('renders options.wrapper around node', async () => {
});
```
-💡 Since our testing environment (`@lynx-js/test-environment`) is based on jsdom, You may also be interested in installing `@testing-library/jest-dom` so you can use
+💡 Since our testing environment (`@lynx-js/testing-environment`) is based on jsdom, You may also be interested in installing `@testing-library/jest-dom` so you can use
[the custom jest matchers](https://github.com/testing-library/jest-dom).
## Examples
diff --git a/packages/react/testing-library/api-extractor.json b/packages/react/testing-library/api-extractor.json
deleted file mode 100644
index c275eb4cf6..0000000000
--- a/packages/react/testing-library/api-extractor.json
+++ /dev/null
@@ -1,15 +0,0 @@
-/**
- * Config file for API Extractor. For more info, please visit: https://api-extractor.com
- */
-{
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
- "extends": "../../../api-extractor.json",
- "mainEntryPointFilePath": "/types/entry.d.ts",
- "compiler": {
- "overrideTsconfig": {
- "compilerOptions": {
- "skipLibCheck": true,
- },
- },
- },
-}
diff --git a/packages/react/testing-library/etc/react-lynx-testing-library.api.md b/packages/react/testing-library/etc/react-lynx-testing-library.api.md
index 73d2b96c32..53f6f051e1 100644
--- a/packages/react/testing-library/etc/react-lynx-testing-library.api.md
+++ b/packages/react/testing-library/etc/react-lynx-testing-library.api.md
@@ -7,9 +7,9 @@
import { BoundFunction } from '@testing-library/dom';
import { ComponentChild } from 'preact';
import { ComponentType } from 'preact';
-import { ElementTree } from '@lynx-js/test-environment';
-import { LynxElement } from '@lynx-js/test-environment';
-import { LynxEnv } from '@lynx-js/test-environment';
+import { ElementTree } from '@lynx-js/testing-environment';
+import { LynxElement } from '@lynx-js/testing-environment';
+import { LynxTestingEnv } from '@lynx-js/testing-environment';
import { Queries } from '@testing-library/dom';
import { queries } from '@testing-library/dom';
@@ -18,7 +18,7 @@ export function cleanup(): void;
export { ElementTree }
-export { LynxEnv }
+export { LynxTestingEnv }
// @public
export function render(
diff --git a/packages/react/testing-library/package.json b/packages/react/testing-library/package.json
index f6053c1f4e..68191d4143 100644
--- a/packages/react/testing-library/package.json
+++ b/packages/react/testing-library/package.json
@@ -1,10 +1,9 @@
{
- "name": "@lynx-js/react-lynx-testing-library",
+ "name": "@lynx-js/reactlynx-testing-library",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
- "api-extractor": "api-extractor run --verbose",
"build": "rslib build",
"dev": "rslib build --watch",
"test": "vitest",
@@ -12,7 +11,7 @@
},
"devDependencies": {
"@lynx-js/react": "workspace:*",
- "@lynx-js/test-environment": "workspace:*",
+ "@lynx-js/testing-environment": "workspace:*",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3"
}
diff --git a/packages/react/testing-library/src/__tests__/end-to-end.test.jsx b/packages/react/testing-library/src/__tests__/end-to-end.test.jsx
index e806d66bc7..6b368299db 100644
--- a/packages/react/testing-library/src/__tests__/end-to-end.test.jsx
+++ b/packages/react/testing-library/src/__tests__/end-to-end.test.jsx
@@ -88,9 +88,9 @@ test('state change will cause re-render', async () => {
const isBackground = !__MAIN_THREAD__;
- const callLepusMethod = lynxEnv.backgroundThread.lynx.getNativeApp().callLepusMethod;
+ const callLepusMethod = lynxTestingEnv.backgroundThread.lynx.getNativeApp().callLepusMethod;
// callLepusMethodCalls such as rLynxChange
- globalThis.lynxEnv.switchToMainThread();
+ globalThis.lynxTestingEnv.switchToMainThread();
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`
[
[
@@ -133,7 +133,7 @@ test('state change will cause re-render', async () => {
// restore the original thread state
if (isBackground) {
- globalThis.lynxEnv.switchToBackgroundThread();
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
}
expect(elementTree.root).toMatchInlineSnapshot(`
diff --git a/packages/react/testing-library/src/__tests__/rerender.test.jsx b/packages/react/testing-library/src/__tests__/rerender.test.jsx
index 1a5bf23d44..753b990ff0 100644
--- a/packages/react/testing-library/src/__tests__/rerender.test.jsx
+++ b/packages/react/testing-library/src/__tests__/rerender.test.jsx
@@ -45,7 +45,7 @@ test('rerender will flush pending hooks effects', async () => {
const { rerender } = render();
const { findByText } = rerender();
vi.spyOn(lynx.getNativeApp(), 'callLepusMethod');
- const callLepusMethod = lynxEnv.backgroundThread.lynx.getNativeApp().callLepusMethod;
+ const callLepusMethod = lynxTestingEnv.backgroundThread.lynx.getNativeApp().callLepusMethod;
expect(callLepusMethod.mock.calls).toMatchInlineSnapshot(`[]`);
await findByText('1');
diff --git a/packages/react/testing-library/src/env/vitest.ts b/packages/react/testing-library/src/env/vitest.ts
index 9dcf051390..cf89eb9fdb 100644
--- a/packages/react/testing-library/src/env/vitest.ts
+++ b/packages/react/testing-library/src/env/vitest.ts
@@ -1,3 +1,3 @@
-import env from '@lynx-js/test-environment/env/vitest';
+import env from '@lynx-js/testing-environment/env/vitest';
export default env;
diff --git a/packages/react/testing-library/src/fire-event.ts b/packages/react/testing-library/src/fire-event.ts
index 3c2212afd9..602c9e8e7d 100644
--- a/packages/react/testing-library/src/fire-event.ts
+++ b/packages/react/testing-library/src/fire-event.ts
@@ -21,7 +21,7 @@ export const fireEvent: any = (elemOrNodesRef, ...args) => {
const isMainThread = __MAIN_THREAD__;
// switch to background thread
- lynxEnv.switchToBackgroundThread();
+ lynxTestingEnv.switchToBackgroundThread();
const elem = getElement(elemOrNodesRef);
@@ -29,7 +29,7 @@ export const fireEvent: any = (elemOrNodesRef, ...args) => {
if (isMainThread) {
// switch back to main thread
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.switchToMainThread();
}
return ans;
@@ -153,7 +153,7 @@ Object.keys(eventMap).forEach((key) => {
fireEvent[key] = (elemOrNodesRef, init = {}) => {
const isMainThread = __MAIN_THREAD__;
// switch to background thread
- lynxEnv.switchToBackgroundThread();
+ lynxTestingEnv.switchToBackgroundThread();
const elem = getElement(elemOrNodesRef);
const eventType = init?.['eventType'] || 'bindEvent';
@@ -177,7 +177,7 @@ Object.keys(eventMap).forEach((key) => {
if (isMainThread) {
// switch back to main thread
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.switchToMainThread();
}
return ans;
diff --git a/packages/react/testing-library/src/index.jsx b/packages/react/testing-library/src/index.jsx
index 86e73f671d..7f07a2a4d7 100644
--- a/packages/react/testing-library/src/index.jsx
+++ b/packages/react/testing-library/src/index.jsx
@@ -11,13 +11,13 @@ if (
if (typeof afterEach === 'function') {
afterEach(() => {
cleanup();
- lynxEnv.resetLynxEnv();
+ lynxTestingEnv.reset();
});
} else if (typeof teardown === 'function') {
// eslint-disable-next-line no-undef
teardown(() => {
cleanup();
- lynxEnv.resetLynxEnv();
+ lynxTestingEnv.reset();
});
}
}
diff --git a/packages/react/testing-library/src/pure.jsx b/packages/react/testing-library/src/pure.jsx
index 92064e9346..324b432670 100644
--- a/packages/react/testing-library/src/pure.jsx
+++ b/packages/react/testing-library/src/pure.jsx
@@ -59,11 +59,11 @@ export function render(
const compMainThread = cloneElement(comp);
const compBackgroundThread = cloneElement(comp);
- globalThis.lynxEnv.switchToMainThread();
+ globalThis.lynxTestingEnv.switchToMainThread();
__root.__jsx = enableMainThread ? compMainThread : null;
renderPage();
if (enableBackgroundThread) {
- globalThis.lynxEnv.switchToBackgroundThread();
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
act(() => {
preactRender(compBackgroundThread, __root);
flushDelayedLifecycleEvents();
@@ -71,10 +71,10 @@ export function render(
}
return {
- container: lynxEnv.mainThread.elementTree.root,
+ container: lynxTestingEnv.mainThread.elementTree.root,
unmount: cleanup,
rerender: (rerenderUi) => {
- lynxEnv.resetLynxEnv();
+ lynxTestingEnv.reset();
return render(wrapUiIfNeeded(rerenderUi), {
queries,
wrapper: WrapperComponent,
@@ -82,7 +82,7 @@ export function render(
enableBackgroundThread,
});
},
- ...getQueriesForElement(lynxEnv.mainThread.elementTree.root, queries),
+ ...getQueriesForElement(lynxTestingEnv.mainThread.elementTree.root, queries),
};
}
@@ -90,17 +90,17 @@ export function cleanup() {
const isMainThread = __MAIN_THREAD__;
// Ensure componentWillUnmount is called
- globalThis.lynxEnv.switchToBackgroundThread();
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
act(() => {
preactRender(null, __root);
});
- lynxEnv.mainThread.elementTree.root = undefined;
+ lynxTestingEnv.mainThread.elementTree.root = undefined;
clearPage();
- lynxEnv.jsdom.window.document.body.innerHTML = '';
+ lynxTestingEnv.jsdom.window.document.body.innerHTML = '';
if (isMainThread) {
- globalThis.lynxEnv.switchToMainThread();
+ globalThis.lynxTestingEnv.switchToMainThread();
}
}
diff --git a/packages/react/testing-library/src/vitest-global-setup.js b/packages/react/testing-library/src/vitest-global-setup.js
index 3cf3f44542..526a2e9978 100644
--- a/packages/react/testing-library/src/vitest-global-setup.js
+++ b/packages/react/testing-library/src/vitest-global-setup.js
@@ -20,7 +20,7 @@ import { initWorklet } from '../../worklet-runtime/lib/workletRuntime.js';
const {
onInjectMainThreadGlobals,
onInjectBackgroundThreadGlobals,
- onResetLynxEnv,
+ onResetLynxTestingEnv,
onSwitchedToMainThread,
onSwitchedToBackgroundThread,
onInitWorkletRuntime,
@@ -123,7 +123,7 @@ globalThis.onInjectBackgroundThreadGlobals = (target) => {
// TODO: can we only inject to target(mainThread.globalThis) instead of globalThis?
// packages/react/runtime/src/lynx.ts
- // intercept lynxCoreInject assignments to lynxEnv.backgroundThread.globalThis.lynxCoreInject
+ // intercept lynxCoreInject assignments to lynxTestingEnv.backgroundThread.globalThis.lynxCoreInject
const oldLynxCoreInject = globalThis.lynxCoreInject;
globalThis.lynxCoreInject = target.lynxCoreInject;
injectTt();
@@ -133,20 +133,20 @@ globalThis.onInjectBackgroundThreadGlobals = (target) => {
deinitGlobalSnapshotPatch();
clearCommitTaskId();
};
-globalThis.onResetLynxEnv = () => {
- if (onResetLynxEnv) {
- onResetLynxEnv();
+globalThis.onResetLynxTestingEnv = () => {
+ if (onResetLynxTestingEnv) {
+ onResetLynxTestingEnv();
}
if (process.env.DEBUG) {
- console.log('onResetLynxEnv');
+ console.log('onResetLynxTestingEnv');
}
flushDelayedLifecycleEvents();
destroyWorklet();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.switchToMainThread();
initEventListeners();
- lynxEnv.switchToBackgroundThread();
+ lynxTestingEnv.switchToBackgroundThread();
};
globalThis.onSwitchedToMainThread = () => {
@@ -173,8 +173,8 @@ globalThis.onSwitchedToBackgroundThread = () => {
};
globalThis.onInjectMainThreadGlobals(
- globalThis.lynxEnv.mainThread.globalThis,
+ globalThis.lynxTestingEnv.mainThread.globalThis,
);
globalThis.onInjectBackgroundThreadGlobals(
- globalThis.lynxEnv.backgroundThread.globalThis,
+ globalThis.lynxTestingEnv.backgroundThread.globalThis,
);
diff --git a/packages/react/testing-library/turbo.json b/packages/react/testing-library/turbo.json
index 3e8e016168..8b532033f7 100644
--- a/packages/react/testing-library/turbo.json
+++ b/packages/react/testing-library/turbo.json
@@ -5,7 +5,7 @@
"build": {
"dependsOn": [
"@lynx-js/react-transform#build:wasm",
- "@lynx-js/test-environment#build"
+ "@lynx-js/testing-environment#build"
],
"inputs": [
"src"
diff --git a/packages/react/testing-library/types/entry.d.ts b/packages/react/testing-library/types/entry.d.ts
index c7560bf9b8..998c37c55a 100644
--- a/packages/react/testing-library/types/entry.d.ts
+++ b/packages/react/testing-library/types/entry.d.ts
@@ -8,10 +8,10 @@
*/
import { queries, Queries, BoundFunction } from '@testing-library/dom';
-import { LynxElement, type ElementTree, type LynxEnv } from '@lynx-js/test-environment';
+import { LynxElement, type ElementTree, type LynxTestingEnv } from '@lynx-js/testing-environment';
import { ComponentChild, ComponentType } from 'preact';
export * from '@testing-library/dom';
-export { ElementTree, LynxEnv };
+export { ElementTree, LynxTestingEnv };
/**
* The options for {@link render}.
diff --git a/packages/react/testing-library/types/index.d.ts b/packages/react/testing-library/types/index.d.ts
index 6f21459aa8..ebd08d8023 100644
--- a/packages/react/testing-library/types/index.d.ts
+++ b/packages/react/testing-library/types/index.d.ts
@@ -1,15 +1,15 @@
// @ts-nocheck
export * from '../dist/index.d.ts';
-import { ElementTree, LynxEnv } from '../dist/index.d.ts';
+import { ElementTree, LynxTestingEnv } from '../dist/index.d.ts';
declare global {
- var lynxEnv: LynxEnv;
+ var lynxTestingEnv: LynxTestingEnv;
var elementTree: ElementTree;
function onInjectBackgroundThreadGlobals(globals: any): void;
function onInjectMainThreadGlobals(globals: any): void;
function onSwitchedToBackgroundThread(): void;
function onSwitchedToMainThread(): void;
- function onResetLynxEnv(): void;
+ function onResetLynxTestingEnv(): void;
function onInitWorkletRuntime(): void;
}
diff --git a/packages/react/turbo.json b/packages/react/turbo.json
index 96a6732887..de23051e9d 100644
--- a/packages/react/turbo.json
+++ b/packages/react/turbo.json
@@ -7,8 +7,8 @@
"@lynx-js/react-refresh#build",
"@lynx-js/react-transform#build:wasm",
"@lynx-js/react-worklet-runtime#build",
- "@lynx-js/react-lynx-testing-library#build",
- "@lynx-js/test-environment#build"
+ "@lynx-js/reactlynx-testing-library#build",
+ "@lynx-js/testing-environment#build"
]
}
}
diff --git a/packages/testing-library/README.md b/packages/testing-library/README.md
index a236f046d5..a47064aca3 100644
--- a/packages/testing-library/README.md
+++ b/packages/testing-library/README.md
@@ -6,7 +6,7 @@ Unit testing library for lynx, same as https://github.com/testing-library.
| Package | Description | Equivalent |
| ---------------------------------------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------ |
-| [@lynx-js/test-environment](./lynx-environment/) | Lynx equivalent of jsdom | [jsdom](https://github.com/jsdom/jsdom) |
+| [@lynx-js/testing-environment](./lynx-environment/) | Lynx equivalent of jsdom | [jsdom](https://github.com/jsdom/jsdom) |
| [@lynx-js/react/testing-library](../react/testing-library) | Lynx equivalent of preact-testing-library | [@testing-library/preact](https://github.com/testing-library/preact-testing-library) |
## Documentation
diff --git a/packages/testing-library/test-environment/CHANGELOG.md b/packages/testing-library/testing-environment/CHANGELOG.md
similarity index 80%
rename from packages/testing-library/test-environment/CHANGELOG.md
rename to packages/testing-library/testing-environment/CHANGELOG.md
index 0eedb1dd20..e9e81dac5a 100644
--- a/packages/testing-library/test-environment/CHANGELOG.md
+++ b/packages/testing-library/testing-environment/CHANGELOG.md
@@ -1,4 +1,4 @@
-# @lynx-js/test-environment
+# @lynx-js/testing-environment
## 0.0.1
diff --git a/packages/testing-library/test-environment/README.md b/packages/testing-library/testing-environment/README.md
similarity index 54%
rename from packages/testing-library/test-environment/README.md
rename to packages/testing-library/testing-environment/README.md
index ad480507e8..bfac35ad99 100644
--- a/packages/testing-library/test-environment/README.md
+++ b/packages/testing-library/testing-environment/README.md
@@ -1,23 +1,23 @@
-# @lynx-js/test-environment
+# @lynx-js/testing-environment
-`@lynx-js/test-environment` is a pure-JavaScript implementation of the [Lynx Spec](https://lynxjs.org/api/engine/element-api), notably the [Element PAPI](https://lynxjs.org/api/engine/element-api) and [Dual-threaded Model](https://lynxjs.org/guide/spec#dual-threaded-model) for use with Node.js. In general, the goal of the project is to emulate enough of a subset of a Lynx environment to be useful for testing.
+`@lynx-js/testing-environment` is a pure-JavaScript implementation of the [Lynx Spec](https://lynxjs.org/api/engine/element-api), notably the [Element PAPI](https://lynxjs.org/api/engine/element-api) and [Dual-threaded Model](https://lynxjs.org/guide/spec#dual-threaded-model) for use with Node.js. In general, the goal of the project is to emulate enough of a subset of a Lynx environment to be useful for testing.
The Element PAPI implementation is based on jsdom, for example `__CreateElement` will return a `LynxElement`, which extends `HTMLElement` from jsdom. You can reuse the testing utilities that are commonly used for DOM testing, such as [`@testing-library/dom`](https://github.com/testing-library/dom-testing-library) (for DOM querying) and [`@testing-library/jest-dom`](https://github.com/testing-library/jest-dom) (custom jest matchers for the DOM), etc.
## Usage
```js
-import { LynxEnv } from '@lynx-js/test-environment';
+import { LynxTestingEnv } from '@lynx-js/testing-environment';
-const lynxEnv = new LynxEnv();
+const lynxTestingEnv = new LynxTestingEnv();
```
-To use `@lynx-js/test-environment`, you will primarily use the `LynxEnv` constructor, which is a named export of the package. You will get back a `LynxEnv` instance, which has a number of methods of useful properties, notably `switchToMainThread` and `switchToBackgroundThread`, which allow you to switch between the main thread and background thread.
+To use `@lynx-js/testing-environment`, you will primarily use the `LynxTestingEnv` constructor, which is a named export of the package. You will get back a `LynxTestingEnv` instance, which has a number of methods of useful properties, notably `switchToMainThread` and `switchToBackgroundThread`, which allow you to switch between the main thread and background thread.
Use the background thread API:
```js
-lynxEnv.switchToBackgroundThread();
+lynxTestingEnv.switchToBackgroundThread();
// use the background thread global object
globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
// or directly use `lynxCoreInject` since it's already injected to `globalThis`
@@ -27,7 +27,7 @@ globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
Use the main thread API:
```js
-lynxEnv.switchToMainThread();
+lynxTestingEnv.switchToMainThread();
// use the main thread Element PAPI
const page = __CreatePage('0', 0);
const view = __CreateView(0);
@@ -37,9 +37,9 @@ __AppendElement(page, view);
Note that you can still access the other thread's globals without switching threads:
```js
-lynxEnv.switchToMainThread();
+lynxTestingEnv.switchToMainThread();
// use the `backgroundThread` global object even though we're on the main thread
-lynxEnv.backgroundThread.tt.OnLifecycleEvent(...args);
+lynxTestingEnv.backgroundThread.tt.OnLifecycleEvent(...args);
```
### Use in Vitest
@@ -53,15 +53,15 @@ import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: require.resolve(
- '@lynx-js/test-environment/env/vitest',
+ '@lynx-js/testing-environment/env/vitest',
),
},
});
```
-After configuration, you can directly access the `lynxEnv` object globally in the test.
+After configuration, you can directly access the `lynxTestingEnv` object globally in the test.
-If you want to use `@lynx-js/test-environment` for unit testing in ReactLynx, you usually don't need to specify this configuration manually.
+If you want to use `@lynx-js/testing-environment` for unit testing in ReactLynx, you usually don't need to specify this configuration manually.
Please refer to [ReactLynx Testing Library](https://lynxjs.org/react/react-lynx-testing-library.html) to inherit the configuration from `@lynx-js/react/testing-library`.
diff --git a/packages/testing-library/test-environment/api-extractor.json b/packages/testing-library/testing-environment/api-extractor.json
similarity index 100%
rename from packages/testing-library/test-environment/api-extractor.json
rename to packages/testing-library/testing-environment/api-extractor.json
diff --git a/packages/testing-library/test-environment/etc/test-environment.api.md b/packages/testing-library/testing-environment/etc/test-environment.api.md
similarity index 97%
rename from packages/testing-library/test-environment/etc/test-environment.api.md
rename to packages/testing-library/testing-environment/etc/test-environment.api.md
index 10b8e9dc0e..f3424cbbfc 100644
--- a/packages/testing-library/test-environment/etc/test-environment.api.md
+++ b/packages/testing-library/testing-environment/etc/test-environment.api.md
@@ -1,4 +1,4 @@
-## API Report File for "@lynx-js/test-environment"
+## API Report File for "@lynx-js/testing-environment"
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
@@ -80,7 +80,7 @@ export interface LynxElement extends HTMLElement {
}
// @public
-export class LynxEnv {
+export class LynxTestingEnv {
constructor();
backgroundThread: LynxGlobalThis;
// (undocumented)
@@ -91,7 +91,7 @@ export class LynxEnv {
jsdom: JSDOM;
mainThread: LynxGlobalThis & ElementTreeGlobals;
// (undocumented)
- resetLynxEnv(): void;
+ reset(): void;
// (undocumented)
switchToBackgroundThread(): void;
// (undocumented)
diff --git a/packages/testing-library/test-environment/package.json b/packages/testing-library/testing-environment/package.json
similarity index 97%
rename from packages/testing-library/test-environment/package.json
rename to packages/testing-library/testing-environment/package.json
index f899154167..fbadd1de32 100644
--- a/packages/testing-library/test-environment/package.json
+++ b/packages/testing-library/testing-environment/package.json
@@ -1,5 +1,5 @@
{
- "name": "@lynx-js/test-environment",
+ "name": "@lynx-js/testing-environment",
"version": "0.0.1",
"description": "A subset of a Lynx environment to be useful for testing",
"keywords": [
diff --git a/packages/testing-library/test-environment/rslib.config.ts b/packages/testing-library/testing-environment/rslib.config.ts
similarity index 100%
rename from packages/testing-library/test-environment/rslib.config.ts
rename to packages/testing-library/testing-environment/rslib.config.ts
diff --git a/packages/testing-library/test-environment/src/__tests__/basic.test.js b/packages/testing-library/testing-environment/src/__tests__/basic.test.js
similarity index 97%
rename from packages/testing-library/test-environment/src/__tests__/basic.test.js
rename to packages/testing-library/testing-environment/src/__tests__/basic.test.js
index de2b71c098..ae4f06989f 100644
--- a/packages/testing-library/test-environment/src/__tests__/basic.test.js
+++ b/packages/testing-library/testing-environment/src/__tests__/basic.test.js
@@ -1,8 +1,8 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
beforeEach(() => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
});
describe('test', () => {
@@ -142,7 +142,7 @@ describe('test', () => {
"bindEvent:tap": [Function],
}
`);
- lynxEnv.switchToBackgroundThread();
+ lynxTestingEnv.switchToBackgroundThread();
lynxCoreInject.tt.publishEvent = (eventHandler, data) => {
expect(eventHandler).toMatchInlineSnapshot(`"2:0:bindtap"`);
expect(data).toMatchInlineSnapshot(`
diff --git a/packages/testing-library/test-environment/src/__tests__/to-have-text-content.test.js b/packages/testing-library/testing-environment/src/__tests__/to-have-text-content.test.js
similarity index 91%
rename from packages/testing-library/test-environment/src/__tests__/to-have-text-content.test.js
rename to packages/testing-library/testing-environment/src/__tests__/to-have-text-content.test.js
index c15d3a3d91..db4dc104a7 100644
--- a/packages/testing-library/test-environment/src/__tests__/to-have-text-content.test.js
+++ b/packages/testing-library/testing-environment/src/__tests__/to-have-text-content.test.js
@@ -3,8 +3,8 @@ import { expect, test } from 'vitest';
describe('.toHaveTextContent', () => {
test('handles positive test cases', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const text0 = __CreateText(0);
@@ -32,8 +32,8 @@ describe('.toHaveTextContent', () => {
});
test('handles text nodes', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const text0 = __CreateText(0);
const rawText0 = __CreateRawText('example', text0.$$uiSign);
@@ -57,8 +57,8 @@ describe('.toHaveTextContent', () => {
});
test('handles negative test cases', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const text0 = __CreateText(0);
const rawText0 = __CreateRawText('2', text0.$$uiSign);
@@ -86,8 +86,8 @@ describe('.toHaveTextContent', () => {
});
test('normalizes whitespace by default', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const text0 = __CreateText(0);
const rawText0 = __CreateRawText('Step 1 of 4', text0.$$uiSign);
@@ -104,8 +104,8 @@ describe('.toHaveTextContent', () => {
});
test('allows whitespace normalization to be turned off', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const text0 = __CreateText(0);
const rawText0 = __CreateRawText(' Step 1 of 4', text0.$$uiSign);
@@ -124,8 +124,8 @@ describe('.toHaveTextContent', () => {
});
test('can handle multiple levels', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const text0 = __CreateText(0);
const rawText0 = __CreateRawText('Step 1 of 4', text0.$$uiSign);
@@ -147,8 +147,8 @@ describe('.toHaveTextContent', () => {
});
test('can handle multiple levels with content spread across descendants', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const view = __CreateView(0);
const text0 = __CreateText(view.$$uiSign);
@@ -195,8 +195,8 @@ describe('.toHaveTextContent', () => {
});
test('does not throw error with empty content', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const text0 = __CreateText(0);
__AppendElement(page, text0);
@@ -209,8 +209,8 @@ describe('.toHaveTextContent', () => {
});
test('is case-sensitive', () => {
- lynxEnv.resetLynxEnv();
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.reset();
+ lynxTestingEnv.switchToMainThread();
const page = __CreatePage('0', 0);
const text0 = __CreateText(0);
const rawText0 = __CreateRawText('Sensitive text', text0.$$uiSign);
diff --git a/packages/testing-library/test-environment/src/env/vitest/index.ts b/packages/testing-library/testing-environment/src/env/vitest/index.ts
similarity index 63%
rename from packages/testing-library/test-environment/src/env/vitest/index.ts
rename to packages/testing-library/testing-environment/src/env/vitest/index.ts
index 7c3054eca6..5e1105b1d3 100644
--- a/packages/testing-library/test-environment/src/env/vitest/index.ts
+++ b/packages/testing-library/testing-environment/src/env/vitest/index.ts
@@ -1,8 +1,8 @@
import { builtinEnvironments } from 'vitest/environments';
-import { LynxEnv } from '@lynx-js/test-environment';
+import { LynxTestingEnv } from '@lynx-js/testing-environment';
const env = {
- name: 'lynxEnv',
+ name: 'lynxTestingEnv',
transformMode: 'web',
async setup(global) {
const fakeGlobal: {
@@ -11,12 +11,12 @@ const env = {
await builtinEnvironments.jsdom.setup(fakeGlobal, {});
global.jsdom = fakeGlobal.jsdom;
- const lynxEnv = new LynxEnv();
- global.lynxEnv = lynxEnv;
+ const lynxTestingEnv = new LynxTestingEnv();
+ global.lynxTestingEnv = lynxTestingEnv;
return {
teardown(global) {
- delete global.lynxEnv;
+ delete global.lynxTestingEnv;
delete global.jsdom;
},
};
diff --git a/packages/testing-library/test-environment/src/index.ts b/packages/testing-library/testing-environment/src/index.ts
similarity index 90%
rename from packages/testing-library/test-environment/src/index.ts
rename to packages/testing-library/testing-environment/src/index.ts
index c3aac013a8..9612a26cc0 100644
--- a/packages/testing-library/test-environment/src/index.ts
+++ b/packages/testing-library/testing-environment/src/index.ts
@@ -34,7 +34,7 @@ export type PickUnderscoreKeys = Pick>;
export type ElementTreeGlobals = PickUnderscoreKeys;
declare global {
- var lynxEnv: LynxEnv;
+ var lynxTestingEnv: LynxTestingEnv;
var elementTree: ElementTree;
var __JS__: boolean;
var __LEPUS__: boolean;
@@ -49,7 +49,7 @@ declare global {
function onInjectMainThreadGlobals(globals: any): void;
function onSwitchedToBackgroundThread(): void;
function onSwitchedToMainThread(): void;
- function onResetLynxEnv(): void;
+ function onResetLynxTestingEnv(): void;
function onInitWorkletRuntime(): void;
}
@@ -79,11 +79,11 @@ function __injectElementApi(target?: any) {
target.__OnLifecycleEvent = (...args: any[]) => {
const isMainThread = __MAIN_THREAD__;
- globalThis.lynxEnv.switchToBackgroundThread();
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
if (isMainThread) {
- globalThis.lynxEnv.switchToMainThread();
+ globalThis.lynxTestingEnv.switchToMainThread();
}
};
target._ReportError = () => {};
@@ -94,16 +94,16 @@ function createPolyfills() {
callLepusMethod: (...rLynxChange: any[]) => {
const isBackground = !__MAIN_THREAD__;
- globalThis.lynxEnv.switchToMainThread();
+ globalThis.lynxTestingEnv.switchToMainThread();
globalThis[rLynxChange[0]](rLynxChange[1]);
- globalThis.lynxEnv.switchToBackgroundThread();
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
rLynxChange[2]();
- globalThis.lynxEnv.switchToMainThread();
+ globalThis.lynxTestingEnv.switchToMainThread();
// restore the original thread state
if (isBackground) {
- globalThis.lynxEnv.switchToBackgroundThread();
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
}
},
markTiming: () => {},
@@ -143,7 +143,7 @@ function createPolyfills() {
data,
}) => {
const isMainThread = __MAIN_THREAD__;
- lynxEnv.switchToBackgroundThread();
+ lynxTestingEnv.switchToBackgroundThread();
// Ensure the code is running on the background thread
ee.emit(type, {
@@ -151,7 +151,7 @@ function createPolyfills() {
});
if (isMainThread) {
- lynxEnv.switchToMainThread();
+ lynxTestingEnv.switchToMainThread();
}
};
// @ts-ignore
@@ -168,7 +168,7 @@ function createPolyfills() {
options,
) {
const isBackground = !__MAIN_THREAD__;
- globalThis.lynxEnv.switchToMainThread();
+ globalThis.lynxTestingEnv.switchToMainThread();
if (process.env['DEBUG']) {
console.log('__LoadLepusChunk', chunkName, options);
@@ -182,7 +182,7 @@ function createPolyfills() {
// restore the original thread state
if (isBackground) {
- globalThis.lynxEnv.switchToBackgroundThread();
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
}
return ans;
@@ -360,11 +360,11 @@ function injectBackgroundThreadGlobals(target?: any, polyfills?: any) {
* @example
*
* ```ts
- * import { LynxEnv } from '@lynx-js/test-environment';
+ * import { LynxTestingEnv } from '@lynx-js/testing-environment';
*
- * const lynxEnv = new LynxEnv();
+ * const lynxTestingEnv = new LynxTestingEnv();
*
- * lynxEnv.switchToMainThread();
+ * lynxTestingEnv.switchToMainThread();
* // use the main thread Element PAPI
* const page = __CreatePage('0', 0);
* const view = __CreateView(0);
@@ -374,7 +374,7 @@ function injectBackgroundThreadGlobals(target?: any, polyfills?: any) {
*
* @public
*/
-export class LynxEnv {
+export class LynxTestingEnv {
private originals: Map = new Map();
/**
* The global object for the background thread.
@@ -382,11 +382,11 @@ export class LynxEnv {
* @example
*
* ```ts
- * import { LynxEnv } from '@lynx-js/test-environment';
+ * import { LynxTestingEnv } from '@lynx-js/testing-environment';
*
- * const lynxEnv = new LynxEnv();
+ * const lynxTestingEnv = new LynxTestingEnv();
*
- * lynxEnv.switchToBackgroundThread();
+ * lynxTestingEnv.switchToBackgroundThread();
* // use the background thread global object
* globalThis.lynxCoreInject.tt.OnLifecycleEvent(...args);
* ```
@@ -398,11 +398,11 @@ export class LynxEnv {
* @example
*
* ```ts
- * import { LynxEnv } from '@lynx-js/test-environment';
+ * import { LynxTestingEnv } from '@lynx-js/testing-environment';
*
- * const lynxEnv = new LynxEnv();
+ * const lynxTestingEnv = new LynxTestingEnv();
*
- * lynxEnv.switchToMainThread();
+ * lynxTestingEnv.switchToMainThread();
* // use the main thread global object
* const page = globalThis.__CreatePage('0', 0);
* const view = globalThis.__CreateView(0);
@@ -482,11 +482,11 @@ export class LynxEnv {
});
this.originals?.clear();
}
- resetLynxEnv() {
+ reset() {
this.injectGlobals();
// ensure old globals are replaced with new globals
this.switchToMainThread();
this.switchToBackgroundThread();
- globalThis.onResetLynxEnv?.();
+ globalThis.onResetLynxTestingEnv?.();
}
}
diff --git a/packages/testing-library/test-environment/src/lynx/ElementPAPI.ts b/packages/testing-library/testing-environment/src/lynx/ElementPAPI.ts
similarity index 96%
rename from packages/testing-library/test-environment/src/lynx/ElementPAPI.ts
rename to packages/testing-library/testing-environment/src/lynx/ElementPAPI.ts
index 2a65fe5bc7..44bca49c7f 100644
--- a/packages/testing-library/test-environment/src/lynx/ElementPAPI.ts
+++ b/packages/testing-library/testing-environment/src/lynx/ElementPAPI.ts
@@ -79,14 +79,15 @@ export const initElementTree = () => {
__CreatePage(_tag: string, parentComponentUniqueId: number) {
const page = this.__CreateElement('page', parentComponentUniqueId);
this.root = page;
- lynxEnv.jsdom.window.document.body.appendChild(page);
+ lynxTestingEnv.jsdom.window.document.body.appendChild(page);
return page;
}
__CreateRawText(text: string): LynxElement {
- const element = lynxEnv.jsdom.window.document.createTextNode(
- text,
- ) as unknown as LynxElement;
+ const element = lynxTestingEnv.jsdom.window.document
+ .createTextNode(
+ text,
+ ) as unknown as LynxElement;
this.countElement(element, 0);
return element;
@@ -108,9 +109,10 @@ export const initElementTree = () => {
return this.__CreateRawText('');
}
- const element = lynxEnv.jsdom.window.document.createElement(
- tag,
- ) as LynxElement;
+ const element = lynxTestingEnv.jsdom.window.document
+ .createElement(
+ tag,
+ ) as LynxElement;
this.countElement(element, parentComponentUniqueId);
return element;
}
@@ -230,14 +232,14 @@ export const initElementTree = () => {
typeof eventHandler === 'object' && eventHandler['type'] === 'worklet'
) {
const isBackground = !__MAIN_THREAD__;
- globalThis.lynxEnv.switchToMainThread();
+ globalThis.lynxTestingEnv.switchToMainThread();
// Use Object.assign to convert evt to plain object to avoid infinite transformWorkletInner
// @ts-ignore
runWorklet(eventHandler.value, [Object.assign({}, evt)]);
if (isBackground) {
- globalThis.lynxEnv.switchToBackgroundThread();
+ globalThis.lynxTestingEnv.switchToBackgroundThread();
}
} else {
// stop the propagation of the event
diff --git a/packages/testing-library/test-environment/src/lynx/GlobalThis.ts b/packages/testing-library/testing-environment/src/lynx/GlobalThis.ts
similarity index 100%
rename from packages/testing-library/test-environment/src/lynx/GlobalThis.ts
rename to packages/testing-library/testing-environment/src/lynx/GlobalThis.ts
diff --git a/packages/testing-library/test-environment/src/util.ts b/packages/testing-library/testing-environment/src/util.ts
similarity index 100%
rename from packages/testing-library/test-environment/src/util.ts
rename to packages/testing-library/testing-environment/src/util.ts
diff --git a/packages/testing-library/test-environment/tsconfig.json b/packages/testing-library/testing-environment/tsconfig.json
similarity index 100%
rename from packages/testing-library/test-environment/tsconfig.json
rename to packages/testing-library/testing-environment/tsconfig.json
diff --git a/packages/testing-library/test-environment/turbo.json b/packages/testing-library/testing-environment/turbo.json
similarity index 100%
rename from packages/testing-library/test-environment/turbo.json
rename to packages/testing-library/testing-environment/turbo.json
diff --git a/packages/testing-library/test-environment/vitest.config.mts b/packages/testing-library/testing-environment/vitest.config.mts
similarity index 100%
rename from packages/testing-library/test-environment/vitest.config.mts
rename to packages/testing-library/testing-environment/vitest.config.mts
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index d0c39e3b03..e96bc42073 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -243,9 +243,9 @@ importers:
'@lynx-js/react':
specifier: workspace:*
version: link:..
- '@lynx-js/test-environment':
+ '@lynx-js/testing-environment':
specifier: workspace:*
- version: link:../../testing-library/test-environment
+ version: link:../../testing-library/testing-environment
'@testing-library/dom':
specifier: ^10.4.0
version: 10.4.0
@@ -580,7 +580,7 @@ importers:
specifier: ^6.6.3
version: 6.6.3
- packages/testing-library/test-environment:
+ packages/testing-library/testing-environment:
devDependencies:
'@testing-library/jest-dom':
specifier: ^6.6.3