@lynx-js/testing-environment 0.1.6 → 0.1.8
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 +14 -0
- package/dist/env/vitest/index.cjs +2 -0
- package/dist/env/vitest/index.d.ts +1 -1
- package/dist/env/vitest/index.js +2 -0
- package/dist/index.cjs +21 -6
- package/dist/index.d.ts +2 -6
- package/dist/index.js +21 -6
- package/dist/lynx/ElementPAPI.cjs +3 -3
- package/dist/lynx/ElementPAPI.d.ts +20 -2
- package/dist/lynx/ElementPAPI.js +3 -3
- package/dist/lynx/GlobalThis.d.ts +8 -0
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @lynx-js/testing-environment
|
|
2
2
|
|
|
3
|
+
## 0.1.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix the "ReferenceError: Node is not defined" error. ([#1850](https://github.com/lynx-family/lynx-stack/pull/1850))
|
|
8
|
+
|
|
9
|
+
This error would happen when upgrading to `@testing-library/jest-dom` [v6.9.0](https://github.com/testing-library/jest-dom/releases/tag/v6.9.0).
|
|
10
|
+
|
|
11
|
+
## 0.1.7
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Support `lynx.createSelectorQuery().select()` and `setNativeProps` API ([#1570](https://github.com/lynx-family/lynx-stack/pull/1570))
|
|
16
|
+
|
|
3
17
|
## 0.1.6
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -36,10 +36,12 @@ const env = {
|
|
|
36
36
|
await environments_namespaceObject.builtinEnvironments.jsdom.setup(fakeGlobal, {});
|
|
37
37
|
const lynxTestingEnv = new testing_environment_namespaceObject.LynxTestingEnv(fakeGlobal.jsdom);
|
|
38
38
|
global.lynxTestingEnv = lynxTestingEnv;
|
|
39
|
+
global.Node = lynxTestingEnv.jsdom.window.Node;
|
|
39
40
|
return {
|
|
40
41
|
teardown (global) {
|
|
41
42
|
delete global.lynxTestingEnv;
|
|
42
43
|
delete global.jsdom;
|
|
44
|
+
delete global.Node;
|
|
43
45
|
}
|
|
44
46
|
};
|
|
45
47
|
}
|
package/dist/env/vitest/index.js
CHANGED
|
@@ -8,10 +8,12 @@ const env = {
|
|
|
8
8
|
await builtinEnvironments.jsdom.setup(fakeGlobal, {});
|
|
9
9
|
const lynxTestingEnv = new LynxTestingEnv(fakeGlobal.jsdom);
|
|
10
10
|
global.lynxTestingEnv = lynxTestingEnv;
|
|
11
|
+
global.Node = lynxTestingEnv.jsdom.window.Node;
|
|
11
12
|
return {
|
|
12
13
|
teardown (global) {
|
|
13
14
|
delete global.lynxTestingEnv;
|
|
14
15
|
delete global.jsdom;
|
|
16
|
+
delete global.Node;
|
|
15
17
|
}
|
|
16
18
|
};
|
|
17
19
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -53,10 +53,10 @@ function _define_property(obj, key, value) {
|
|
|
53
53
|
return obj;
|
|
54
54
|
}
|
|
55
55
|
function __injectElementApi(target) {
|
|
56
|
-
const
|
|
57
|
-
target.elementTree =
|
|
56
|
+
const elementTree1 = (0, ElementPAPI_cjs_namespaceObject.initElementTree)();
|
|
57
|
+
target.elementTree = elementTree1;
|
|
58
58
|
if (void 0 === target) target = globalThis;
|
|
59
|
-
for (const k of Object.getOwnPropertyNames(
|
|
59
|
+
for (const k of Object.getOwnPropertyNames(elementTree1.constructor.prototype))if (k.startsWith('__')) target[k] = elementTree1[k].bind(elementTree1);
|
|
60
60
|
target.$kTemplateAssembler = {};
|
|
61
61
|
target.registerDataProcessor = ()=>{
|
|
62
62
|
console.error('registerDataProcessor is not implemented');
|
|
@@ -72,11 +72,12 @@ function __injectElementApi(target) {
|
|
|
72
72
|
function createPolyfills() {
|
|
73
73
|
const app = {
|
|
74
74
|
callLepusMethod: (...rLynxChange)=>{
|
|
75
|
+
var _rLynxChange_;
|
|
75
76
|
const isBackground = !__MAIN_THREAD__;
|
|
76
77
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
77
78
|
globalThis[rLynxChange[0]](rLynxChange[1]);
|
|
78
79
|
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
79
|
-
rLynxChange[2]();
|
|
80
|
+
null == (_rLynxChange_ = rLynxChange[2]) || _rLynxChange_.call(rLynxChange);
|
|
80
81
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
81
82
|
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
82
83
|
},
|
|
@@ -202,8 +203,14 @@ class NodesRef {
|
|
|
202
203
|
fields() {
|
|
203
204
|
throw new Error('not implemented');
|
|
204
205
|
}
|
|
205
|
-
setNativeProps() {
|
|
206
|
-
|
|
206
|
+
setNativeProps(props) {
|
|
207
|
+
return {
|
|
208
|
+
exec: ()=>{
|
|
209
|
+
const element = elementTree.uniqueId2Element.get(Number(this._nodeSelectToken.identifier));
|
|
210
|
+
if (!element) throw new Error(`[NodesRef.setNativeProps] Element not found for identifier=${this._nodeSelectToken.identifier}`);
|
|
211
|
+
if (element) for(const key in props)element.setAttributeNS(null, key, props[key]);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
207
214
|
}
|
|
208
215
|
constructor(selectorQuery, nodeSelectToken){
|
|
209
216
|
_define_property(this, "_nodeSelectToken", void 0);
|
|
@@ -242,6 +249,14 @@ function injectBackgroundThreadGlobals(target, polyfills) {
|
|
|
242
249
|
type: 2,
|
|
243
250
|
identifier: uniqueId.toString()
|
|
244
251
|
});
|
|
252
|
+
},
|
|
253
|
+
select: function(selector) {
|
|
254
|
+
const el = lynxTestingEnv.jsdom.window.document.querySelector(selector);
|
|
255
|
+
if (!el) throw new Error(`[createSelectorQuery.select] No element matches selector: ${selector}`);
|
|
256
|
+
return new NodesRef({}, {
|
|
257
|
+
type: 0,
|
|
258
|
+
identifier: el.$$uiSign.toString()
|
|
259
|
+
});
|
|
245
260
|
}
|
|
246
261
|
}),
|
|
247
262
|
getCoreContext: ()=>CoreContext,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
*
|
|
4
|
-
* A pure-JavaScript implementation of the {@link https://lynxjs.org/guide/spec.html | Lynx Spec},
|
|
5
|
-
* notably the {@link https://lynxjs.org/api/engine/element-api | Element PAPI} and {@link https://lynxjs.org/guide/spec#dual-threaded-model | Dual-threaded Model} for use with Node.js.
|
|
6
|
-
*/
|
|
7
1
|
import { JSDOM } from 'jsdom';
|
|
8
2
|
import { LynxGlobalThis } from './lynx/GlobalThis.js';
|
|
9
3
|
import { initElementTree } from './lynx/ElementPAPI.js';
|
|
@@ -109,6 +103,8 @@ export declare class LynxTestingEnv {
|
|
|
109
103
|
injectGlobals(): void;
|
|
110
104
|
switchToBackgroundThread(): void;
|
|
111
105
|
switchToMainThread(): void;
|
|
106
|
+
// we do not use it because we have to keep background thread
|
|
107
|
+
// otherwise we will get error on __MAIN_THREAD__/__BACKGROUND__/lynx not defined etc.
|
|
112
108
|
clearGlobal(): void;
|
|
113
109
|
reset(): void;
|
|
114
110
|
}
|
package/dist/index.js
CHANGED
|
@@ -14,10 +14,10 @@ function _define_property(obj, key, value) {
|
|
|
14
14
|
return obj;
|
|
15
15
|
}
|
|
16
16
|
function __injectElementApi(target) {
|
|
17
|
-
const
|
|
18
|
-
target.elementTree =
|
|
17
|
+
const elementTree1 = initElementTree();
|
|
18
|
+
target.elementTree = elementTree1;
|
|
19
19
|
if (void 0 === target) target = globalThis;
|
|
20
|
-
for (const k of Object.getOwnPropertyNames(
|
|
20
|
+
for (const k of Object.getOwnPropertyNames(elementTree1.constructor.prototype))if (k.startsWith('__')) target[k] = elementTree1[k].bind(elementTree1);
|
|
21
21
|
target.$kTemplateAssembler = {};
|
|
22
22
|
target.registerDataProcessor = ()=>{
|
|
23
23
|
console.error('registerDataProcessor is not implemented');
|
|
@@ -33,11 +33,12 @@ function __injectElementApi(target) {
|
|
|
33
33
|
function createPolyfills() {
|
|
34
34
|
const app = {
|
|
35
35
|
callLepusMethod: (...rLynxChange)=>{
|
|
36
|
+
var _rLynxChange_;
|
|
36
37
|
const isBackground = !__MAIN_THREAD__;
|
|
37
38
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
38
39
|
globalThis[rLynxChange[0]](rLynxChange[1]);
|
|
39
40
|
globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
40
|
-
rLynxChange[2]();
|
|
41
|
+
null == (_rLynxChange_ = rLynxChange[2]) || _rLynxChange_.call(rLynxChange);
|
|
41
42
|
globalThis.lynxTestingEnv.switchToMainThread();
|
|
42
43
|
if (isBackground) globalThis.lynxTestingEnv.switchToBackgroundThread();
|
|
43
44
|
},
|
|
@@ -163,8 +164,14 @@ class NodesRef {
|
|
|
163
164
|
fields() {
|
|
164
165
|
throw new Error('not implemented');
|
|
165
166
|
}
|
|
166
|
-
setNativeProps() {
|
|
167
|
-
|
|
167
|
+
setNativeProps(props) {
|
|
168
|
+
return {
|
|
169
|
+
exec: ()=>{
|
|
170
|
+
const element = elementTree.uniqueId2Element.get(Number(this._nodeSelectToken.identifier));
|
|
171
|
+
if (!element) throw new Error(`[NodesRef.setNativeProps] Element not found for identifier=${this._nodeSelectToken.identifier}`);
|
|
172
|
+
if (element) for(const key in props)element.setAttributeNS(null, key, props[key]);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
168
175
|
}
|
|
169
176
|
constructor(selectorQuery, nodeSelectToken){
|
|
170
177
|
_define_property(this, "_nodeSelectToken", void 0);
|
|
@@ -203,6 +210,14 @@ function injectBackgroundThreadGlobals(target, polyfills) {
|
|
|
203
210
|
type: 2,
|
|
204
211
|
identifier: uniqueId.toString()
|
|
205
212
|
});
|
|
213
|
+
},
|
|
214
|
+
select: function(selector) {
|
|
215
|
+
const el = lynxTestingEnv.jsdom.window.document.querySelector(selector);
|
|
216
|
+
if (!el) throw new Error(`[createSelectorQuery.select] No element matches selector: ${selector}`);
|
|
217
|
+
return new NodesRef({}, {
|
|
218
|
+
type: 0,
|
|
219
|
+
identifier: el.$$uiSign.toString()
|
|
220
|
+
});
|
|
206
221
|
}
|
|
207
222
|
}),
|
|
208
223
|
getCoreContext: ()=>CoreContext,
|
|
@@ -38,11 +38,10 @@ function _define_property(obj, key, value) {
|
|
|
38
38
|
}
|
|
39
39
|
const initElementTree = ()=>{
|
|
40
40
|
let uiSignNext = 0;
|
|
41
|
-
const uniqueId2Element = new Map();
|
|
42
41
|
return new class {
|
|
43
42
|
countElement(element, parentComponentUniqueId) {
|
|
44
43
|
element.$$uiSign = uiSignNext++;
|
|
45
|
-
uniqueId2Element.set(element.$$uiSign, element);
|
|
44
|
+
this.uniqueId2Element.set(element.$$uiSign, element);
|
|
46
45
|
element.parentComponentUniqueId = parentComponentUniqueId;
|
|
47
46
|
}
|
|
48
47
|
__CreatePage(_tag, parentComponentUniqueId) {
|
|
@@ -251,9 +250,10 @@ const initElementTree = ()=>{
|
|
|
251
250
|
return this.toTree();
|
|
252
251
|
}
|
|
253
252
|
__GetElementByUniqueId(uniqueId) {
|
|
254
|
-
return uniqueId2Element.get(uniqueId);
|
|
253
|
+
return this.uniqueId2Element.get(uniqueId);
|
|
255
254
|
}
|
|
256
255
|
constructor(){
|
|
256
|
+
_define_property(this, "uniqueId2Element", new Map());
|
|
257
257
|
_define_property(this, "root", void 0);
|
|
258
258
|
}
|
|
259
259
|
}();
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*
|
|
2
|
+
// Copyright 2024 The Lynx Authors. All rights reserved.
|
|
3
|
+
// Licensed under the Apache License Version 2.0 that can be found in the
|
|
4
|
+
// LICENSE file in the root directory of this source tree.
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Any Lynx Element, such as `view`, `text`, `image`, etc.
|
|
3
8
|
*
|
|
@@ -6,6 +11,18 @@
|
|
|
6
11
|
* @public
|
|
7
12
|
*/
|
|
8
13
|
export interface LynxElement extends HTMLElement {
|
|
14
|
+
/**
|
|
15
|
+
* The unique id of the element.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
$$uiSign: number;
|
|
20
|
+
/**
|
|
21
|
+
* The unique id of the parent of the element.
|
|
22
|
+
*
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
parentComponentUniqueId: number;
|
|
9
26
|
/**
|
|
10
27
|
* The map of events bound to the element.
|
|
11
28
|
*/
|
|
@@ -45,6 +62,7 @@ export interface LynxElement extends HTMLElement {
|
|
|
45
62
|
* @public
|
|
46
63
|
*/
|
|
47
64
|
export declare const initElementTree: () => {
|
|
65
|
+
uniqueId2Element: Map<number, LynxElement>;
|
|
48
66
|
root: LynxElement | undefined;
|
|
49
67
|
countElement(element: LynxElement, parentComponentUniqueId: number): void;
|
|
50
68
|
__CreatePage(_tag: string, parentComponentUniqueId: number): LynxElement;
|
|
@@ -60,7 +78,7 @@ export declare const initElementTree: () => {
|
|
|
60
78
|
__CreateWrapperElement(parentComponentUniqueId: number): LynxElement;
|
|
61
79
|
__AddInlineStyle(e: HTMLElement, key: number, value: string): void;
|
|
62
80
|
__AppendElement(parent: LynxElement, child: LynxElement): void;
|
|
63
|
-
__SetCSSId(e: LynxElement | LynxElement
|
|
81
|
+
__SetCSSId(e: LynxElement[] | LynxElement, id: string, entryName?: string | undefined): void;
|
|
64
82
|
__SetAttribute(e: LynxElement, key: string, value: any): void;
|
|
65
83
|
__AddEvent(e: LynxElement, eventType: string, eventName: string, eventHandler: string | Record<string, any>): void;
|
|
66
84
|
__GetEvent(e: LynxElement, eventType: string, eventName: string): {
|
|
@@ -75,7 +93,7 @@ export declare const initElementTree: () => {
|
|
|
75
93
|
__SetGestureDetector(e: LynxElement, id: number, type: number, config: any, relationMap: Record<string, number[]>): void;
|
|
76
94
|
__GetDataset(e: LynxElement): DOMStringMap;
|
|
77
95
|
__RemoveElement(parent: LynxElement, child: LynxElement): void;
|
|
78
|
-
__InsertElementBefore(parent: LynxElement, child: LynxElement, ref?: LynxElement): void;
|
|
96
|
+
__InsertElementBefore(parent: LynxElement, child: LynxElement, ref?: LynxElement | undefined): void;
|
|
79
97
|
__ReplaceElement(newElement: LynxElement, oldElement: LynxElement): void;
|
|
80
98
|
__FlushElementTree(): void;
|
|
81
99
|
__UpdateListComponents(_list: LynxElement, _components: string[]): void;
|
package/dist/lynx/ElementPAPI.js
CHANGED
|
@@ -10,11 +10,10 @@ function _define_property(obj, key, value) {
|
|
|
10
10
|
}
|
|
11
11
|
const initElementTree = ()=>{
|
|
12
12
|
let uiSignNext = 0;
|
|
13
|
-
const uniqueId2Element = new Map();
|
|
14
13
|
return new class {
|
|
15
14
|
countElement(element, parentComponentUniqueId) {
|
|
16
15
|
element.$$uiSign = uiSignNext++;
|
|
17
|
-
uniqueId2Element.set(element.$$uiSign, element);
|
|
16
|
+
this.uniqueId2Element.set(element.$$uiSign, element);
|
|
18
17
|
element.parentComponentUniqueId = parentComponentUniqueId;
|
|
19
18
|
}
|
|
20
19
|
__CreatePage(_tag, parentComponentUniqueId) {
|
|
@@ -223,9 +222,10 @@ const initElementTree = ()=>{
|
|
|
223
222
|
return this.toTree();
|
|
224
223
|
}
|
|
225
224
|
__GetElementByUniqueId(uniqueId) {
|
|
226
|
-
return uniqueId2Element.get(uniqueId);
|
|
225
|
+
return this.uniqueId2Element.get(uniqueId);
|
|
227
226
|
}
|
|
228
227
|
constructor(){
|
|
228
|
+
_define_property(this, "uniqueId2Element", new Map());
|
|
229
229
|
_define_property(this, "root", void 0);
|
|
230
230
|
}
|
|
231
231
|
}();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lynx-js/testing-environment",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "A subset of a Lynx environment to be useful for testing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Lynx",
|
|
@@ -47,13 +47,14 @@
|
|
|
47
47
|
"CHANGELOG.md"
|
|
48
48
|
],
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@testing-library/jest-dom": "^6.
|
|
50
|
+
"@testing-library/jest-dom": "^6.9.0",
|
|
51
51
|
"@types/jsdom": "^21.1.7",
|
|
52
52
|
"rsbuild-plugin-publint": "0.3.3"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"api-extractor": "api-extractor run --verbose",
|
|
56
56
|
"build": "rslib build",
|
|
57
|
-
"dev": "rslib build --watch"
|
|
57
|
+
"dev": "rslib build --watch",
|
|
58
|
+
"test": "vitest"
|
|
58
59
|
}
|
|
59
60
|
}
|