@lynx-js/testing-environment 0.1.2 → 0.1.4

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/dist/index.cjs CHANGED
@@ -40,6 +40,7 @@ const external_events_namespaceObject = require("events");
40
40
  var external_events_default = /*#__PURE__*/ __webpack_require__.n(external_events_namespaceObject);
41
41
  const GlobalThis_cjs_namespaceObject = require("./lynx/GlobalThis.cjs");
42
42
  const ElementPAPI_cjs_namespaceObject = require("./lynx/ElementPAPI.cjs");
43
+ const external_console_namespaceObject = require("console");
43
44
  function _define_property(obj, key, value) {
44
45
  if (key in obj) Object.defineProperty(obj, key, {
45
46
  value: value,
@@ -115,21 +116,23 @@ function createPolyfills() {
115
116
  };
116
117
  const ee = new (external_events_default())();
117
118
  ee.dispatchEvent = ({ type, data })=>{
118
- const isMainThread = __MAIN_THREAD__;
119
- lynxTestingEnv.switchToBackgroundThread();
119
+ const origin = __MAIN_THREAD__ ? 'CoreContext' : 'JSContext';
120
+ if ('CoreContext' === origin) lynxTestingEnv.switchToBackgroundThread();
121
+ else lynxTestingEnv.switchToMainThread();
120
122
  ee.emit(type, {
121
- data: data
123
+ data: data,
124
+ origin
122
125
  });
123
- if (isMainThread) lynxTestingEnv.switchToMainThread();
126
+ if ('CoreContext' === origin) lynxTestingEnv.switchToMainThread();
127
+ else lynxTestingEnv.switchToBackgroundThread();
124
128
  };
125
129
  ee.addEventListener = ee.addListener;
126
130
  ee.removeEventListener = ee.removeListener;
127
131
  const CoreContext = ee;
128
132
  const JsContext = ee;
129
- function __LoadLepusChunk(chunkName, options) {
133
+ function __LoadLepusChunk(chunkName, _options) {
130
134
  const isBackground = !__MAIN_THREAD__;
131
135
  globalThis.lynxTestingEnv.switchToMainThread();
132
- if (process.env['DEBUG']) console.log('__LoadLepusChunk', chunkName, options);
133
136
  let ans;
134
137
  if ('worklet-runtime' === chunkName) {
135
138
  var _globalThis_onInitWorkletRuntime, _globalThis;
@@ -146,6 +149,13 @@ function createPolyfills() {
146
149
  __LoadLepusChunk
147
150
  };
148
151
  }
152
+ function createPreconfiguredConsole() {
153
+ const console1 = new external_console_namespaceObject.Console(process.stdout, process.stderr);
154
+ console1.profile = ()=>{};
155
+ console1.profileEnd = ()=>{};
156
+ console1.alog = ()=>{};
157
+ return console1;
158
+ }
149
159
  function injectMainThreadGlobals(target, polyfills) {
150
160
  var _globalThis_onInjectMainThreadGlobals, _globalThis;
151
161
  __injectElementApi(target);
@@ -153,6 +163,7 @@ function injectMainThreadGlobals(target, polyfills) {
153
163
  if (void 0 === target) target = globalThis;
154
164
  target.__DEV__ = true;
155
165
  target.__PROFILE__ = true;
166
+ target.__ALOG__ = true;
156
167
  target.__JS__ = false;
157
168
  target.__LEPUS__ = true;
158
169
  target.__BACKGROUND__ = false;
@@ -172,8 +183,7 @@ function injectMainThreadGlobals(target, polyfills) {
172
183
  };
173
184
  target.requestAnimationFrame = setTimeout;
174
185
  target.cancelAnimationFrame = clearTimeout;
175
- target.console.profile = ()=>{};
176
- target.console.profileEnd = ()=>{};
186
+ target.console = createPreconfiguredConsole();
177
187
  target.__LoadLepusChunk = __LoadLepusChunk;
178
188
  null == (_globalThis_onInjectMainThreadGlobals = (_globalThis = globalThis).onInjectMainThreadGlobals) || _globalThis_onInjectMainThreadGlobals.call(_globalThis, target);
179
189
  }
@@ -207,6 +217,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
207
217
  if (void 0 === target) target = globalThis;
208
218
  target.__DEV__ = true;
209
219
  target.__PROFILE__ = true;
220
+ target.__ALOG__ = true;
210
221
  target.__JS__ = true;
211
222
  target.__LEPUS__ = false;
212
223
  target.__BACKGROUND__ = true;
@@ -246,8 +257,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
246
257
  };
247
258
  target.requestAnimationFrame = setTimeout;
248
259
  target.cancelAnimationFrame = clearTimeout;
249
- target.console.profile = ()=>{};
250
- target.console.profileEnd = ()=>{};
260
+ target.console = createPreconfiguredConsole();
251
261
  target.SystemInfo = {
252
262
  platform: 'iOS',
253
263
  pixelRatio: 3,
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import events from "events";
2
2
  import { createGlobalThis } from "./lynx/GlobalThis.js";
3
3
  import { initElementTree } from "./lynx/ElementPAPI.js";
4
+ import { Console } from "console";
4
5
  function _define_property(obj, key, value) {
5
6
  if (key in obj) Object.defineProperty(obj, key, {
6
7
  value: value,
@@ -76,21 +77,23 @@ function createPolyfills() {
76
77
  };
77
78
  const ee = new events();
78
79
  ee.dispatchEvent = ({ type, data })=>{
79
- const isMainThread = __MAIN_THREAD__;
80
- lynxTestingEnv.switchToBackgroundThread();
80
+ const origin = __MAIN_THREAD__ ? 'CoreContext' : 'JSContext';
81
+ if ('CoreContext' === origin) lynxTestingEnv.switchToBackgroundThread();
82
+ else lynxTestingEnv.switchToMainThread();
81
83
  ee.emit(type, {
82
- data: data
84
+ data: data,
85
+ origin
83
86
  });
84
- if (isMainThread) lynxTestingEnv.switchToMainThread();
87
+ if ('CoreContext' === origin) lynxTestingEnv.switchToMainThread();
88
+ else lynxTestingEnv.switchToBackgroundThread();
85
89
  };
86
90
  ee.addEventListener = ee.addListener;
87
91
  ee.removeEventListener = ee.removeListener;
88
92
  const CoreContext = ee;
89
93
  const JsContext = ee;
90
- function __LoadLepusChunk(chunkName, options) {
94
+ function __LoadLepusChunk(chunkName, _options) {
91
95
  const isBackground = !__MAIN_THREAD__;
92
96
  globalThis.lynxTestingEnv.switchToMainThread();
93
- if (process.env['DEBUG']) console.log('__LoadLepusChunk', chunkName, options);
94
97
  let ans;
95
98
  if ('worklet-runtime' === chunkName) {
96
99
  var _globalThis_onInitWorkletRuntime, _globalThis;
@@ -107,6 +110,13 @@ function createPolyfills() {
107
110
  __LoadLepusChunk
108
111
  };
109
112
  }
113
+ function createPreconfiguredConsole() {
114
+ const console1 = new Console(process.stdout, process.stderr);
115
+ console1.profile = ()=>{};
116
+ console1.profileEnd = ()=>{};
117
+ console1.alog = ()=>{};
118
+ return console1;
119
+ }
110
120
  function injectMainThreadGlobals(target, polyfills) {
111
121
  var _globalThis_onInjectMainThreadGlobals, _globalThis;
112
122
  __injectElementApi(target);
@@ -114,6 +124,7 @@ function injectMainThreadGlobals(target, polyfills) {
114
124
  if (void 0 === target) target = globalThis;
115
125
  target.__DEV__ = true;
116
126
  target.__PROFILE__ = true;
127
+ target.__ALOG__ = true;
117
128
  target.__JS__ = false;
118
129
  target.__LEPUS__ = true;
119
130
  target.__BACKGROUND__ = false;
@@ -133,8 +144,7 @@ function injectMainThreadGlobals(target, polyfills) {
133
144
  };
134
145
  target.requestAnimationFrame = setTimeout;
135
146
  target.cancelAnimationFrame = clearTimeout;
136
- target.console.profile = ()=>{};
137
- target.console.profileEnd = ()=>{};
147
+ target.console = createPreconfiguredConsole();
138
148
  target.__LoadLepusChunk = __LoadLepusChunk;
139
149
  null == (_globalThis_onInjectMainThreadGlobals = (_globalThis = globalThis).onInjectMainThreadGlobals) || _globalThis_onInjectMainThreadGlobals.call(_globalThis, target);
140
150
  }
@@ -168,6 +178,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
168
178
  if (void 0 === target) target = globalThis;
169
179
  target.__DEV__ = true;
170
180
  target.__PROFILE__ = true;
181
+ target.__ALOG__ = true;
171
182
  target.__JS__ = true;
172
183
  target.__LEPUS__ = false;
173
184
  target.__BACKGROUND__ = true;
@@ -207,8 +218,7 @@ function injectBackgroundThreadGlobals(target, polyfills) {
207
218
  };
208
219
  target.requestAnimationFrame = setTimeout;
209
220
  target.cancelAnimationFrame = clearTimeout;
210
- target.console.profile = ()=>{};
211
- target.console.profileEnd = ()=>{};
221
+ target.console = createPreconfiguredConsole();
212
222
  target.SystemInfo = {
213
223
  platform: 'iOS',
214
224
  pixelRatio: 3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/testing-environment",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A subset of a Lynx environment to be useful for testing",
5
5
  "keywords": [
6
6
  "Lynx",