@lynx-js/testing-environment 0.1.5 → 0.1.6

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 ADDED
@@ -0,0 +1,66 @@
1
+ # @lynx-js/testing-environment
2
+
3
+ ## 0.1.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix that `lynxTestingEnv.jsdom` cannot be initialized correctly when `global.jsdom` is not defined. ([#1422](https://github.com/lynx-family/lynx-stack/pull/1422))
8
+
9
+ ## 0.1.5
10
+
11
+ ### Patch Changes
12
+
13
+ - Fix `GlobalEventEmitter` type definition, the `emit(eventName: string, data: unknown)` function should recevie an array typed `data` and pass as param list of listeners. ([#1479](https://github.com/lynx-family/lynx-stack/pull/1479))
14
+
15
+ ## 0.1.4
16
+
17
+ ### Patch Changes
18
+
19
+ - Fix the thread switching bug in `lynx.getCoreContext` and `lynx.getJSContext`. ([#1244](https://github.com/lynx-family/lynx-stack/pull/1244))
20
+
21
+ ## 0.1.3
22
+
23
+ ### Patch Changes
24
+
25
+ - Support alog of component rendering on production for better error reporting. Enable it by using `REACT_ALOG=true rspeedy dev/build` or defining `__ALOG__` to `true` in `lynx.config.js`: ([#1164](https://github.com/lynx-family/lynx-stack/pull/1164))
26
+
27
+ ```js
28
+ export default defineConfig({
29
+ // ...
30
+ source: {
31
+ define: {
32
+ __ALOG__: true,
33
+ },
34
+ },
35
+ });
36
+ ```
37
+
38
+ - Supports `console.alog` and use different `console` object in main thread and background thread. ([#1164](https://github.com/lynx-family/lynx-stack/pull/1164))
39
+
40
+ ## 0.1.2
41
+
42
+ ### Patch Changes
43
+
44
+ - Fix the infinite loop in the `__RemoveElement` element PAPI. ([#1263](https://github.com/lynx-family/lynx-stack/pull/1263))
45
+
46
+ ## 0.1.1
47
+
48
+ ### Patch Changes
49
+
50
+ - Fix `getJSContext` or `getCoreContext` is not a function. ([#1122](https://github.com/lynx-family/lynx-stack/pull/1122))
51
+
52
+ ## 0.1.0
53
+
54
+ ### Minor Changes
55
+
56
+ - Switch to ESM package format by setting `"type": "module"`. ([#703](https://github.com/lynx-family/lynx-stack/pull/703))
57
+
58
+ ### Patch Changes
59
+
60
+ - rename @lynx-js/test-environment to @lynx-js/testing-environment ([#704](https://github.com/lynx-family/lynx-stack/pull/704))
61
+
62
+ ## 0.0.1
63
+
64
+ ### Patch Changes
65
+
66
+ - Add testing library for ReactLynx ([#74](https://github.com/lynx-family/lynx-stack/pull/74))
package/README.md CHANGED
@@ -8,8 +8,9 @@ The Element PAPI implementation is based on jsdom, for example `__CreateElement`
8
8
 
9
9
  ```js
10
10
  import { LynxTestingEnv } from '@lynx-js/testing-environment';
11
+ import { JSDOM } from 'jsdom';
11
12
 
12
- const lynxTestingEnv = new LynxTestingEnv();
13
+ const lynxTestingEnv = new LynxTestingEnv(new JSDOM());
13
14
  ```
14
15
 
15
16
  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.
@@ -34,8 +34,7 @@ const env = {
34
34
  async setup (global) {
35
35
  const fakeGlobal = {};
36
36
  await environments_namespaceObject.builtinEnvironments.jsdom.setup(fakeGlobal, {});
37
- global.jsdom = fakeGlobal.jsdom;
38
- const lynxTestingEnv = new testing_environment_namespaceObject.LynxTestingEnv();
37
+ const lynxTestingEnv = new testing_environment_namespaceObject.LynxTestingEnv(fakeGlobal.jsdom);
39
38
  global.lynxTestingEnv = lynxTestingEnv;
40
39
  return {
41
40
  teardown (global) {
@@ -6,8 +6,7 @@ const env = {
6
6
  async setup (global) {
7
7
  const fakeGlobal = {};
8
8
  await builtinEnvironments.jsdom.setup(fakeGlobal, {});
9
- global.jsdom = fakeGlobal.jsdom;
10
- const lynxTestingEnv = new LynxTestingEnv();
9
+ const lynxTestingEnv = new LynxTestingEnv(fakeGlobal.jsdom);
11
10
  global.lynxTestingEnv = lynxTestingEnv;
12
11
  return {
13
12
  teardown (global) {
package/dist/index.cjs CHANGED
@@ -310,11 +310,13 @@ class LynxTestingEnv {
310
310
  this.switchToBackgroundThread();
311
311
  null == (_globalThis_onResetLynxTestingEnv = (_globalThis = globalThis).onResetLynxTestingEnv) || _globalThis_onResetLynxTestingEnv.call(_globalThis);
312
312
  }
313
- constructor(){
313
+ constructor(jsdom){
314
314
  _define_property(this, "originals", new Map());
315
315
  _define_property(this, "backgroundThread", void 0);
316
316
  _define_property(this, "mainThread", void 0);
317
- _define_property(this, "jsdom", global.jsdom);
317
+ _define_property(this, "jsdom", void 0);
318
+ this.jsdom = jsdom ?? global.jsdom;
319
+ if (!this.jsdom) throw new Error("LynxTestingEnv requires a JSDOM instance. Pass one to the constructor, or ensure your test runner sets global.jsdom (e.g., via a setup file).");
318
320
  this.backgroundThread = (0, GlobalThis_cjs_namespaceObject.createGlobalThis)();
319
321
  this.mainThread = (0, GlobalThis_cjs_namespaceObject.createGlobalThis)();
320
322
  const globalPolyfills = {
package/dist/index.d.ts CHANGED
@@ -56,7 +56,7 @@ declare global {
56
56
  * ```ts
57
57
  * import { LynxTestingEnv } from '@lynx-js/testing-environment';
58
58
  *
59
- * const lynxTestingEnv = new LynxTestingEnv();
59
+ * const lynxTestingEnv = new LynxTestingEnv(new JSDOM());
60
60
  *
61
61
  * lynxTestingEnv.switchToMainThread();
62
62
  * // use the main thread Element PAPI
@@ -78,7 +78,7 @@ export declare class LynxTestingEnv {
78
78
  * ```ts
79
79
  * import { LynxTestingEnv } from '@lynx-js/testing-environment';
80
80
  *
81
- * const lynxTestingEnv = new LynxTestingEnv();
81
+ * const lynxTestingEnv = new LynxTestingEnv(new JSDOM());
82
82
  *
83
83
  * lynxTestingEnv.switchToBackgroundThread();
84
84
  * // use the background thread global object
@@ -94,7 +94,7 @@ export declare class LynxTestingEnv {
94
94
  * ```ts
95
95
  * import { LynxTestingEnv } from '@lynx-js/testing-environment';
96
96
  *
97
- * const lynxTestingEnv = new LynxTestingEnv();
97
+ * const lynxTestingEnv = new LynxTestingEnv(new JSDOM());
98
98
  *
99
99
  * lynxTestingEnv.switchToMainThread();
100
100
  * // use the main thread global object
@@ -105,7 +105,7 @@ export declare class LynxTestingEnv {
105
105
  */
106
106
  mainThread: LynxGlobalThis & ElementTreeGlobals;
107
107
  jsdom: JSDOM;
108
- constructor();
108
+ constructor(jsdom?: JSDOM);
109
109
  injectGlobals(): void;
110
110
  switchToBackgroundThread(): void;
111
111
  switchToMainThread(): void;
package/dist/index.js CHANGED
@@ -271,11 +271,13 @@ class LynxTestingEnv {
271
271
  this.switchToBackgroundThread();
272
272
  null == (_globalThis_onResetLynxTestingEnv = (_globalThis = globalThis).onResetLynxTestingEnv) || _globalThis_onResetLynxTestingEnv.call(_globalThis);
273
273
  }
274
- constructor(){
274
+ constructor(jsdom){
275
275
  _define_property(this, "originals", new Map());
276
276
  _define_property(this, "backgroundThread", void 0);
277
277
  _define_property(this, "mainThread", void 0);
278
- _define_property(this, "jsdom", global.jsdom);
278
+ _define_property(this, "jsdom", void 0);
279
+ this.jsdom = jsdom ?? global.jsdom;
280
+ if (!this.jsdom) throw new Error("LynxTestingEnv requires a JSDOM instance. Pass one to the constructor, or ensure your test runner sets global.jsdom (e.g., via a setup file).");
279
281
  this.backgroundThread = createGlobalThis();
280
282
  this.mainThread = createGlobalThis();
281
283
  const globalPolyfills = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/testing-environment",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "A subset of a Lynx environment to be useful for testing",
5
5
  "keywords": [
6
6
  "Lynx",
@@ -43,12 +43,13 @@
43
43
  }
44
44
  },
45
45
  "files": [
46
- "dist"
46
+ "dist",
47
+ "CHANGELOG.md"
47
48
  ],
48
49
  "devDependencies": {
49
- "@testing-library/jest-dom": "^6.6.4",
50
+ "@testing-library/jest-dom": "^6.7.0",
50
51
  "@types/jsdom": "^21.1.7",
51
- "rsbuild-plugin-publint": "0.3.2"
52
+ "rsbuild-plugin-publint": "0.3.3"
52
53
  },
53
54
  "scripts": {
54
55
  "api-extractor": "api-extractor run --verbose",