@react-native-harness/runtime 1.0.0-alpha.1

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.
Files changed (229) hide show
  1. package/.babelrc.js +23 -0
  2. package/LICENSE +20 -0
  3. package/README.md +7 -0
  4. package/assets/logo.png +0 -0
  5. package/assets/moduleSystem.flow.js +1062 -0
  6. package/dist/bundler/bundle.d.ts +2 -0
  7. package/dist/bundler/bundle.d.ts.map +1 -0
  8. package/dist/bundler/bundle.js +16 -0
  9. package/dist/bundler/dev-server.d.ts +2 -0
  10. package/dist/bundler/dev-server.d.ts.map +1 -0
  11. package/dist/bundler/dev-server.js +5 -0
  12. package/dist/bundler/errors.d.ts +10 -0
  13. package/dist/bundler/errors.d.ts.map +1 -0
  14. package/dist/bundler/errors.js +18 -0
  15. package/dist/bundler/evaluate.d.ts +2 -0
  16. package/dist/bundler/evaluate.d.ts.map +1 -0
  17. package/dist/bundler/evaluate.js +18 -0
  18. package/dist/bundler/index.d.ts +3 -0
  19. package/dist/bundler/index.d.ts.map +1 -0
  20. package/dist/bundler/index.js +2 -0
  21. package/dist/client/factory.d.ts +2 -0
  22. package/dist/client/factory.d.ts.map +1 -0
  23. package/dist/client/factory.js +41 -0
  24. package/dist/client/getDeviceDescriptor.d.ts +8 -0
  25. package/dist/client/getDeviceDescriptor.d.ts.map +1 -0
  26. package/dist/client/getDeviceDescriptor.js +20 -0
  27. package/dist/client/getWSServer.d.ts +2 -0
  28. package/dist/client/getWSServer.d.ts.map +1 -0
  29. package/dist/client/getWSServer.js +7 -0
  30. package/dist/client/index.d.ts +2 -0
  31. package/dist/client/index.d.ts.map +1 -0
  32. package/dist/client/index.js +1 -0
  33. package/dist/collector/errors.d.ts +8 -0
  34. package/dist/collector/errors.d.ts.map +1 -0
  35. package/dist/collector/errors.js +20 -0
  36. package/dist/collector/factory.d.ts +3 -0
  37. package/dist/collector/factory.d.ts.map +1 -0
  38. package/dist/collector/factory.js +25 -0
  39. package/dist/collector/functions.d.ts +22 -0
  40. package/dist/collector/functions.d.ts.map +1 -0
  41. package/dist/collector/functions.js +271 -0
  42. package/dist/collector/index.d.ts +5 -0
  43. package/dist/collector/index.d.ts.map +1 -0
  44. package/dist/collector/index.js +3 -0
  45. package/dist/collector/types.d.ts +10 -0
  46. package/dist/collector/types.d.ts.map +1 -0
  47. package/dist/collector/types.js +1 -0
  48. package/dist/collector/validation.d.ts +4 -0
  49. package/dist/collector/validation.d.ts.map +1 -0
  50. package/dist/collector/validation.js +15 -0
  51. package/dist/constants.d.ts +3 -0
  52. package/dist/constants.d.ts.map +1 -0
  53. package/dist/constants.js +2 -0
  54. package/dist/errors.d.ts +6 -0
  55. package/dist/errors.d.ts.map +1 -0
  56. package/dist/errors.js +13 -0
  57. package/dist/expect/index.d.ts +9 -0
  58. package/dist/expect/index.d.ts.map +1 -0
  59. package/dist/expect/index.js +71 -0
  60. package/dist/expect/setup.d.ts +2 -0
  61. package/dist/expect/setup.d.ts.map +1 -0
  62. package/dist/expect/setup.js +5 -0
  63. package/dist/exports.d.ts +7 -0
  64. package/dist/exports.d.ts.map +1 -0
  65. package/dist/exports.js +6 -0
  66. package/dist/getEntryComponent.d.ts +6 -0
  67. package/dist/getEntryComponent.d.ts.map +1 -0
  68. package/dist/getEntryComponent.js +6 -0
  69. package/dist/globals.d.ts +5 -0
  70. package/dist/globals.d.ts.map +1 -0
  71. package/dist/globals.js +1 -0
  72. package/dist/index.d.ts +7 -0
  73. package/dist/index.d.ts.map +1 -0
  74. package/dist/index.js +6 -0
  75. package/dist/initialize.d.ts +2 -0
  76. package/dist/initialize.d.ts.map +1 -0
  77. package/dist/initialize.js +16 -0
  78. package/dist/logger.d.ts +6 -0
  79. package/dist/logger.d.ts.map +1 -0
  80. package/dist/logger.js +14 -0
  81. package/dist/mock.d.ts +15 -0
  82. package/dist/mock.d.ts.map +1 -0
  83. package/dist/mock.js +37 -0
  84. package/dist/mocker/index.d.ts +2 -0
  85. package/dist/mocker/index.d.ts.map +1 -0
  86. package/dist/mocker/index.js +1 -0
  87. package/dist/mocker/registry.d.ts +7 -0
  88. package/dist/mocker/registry.d.ts.map +1 -0
  89. package/dist/mocker/registry.js +41 -0
  90. package/dist/mocker/types.d.ts +6 -0
  91. package/dist/mocker/types.d.ts.map +1 -0
  92. package/dist/mocker/types.js +1 -0
  93. package/dist/module.d.ts +3 -0
  94. package/dist/module.d.ts.map +1 -0
  95. package/dist/module.js +19 -0
  96. package/dist/module.web.d.ts +2 -0
  97. package/dist/module.web.d.ts.map +1 -0
  98. package/dist/module.web.js +12 -0
  99. package/dist/rntl/client.d.ts +3 -0
  100. package/dist/rntl/client.d.ts.map +1 -0
  101. package/dist/rntl/client.js +8 -0
  102. package/dist/rntl/describe.d.ts +2 -0
  103. package/dist/rntl/describe.d.ts.map +1 -0
  104. package/dist/rntl/describe.js +1 -0
  105. package/dist/rntl/expect.d.ts +128 -0
  106. package/dist/rntl/expect.d.ts.map +1 -0
  107. package/dist/rntl/expect.js +670 -0
  108. package/dist/rntl/fn.d.ts +2 -0
  109. package/dist/rntl/fn.d.ts.map +1 -0
  110. package/dist/rntl/fn.js +1 -0
  111. package/dist/rntl/mock.d.ts +2 -0
  112. package/dist/rntl/mock.d.ts.map +1 -0
  113. package/dist/rntl/mock.js +1 -0
  114. package/dist/rntl/render.d.ts +4 -0
  115. package/dist/rntl/render.d.ts.map +1 -0
  116. package/dist/rntl/render.js +11 -0
  117. package/dist/rntl/screen.d.ts +45 -0
  118. package/dist/rntl/screen.d.ts.map +1 -0
  119. package/dist/rntl/screen.js +31 -0
  120. package/dist/rntl/spies.d.ts +45 -0
  121. package/dist/rntl/spies.d.ts.map +1 -0
  122. package/dist/rntl/spies.js +553 -0
  123. package/dist/rntl/userEvent.d.ts +22 -0
  124. package/dist/rntl/userEvent.d.ts.map +1 -0
  125. package/dist/rntl/userEvent.js +19 -0
  126. package/dist/runner/errors.d.ts +9 -0
  127. package/dist/runner/errors.d.ts.map +1 -0
  128. package/dist/runner/errors.js +23 -0
  129. package/dist/runner/factory.d.ts +3 -0
  130. package/dist/runner/factory.d.ts.map +1 -0
  131. package/dist/runner/factory.js +17 -0
  132. package/dist/runner/hooks.d.ts +4 -0
  133. package/dist/runner/hooks.d.ts.map +1 -0
  134. package/dist/runner/hooks.js +39 -0
  135. package/dist/runner/index.d.ts +4 -0
  136. package/dist/runner/index.d.ts.map +1 -0
  137. package/dist/runner/index.js +2 -0
  138. package/dist/runner/runSuite.d.ts +4 -0
  139. package/dist/runner/runSuite.d.ts.map +1 -0
  140. package/dist/runner/runSuite.js +147 -0
  141. package/dist/runner/types.d.ts +13 -0
  142. package/dist/runner/types.d.ts.map +1 -0
  143. package/dist/runner/types.js +1 -0
  144. package/dist/runner.d.ts +7 -0
  145. package/dist/runner.d.ts.map +1 -0
  146. package/dist/runner.js +201 -0
  147. package/dist/runtime.d.ts +2 -0
  148. package/dist/runtime.d.ts.map +1 -0
  149. package/dist/runtime.js +44 -0
  150. package/dist/spy/index.d.ts +2 -0
  151. package/dist/spy/index.d.ts.map +1 -0
  152. package/dist/spy/index.js +2 -0
  153. package/dist/state.d.ts +25 -0
  154. package/dist/state.d.ts.map +1 -0
  155. package/dist/state.js +37 -0
  156. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  157. package/dist/ui/ReadyScreen.d.ts +2 -0
  158. package/dist/ui/ReadyScreen.d.ts.map +1 -0
  159. package/dist/ui/ReadyScreen.js +110 -0
  160. package/dist/ui/UI.d.ts +13 -0
  161. package/dist/ui/UI.d.ts.map +1 -0
  162. package/dist/ui/UI.js +121 -0
  163. package/dist/ui/WrongEnvironmentScreen.d.ts +2 -0
  164. package/dist/ui/WrongEnvironmentScreen.d.ts.map +1 -0
  165. package/dist/ui/WrongEnvironmentScreen.js +87 -0
  166. package/dist/ui/index.d.ts +2 -0
  167. package/dist/ui/index.d.ts.map +1 -0
  168. package/dist/ui/index.js +3 -0
  169. package/dist/ui/state.d.ts +7 -0
  170. package/dist/ui/state.d.ts.map +1 -0
  171. package/dist/ui/state.js +6 -0
  172. package/dist/utils/dev-server.d.ts +2 -0
  173. package/dist/utils/dev-server.d.ts.map +1 -0
  174. package/dist/utils/dev-server.js +5 -0
  175. package/dist/utils/emitter.d.ts +16 -0
  176. package/dist/utils/emitter.d.ts.map +1 -0
  177. package/dist/utils/emitter.js +39 -0
  178. package/eslint.config.mjs +16 -0
  179. package/package.json +38 -0
  180. package/src/__tests__/collector.test.ts +553 -0
  181. package/src/__tests__/error-handling.test.ts +132 -0
  182. package/src/__tests__/expect.test.ts +619 -0
  183. package/src/__tests__/spy.test.ts +538 -0
  184. package/src/bundler/bundle.ts +19 -0
  185. package/src/bundler/errors.ts +16 -0
  186. package/src/bundler/evaluate.ts +25 -0
  187. package/src/bundler/index.ts +2 -0
  188. package/src/client/factory.ts +56 -0
  189. package/src/client/getDeviceDescriptor.ts +30 -0
  190. package/src/client/getWSServer.ts +9 -0
  191. package/src/client/index.ts +1 -0
  192. package/src/collector/errors.ts +27 -0
  193. package/src/collector/factory.ts +32 -0
  194. package/src/collector/functions.ts +376 -0
  195. package/src/collector/index.ts +12 -0
  196. package/src/collector/types.ts +15 -0
  197. package/src/collector/validation.ts +21 -0
  198. package/src/constants.ts +2 -0
  199. package/src/errors.ts +12 -0
  200. package/src/expect/index.ts +117 -0
  201. package/src/expect/setup.ts +10 -0
  202. package/src/globals.ts +5 -0
  203. package/src/index.ts +7 -0
  204. package/src/initialize.ts +22 -0
  205. package/src/mocker/index.ts +1 -0
  206. package/src/mocker/metro-require.d.ts +5 -0
  207. package/src/mocker/registry.ts +58 -0
  208. package/src/mocker/types.ts +6 -0
  209. package/src/react-native.d.ts +16 -0
  210. package/src/runner/errors.ts +31 -0
  211. package/src/runner/factory.ts +21 -0
  212. package/src/runner/hooks.ts +51 -0
  213. package/src/runner/index.ts +7 -0
  214. package/src/runner/runSuite.ts +201 -0
  215. package/src/runner/types.ts +19 -0
  216. package/src/spy/index.ts +2 -0
  217. package/src/ui/ReadyScreen.tsx +151 -0
  218. package/src/ui/WrongEnvironmentScreen.tsx +113 -0
  219. package/src/ui/index.ts +3 -0
  220. package/src/ui/state.ts +13 -0
  221. package/src/utils/dev-server.ts +6 -0
  222. package/src/utils/emitter.ts +64 -0
  223. package/tsconfig.json +16 -0
  224. package/tsconfig.lib.json +33 -0
  225. package/tsconfig.spec.json +30 -0
  226. package/tsconfig.tsbuildinfo +1 -0
  227. package/types/global.d.ts +2 -0
  228. package/types/index.d.ts +1 -0
  229. package/vite.config.ts +27 -0
@@ -0,0 +1,15 @@
1
+ import { TestError } from './errors.js';
2
+ export const validateTestName = (name, functionName) => {
3
+ if (!name || typeof name !== 'string' || name.trim() === '') {
4
+ throw new TestError('INVALID_TEST_NAME', functionName, {
5
+ name,
6
+ });
7
+ }
8
+ };
9
+ export const validateTestFunction = (fn, functionName) => {
10
+ if (typeof fn !== 'function') {
11
+ throw new TestError('INVALID_FUNCTION', functionName, {
12
+ functionType: typeof fn,
13
+ });
14
+ }
15
+ };
@@ -0,0 +1,3 @@
1
+ export declare const LOGO_IMAGE: any;
2
+ export declare const WS_SERVER_PORT = 3001;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,KAAgC,CAAC;AACxD,eAAO,MAAM,cAAc,OAAO,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const LOGO_IMAGE = require('../assets/logo.png');
2
+ export const WS_SERVER_PORT = 3001;
@@ -0,0 +1,6 @@
1
+ export declare class EnvironmentError extends Error {
2
+ readonly context: string;
3
+ readonly details?: string | undefined;
4
+ constructor(context: string, details?: string | undefined);
5
+ }
6
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,gBAAiB,SAAQ,KAAK;aAEvB,OAAO,EAAE,MAAM;aACf,OAAO,CAAC,EAAE,MAAM;gBADhB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,MAAM,YAAA;CAQnC"}
package/dist/errors.js ADDED
@@ -0,0 +1,13 @@
1
+ export class EnvironmentError extends Error {
2
+ context;
3
+ details;
4
+ constructor(context, details) {
5
+ const message = details
6
+ ? `Environment error in ${context}: ${details}`
7
+ : `Environment error: ${context}`;
8
+ super(message);
9
+ this.context = context;
10
+ this.details = details;
11
+ this.name = 'EnvironmentError';
12
+ }
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { ExpectStatic } from '@vitest/expect';
2
+ import * as chai from 'chai';
3
+ import './setup.js';
4
+ export declare function createExpect(): ExpectStatic;
5
+ declare const globalExpect: ExpectStatic;
6
+ export { assert, should } from 'chai';
7
+ export { chai, globalExpect as expect };
8
+ export type { Assertion, AsymmetricMatchersContaining, DeeplyAllowMatchers, ExpectStatic, JestAssertion, Matchers, } from '@vitest/expect';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/expect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAS5E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,OAAO,YAAY,CAAC;AAEpB,wBAAgB,YAAY,IAAI,YAAY,CAkF3C;AAED,QAAA,MAAM,YAAY,EAAE,YAA6B,CAAC;AAQlD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,YAAY,IAAI,MAAM,EAAE,CAAC;AAExC,YAAY,EACV,SAAS,EACT,4BAA4B,EAC5B,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,QAAQ,GACT,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { addCustomEqualityTesters, ASYMMETRIC_MATCHERS_OBJECT, customMatchers, getState, GLOBAL_EXPECT, setState, } from '@vitest/expect';
2
+ import * as chai from 'chai';
3
+ // Setup additional matchers
4
+ import './setup.js';
5
+ export function createExpect() {
6
+ const expect = ((value, message) => {
7
+ const { assertionCalls } = getState(expect);
8
+ setState({ assertionCalls: assertionCalls + 1 }, expect);
9
+ return chai.expect(value, message);
10
+ });
11
+ Object.assign(expect, chai.expect);
12
+ Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
13
+ expect.getState = () => getState(expect);
14
+ expect.setState = (state) => setState(state, expect);
15
+ // @ts-expect-error global is not typed
16
+ const globalState = getState(globalThis[GLOBAL_EXPECT]) || {};
17
+ setState({
18
+ // this should also add "snapshotState" that is added conditionally
19
+ ...globalState,
20
+ assertionCalls: 0,
21
+ isExpectingAssertions: false,
22
+ isExpectingAssertionsError: null,
23
+ expectedAssertionsNumber: null,
24
+ expectedAssertionsNumberErrorGen: null,
25
+ }, expect);
26
+ // @ts-expect-error untyped
27
+ expect.extend = (matchers) => chai.expect.extend(expect, matchers);
28
+ // @ts-expect-error untyped
29
+ expect.addEqualityTesters = (customTesters) => addCustomEqualityTesters(customTesters);
30
+ // @ts-expect-error untyped
31
+ expect.soft = (...args) => {
32
+ // @ts-expect-error private soft access
33
+ return expect(...args).withContext({ soft: true });
34
+ };
35
+ // @ts-expect-error untyped
36
+ expect.unreachable = (message) => {
37
+ chai.assert.fail(`expected${message ? ` "${message}" ` : ' '}not to be reached`);
38
+ };
39
+ function assertions(expected) {
40
+ const errorGen = () => new Error(`expected number of assertions to be ${expected}, but got ${expect.getState().assertionCalls}`);
41
+ if (Error.captureStackTrace) {
42
+ Error.captureStackTrace(errorGen(), assertions);
43
+ }
44
+ expect.setState({
45
+ expectedAssertionsNumber: expected,
46
+ expectedAssertionsNumberErrorGen: errorGen,
47
+ });
48
+ }
49
+ function hasAssertions() {
50
+ const error = new Error('expected any number of assertion, but got none');
51
+ if (Error.captureStackTrace) {
52
+ Error.captureStackTrace(error, hasAssertions);
53
+ }
54
+ expect.setState({
55
+ isExpectingAssertions: true,
56
+ isExpectingAssertionsError: error,
57
+ });
58
+ }
59
+ chai.util.addMethod(expect, 'assertions', assertions);
60
+ chai.util.addMethod(expect, 'hasAssertions', hasAssertions);
61
+ expect.extend(customMatchers);
62
+ return expect;
63
+ }
64
+ const globalExpect = createExpect();
65
+ Object.defineProperty(globalThis, GLOBAL_EXPECT, {
66
+ value: globalExpect,
67
+ writable: true,
68
+ configurable: true,
69
+ });
70
+ export { assert, should } from 'chai';
71
+ export { chai, globalExpect as expect };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/expect/setup.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { JestAsymmetricMatchers, JestChaiExpect, JestExtend, } from '@vitest/expect';
2
+ import * as chai from 'chai';
3
+ chai.use(JestExtend);
4
+ chai.use(JestChaiExpect);
5
+ chai.use(JestAsymmetricMatchers);
@@ -0,0 +1,7 @@
1
+ export { UI } from './ui/UI.js';
2
+ export { getEntryComponent } from './getEntryComponent.js';
3
+ export * from './spy/index.js';
4
+ export * from './expect/index.js';
5
+ export * from './collector/index.js';
6
+ export * from './mocker/index.js';
7
+ //# sourceMappingURL=exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../src/exports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,YAAY,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,6 @@
1
+ export { UI } from './ui/UI.js';
2
+ export { getEntryComponent } from './getEntryComponent.js';
3
+ export * from './spy/index.js';
4
+ export * from './expect/index.js';
5
+ export * from './collector/index.js';
6
+ export * from './mocker/index.js';
@@ -0,0 +1,6 @@
1
+ import { ComponentType } from 'react';
2
+ declare global {
3
+ var RN_HARNESS: boolean;
4
+ }
5
+ export declare const getEntryComponent: (Component: ComponentType) => any;
6
+ //# sourceMappingURL=getEntryComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getEntryComponent.d.ts","sourceRoot":"","sources":["../src/getEntryComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,OAAO,CAAC;AAEpC,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,UAAU,EAAE,OAAO,CAAC;CACzB;AAED,eAAO,MAAM,iBAAiB,GAAI,WAAW,aAAa,QAMzD,CAAC"}
@@ -0,0 +1,6 @@
1
+ export const getEntryComponent = (Component) => {
2
+ if ('RN_HARNESS' in global) {
3
+ return require('./ui/UI').default;
4
+ }
5
+ return Component;
6
+ };
@@ -0,0 +1,5 @@
1
+ declare global {
2
+ var RN_HARNESS: boolean | undefined;
3
+ }
4
+ export {};
5
+ //# sourceMappingURL=globals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC;CACrC;AAED,OAAO,EAAE,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import './globals.d.ts';
2
+ export { UI as ReactNativeHarness } from './ui/index.js';
3
+ export * from './spy/index.js';
4
+ export * from './expect/index.js';
5
+ export * from './collector/index.js';
6
+ export * from './mocker/index.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AAExB,OAAO,EAAE,EAAE,IAAI,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACzD,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import './globals.d.ts';
2
+ export { UI as ReactNativeHarness } from './ui/index.js';
3
+ export * from './spy/index.js';
4
+ export * from './expect/index.js';
5
+ export * from './collector/index.js';
6
+ export * from './mocker/index.js';
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=initialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../src/initialize.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import { getDeviceDescriptor } from './client/getDeviceDescriptor.js';
2
+ import { getClient } from './client/index.js';
3
+ // Polyfill for EventTarget
4
+ const Shim = require('event-target-shim');
5
+ globalThis.Event = Shim.Event;
6
+ globalThis.EventTarget = Shim.EventTarget;
7
+ // Turn off LogBox
8
+ const { LogBox } = require('react-native');
9
+ LogBox.ignoreAllLogs(true);
10
+ // Turn off HMR
11
+ const HMRClient = require('react-native/Libraries/Utilities/HMRClient');
12
+ HMRClient.setup = () => {
13
+ // No setup = no HMR
14
+ };
15
+ // Initialize the client
16
+ void getClient().then((client) => client.rpc.reportReady(getDeviceDescriptor()));
@@ -0,0 +1,6 @@
1
+ export declare const logger: {
2
+ info: (...args: unknown[]) => void;
3
+ error: (...args: unknown[]) => void;
4
+ log: (...args: unknown[]) => void;
5
+ };
6
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM;oBACD,OAAO,EAAE;qBAGR,OAAO,EAAE;mBAGX,OAAO,EAAE;CAKzB,CAAC"}
package/dist/logger.js ADDED
@@ -0,0 +1,14 @@
1
+ const verbose = global.RN_HARNESS.verbose;
2
+ export const logger = {
3
+ info: (...args) => {
4
+ console.info(...args);
5
+ },
6
+ error: (...args) => {
7
+ console.error(...args);
8
+ },
9
+ log: (...args) => {
10
+ if (verbose) {
11
+ console.log(...args);
12
+ }
13
+ },
14
+ };
package/dist/mock.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ type ModuleId = number;
2
+ type Require = {
3
+ (moduleId: number): unknown;
4
+ };
5
+ declare global {
6
+ var __r: Require;
7
+ }
8
+ export type ModuleFactory = () => unknown;
9
+ export declare const mock: (moduleId: ModuleId, factory: ModuleFactory) => void;
10
+ export declare const clearMocks: () => void;
11
+ export declare const getMockRegistry: () => Map<number, ModuleFactory>;
12
+ export declare const getMockImplementation: (moduleId: number) => unknown | null;
13
+ export declare const requireActual: <T = any>(moduleId: ModuleId) => T;
14
+ export {};
15
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAAA,KAAK,QAAQ,GAAG,MAAM,CAAC;AACvB,KAAK,OAAO,GAAG;IACb,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B,CAAC;AACF,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,GAAG,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC;AAO1C,eAAO,MAAM,IAAI,GAAI,UAAU,QAAQ,EAAE,SAAS,aAAa,KAAG,IAGjE,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,IAG7B,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,GAAG,CAAC,MAAM,EAAE,aAAa,CAE3D,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,KAAG,OAAO,GAAG,IAalE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,CAAC,GAAG,GAAG,EAAE,UAAU,QAAQ,KAAG,CAC5B,CAAC"}
package/dist/mock.js ADDED
@@ -0,0 +1,37 @@
1
+ const mockRegistry = new Map();
2
+ const mockCache = new Map();
3
+ const originalRequire = global.__r;
4
+ export const mock = (moduleId, factory) => {
5
+ mockCache.delete(moduleId);
6
+ mockRegistry.set(moduleId, factory);
7
+ };
8
+ export const clearMocks = () => {
9
+ mockRegistry.clear();
10
+ mockCache.clear();
11
+ };
12
+ export const getMockRegistry = () => {
13
+ return mockRegistry;
14
+ };
15
+ export const getMockImplementation = (moduleId) => {
16
+ if (mockCache.has(moduleId)) {
17
+ return mockCache.get(moduleId);
18
+ }
19
+ const factory = mockRegistry.get(moduleId);
20
+ if (!factory) {
21
+ return null;
22
+ }
23
+ const implementation = factory();
24
+ mockCache.set(moduleId, implementation);
25
+ return implementation;
26
+ };
27
+ export const requireActual = (moduleId) => originalRequire(moduleId);
28
+ const mockRequire = (moduleId) => {
29
+ const mockedModule = getMockImplementation(moduleId);
30
+ if (mockedModule) {
31
+ return mockedModule;
32
+ }
33
+ return originalRequire(moduleId);
34
+ };
35
+ Object.setPrototypeOf(mockRequire, Object.getPrototypeOf(originalRequire));
36
+ Object.defineProperties(mockRequire, Object.getOwnPropertyDescriptors(originalRequire));
37
+ global.__r = mockRequire;
@@ -0,0 +1,2 @@
1
+ export { mock, requireActual, clearMocks } from './registry.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mocker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1 @@
1
+ export { mock, requireActual, clearMocks } from './registry.js';
@@ -0,0 +1,7 @@
1
+ import { ModuleFactory, ModuleId } from './types.js';
2
+ export declare const mock: (moduleId: ModuleId, factory: ModuleFactory) => void;
3
+ export declare const clearMocks: () => void;
4
+ export declare const getMockRegistry: () => Map<number, ModuleFactory>;
5
+ export declare const getMockImplementation: (moduleId: number) => unknown | null;
6
+ export declare const requireActual: <T = any>(moduleId: string) => T;
7
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/mocker/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAW,MAAM,YAAY,CAAC;AAO9D,eAAO,MAAM,IAAI,GAAI,UAAU,QAAQ,EAAE,SAAS,aAAa,KAAG,IAGjE,CAAC;AAEF,eAAO,MAAM,UAAU,QAAO,IAG7B,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,GAAG,CAAC,MAAM,EAAE,aAAa,CAE3D,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,KAAG,OAAO,GAAG,IAalE,CAAC;AAGF,eAAO,MAAM,aAAa,GAAI,CAAC,GAAG,GAAG,EAAE,UAAU,MAAM,KAAG,CAEH,CAAC"}
@@ -0,0 +1,41 @@
1
+ const mockRegistry = new Map();
2
+ const mockCache = new Map();
3
+ const originalRequire = global.__r;
4
+ export const mock = (moduleId, factory) => {
5
+ mockCache.delete(moduleId);
6
+ mockRegistry.set(moduleId, factory);
7
+ };
8
+ export const clearMocks = () => {
9
+ mockRegistry.clear();
10
+ mockCache.clear();
11
+ };
12
+ export const getMockRegistry = () => {
13
+ return mockRegistry;
14
+ };
15
+ export const getMockImplementation = (moduleId) => {
16
+ if (mockCache.has(moduleId)) {
17
+ return mockCache.get(moduleId);
18
+ }
19
+ const factory = mockRegistry.get(moduleId);
20
+ if (!factory) {
21
+ return null;
22
+ }
23
+ const implementation = factory();
24
+ mockCache.set(moduleId, implementation);
25
+ return implementation;
26
+ };
27
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
+ export const requireActual = (moduleId) =>
29
+ // babel plugin will transform 'moduleId' to a number
30
+ originalRequire(moduleId);
31
+ const mockRequire = (moduleId) => {
32
+ // babel plugin will transform 'moduleId' to a number
33
+ const mockedModule = getMockImplementation(moduleId);
34
+ if (mockedModule) {
35
+ return mockedModule;
36
+ }
37
+ return originalRequire(moduleId);
38
+ };
39
+ Object.setPrototypeOf(mockRequire, Object.getPrototypeOf(originalRequire));
40
+ Object.defineProperties(mockRequire, Object.getOwnPropertyDescriptors(originalRequire));
41
+ global.__r = mockRequire;
@@ -0,0 +1,6 @@
1
+ export type ModuleId = number;
2
+ export type Require = {
3
+ (moduleId: number): unknown;
4
+ };
5
+ export type ModuleFactory = () => unknown;
6
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mocker/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAC9B,MAAM,MAAM,OAAO,GAAG;IACpB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export declare const fetchModule: (fileName: string) => Promise<string>;
2
+ export declare const executeModule: (moduleJs: string) => void;
3
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,WAAW,GAAU,UAAU,MAAM,KAAG,OAAO,CAAC,MAAM,CAIlE,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,UAAU,MAAM,KAAG,IAQhD,CAAC"}
package/dist/module.js ADDED
@@ -0,0 +1,19 @@
1
+ import { Platform } from 'react-native';
2
+ const METRO_URL = 'http://localhost:8081';
3
+ const getModuleUrl = (fileName) => {
4
+ const bundleName = fileName.split('.').slice(0, -1).join('.') + '.bundle';
5
+ return `${METRO_URL}/${bundleName}?modulesOnly=true&platform=${Platform.OS}`;
6
+ };
7
+ export const fetchModule = async (fileName) => {
8
+ const url = getModuleUrl(fileName);
9
+ const response = await fetch(url);
10
+ return response.text();
11
+ };
12
+ export const executeModule = (moduleJs) => {
13
+ const __rMatch = moduleJs.match(/__r\((\d+)\)/);
14
+ const __rParam = __rMatch[1];
15
+ // eslint-disable-next-line no-eval
16
+ eval(moduleJs);
17
+ // @ts-ignore - __r is injected by Metro bundler
18
+ __r(Number(__rParam));
19
+ };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=module.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.web.d.ts","sourceRoot":"","sources":["../src/module.web.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ // const context = require.context('../..', false, /\.test.tsx$/);
2
+ export {};
3
+ // export const fetchModule = async (fileName: string): Promise<string> => {
4
+ // return fileName;
5
+ // };
6
+ // export const executeModule = (moduleJs: string): void => {
7
+ // const modulePath = `./${moduleJs}`;
8
+ // if (!context.keys().includes(modulePath)) {
9
+ // throw new Error(`Module ${moduleJs} not found`);
10
+ // }
11
+ // return context(modulePath);
12
+ // };
@@ -0,0 +1,3 @@
1
+ import { BridgeClient } from '@react-native-harness/bridge/client';
2
+ export declare const getClient: () => BridgeClient;
3
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/rntl/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAGnE,eAAO,MAAM,SAAS,QAAO,YAU5B,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { state } from '../state.js';
2
+ export const getClient = () => {
3
+ const client = state.getState().client;
4
+ if (!client) {
5
+ throw new Error('Client not found. Are you sure you are running the test in the react-native-harness environment?');
6
+ }
7
+ return client;
8
+ };
@@ -0,0 +1,2 @@
1
+ export { describe, test, it } from '../collector/functions.js';
2
+ //# sourceMappingURL=describe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"describe.d.ts","sourceRoot":"","sources":["../../src/rntl/describe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1 @@
1
+ export { describe, test, it } from '../collector/functions.js';
@@ -0,0 +1,128 @@
1
+ declare const ASYMMETRIC_MATCHER: unique symbol;
2
+ interface AsymmetricMatcher {
3
+ [ASYMMETRIC_MATCHER]: true;
4
+ asymmetricMatch(other: unknown): boolean;
5
+ toString(): string;
6
+ }
7
+ declare class AnythingMatcher implements AsymmetricMatcher {
8
+ [ASYMMETRIC_MATCHER]: true;
9
+ asymmetricMatch(other: unknown): boolean;
10
+ toString(): string;
11
+ }
12
+ declare class AnyMatcher implements AsymmetricMatcher {
13
+ private expectedType;
14
+ [ASYMMETRIC_MATCHER]: true;
15
+ constructor(expectedType: new (...args: unknown[]) => unknown);
16
+ asymmetricMatch(other: unknown): boolean;
17
+ toString(): string;
18
+ }
19
+ declare class ArrayContainingMatcher implements AsymmetricMatcher {
20
+ private expectedArray;
21
+ [ASYMMETRIC_MATCHER]: true;
22
+ constructor(expectedArray: unknown[]);
23
+ asymmetricMatch(other: unknown): boolean;
24
+ toString(): string;
25
+ }
26
+ declare class ObjectContainingMatcher implements AsymmetricMatcher {
27
+ private expectedObject;
28
+ [ASYMMETRIC_MATCHER]: true;
29
+ constructor(expectedObject: Record<string, unknown>);
30
+ asymmetricMatch(other: unknown): boolean;
31
+ toString(): string;
32
+ }
33
+ declare class StringContainingMatcher implements AsymmetricMatcher {
34
+ private expectedString;
35
+ [ASYMMETRIC_MATCHER]: true;
36
+ constructor(expectedString: string);
37
+ asymmetricMatch(other: unknown): boolean;
38
+ toString(): string;
39
+ }
40
+ declare class StringMatchingMatcher implements AsymmetricMatcher {
41
+ private expectedPattern;
42
+ [ASYMMETRIC_MATCHER]: true;
43
+ constructor(expectedPattern: string | RegExp);
44
+ asymmetricMatch(other: unknown): boolean;
45
+ toString(): string;
46
+ }
47
+ declare class ArrayOfMatcher implements AsymmetricMatcher {
48
+ private expectedValue;
49
+ [ASYMMETRIC_MATCHER]: true;
50
+ constructor(expectedValue: unknown);
51
+ asymmetricMatch(other: unknown): boolean;
52
+ toString(): string;
53
+ }
54
+ declare class CloseToMatcher implements AsymmetricMatcher {
55
+ private expectedNumber;
56
+ private numDigits;
57
+ [ASYMMETRIC_MATCHER]: true;
58
+ constructor(expectedNumber: number, numDigits?: number);
59
+ asymmetricMatch(other: unknown): boolean;
60
+ toString(): string;
61
+ }
62
+ declare class NotMatcher implements AsymmetricMatcher {
63
+ private innerMatcher;
64
+ [ASYMMETRIC_MATCHER]: true;
65
+ constructor(innerMatcher: AsymmetricMatcher);
66
+ asymmetricMatch(other: unknown): boolean;
67
+ toString(): string;
68
+ }
69
+ interface Matchers {
70
+ toBe(expected: unknown): void;
71
+ toEqual(expected: unknown): void;
72
+ toStrictEqual(expected: unknown): void;
73
+ toBeTruthy(): void;
74
+ toBeFalsy(): void;
75
+ toBeNull(): void;
76
+ toBeUndefined(): void;
77
+ toBeDefined(): void;
78
+ toBeInstanceOf(expected: new (...args: unknown[]) => unknown): void;
79
+ toContain(expected: unknown): void;
80
+ toContainEqual(expected: unknown): void;
81
+ toHaveLength(expected: number): void;
82
+ toHaveProperty(keyPath: string | string[], value?: unknown): void;
83
+ toBeCloseTo(expected: number, numDigits?: number): void;
84
+ toBeGreaterThan(expected: number | bigint): void;
85
+ toBeGreaterThanOrEqual(expected: number | bigint): void;
86
+ toBeLessThan(expected: number | bigint): void;
87
+ toBeLessThanOrEqual(expected: number | bigint): void;
88
+ toBeNaN(): void;
89
+ toMatch(expected: string | RegExp): void;
90
+ toMatchObject(expected: Record<string, unknown>): void;
91
+ toThrow(expected?: string | RegExp | Error): void;
92
+ toHaveBeenCalled(): void;
93
+ toHaveBeenCalledTimes(expected: number): void;
94
+ toHaveBeenCalledWith(...expected: unknown[]): void;
95
+ toHaveBeenLastCalledWith(...expected: unknown[]): void;
96
+ toHaveBeenNthCalledWith(nthCall: number, ...expected: unknown[]): void;
97
+ toHaveReturned(): void;
98
+ toHaveReturnedTimes(expected: number): void;
99
+ toHaveReturnedWith(expected: unknown): void;
100
+ toHaveLastReturnedWith(expected: unknown): void;
101
+ toHaveNthReturnedWith(nthCall: number, expected: unknown): void;
102
+ }
103
+ interface ExpectResult extends Matchers {
104
+ not: Matchers;
105
+ }
106
+ export declare const asymmetricMatchers: {
107
+ anything: () => AnythingMatcher;
108
+ any: (expectedType: new (...args: unknown[]) => unknown) => AnyMatcher;
109
+ arrayContaining: (expectedArray: unknown[]) => ArrayContainingMatcher;
110
+ objectContaining: (expectedObject: Record<string, unknown>) => ObjectContainingMatcher;
111
+ stringContaining: (expectedString: string) => StringContainingMatcher;
112
+ stringMatching: (expectedPattern: string | RegExp) => StringMatchingMatcher;
113
+ arrayOf: (expectedValue: unknown) => ArrayOfMatcher;
114
+ closeTo: (expectedNumber: number, numDigits?: number) => CloseToMatcher;
115
+ not: {
116
+ arrayContaining: (expectedArray: unknown[]) => NotMatcher;
117
+ objectContaining: (expectedObject: Record<string, unknown>) => NotMatcher;
118
+ stringContaining: (expectedString: string) => NotMatcher;
119
+ stringMatching: (expectedPattern: string | RegExp) => NotMatcher;
120
+ arrayOf: (expectedValue: unknown) => NotMatcher;
121
+ };
122
+ };
123
+ type ExpectStatic = {
124
+ (actual: unknown): ExpectResult;
125
+ } & typeof asymmetricMatchers;
126
+ export declare const expect: ExpectStatic;
127
+ export {};
128
+ //# sourceMappingURL=expect.d.ts.map