@react-native-harness/runtime 1.1.0 → 1.2.0

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 (212) hide show
  1. package/dist/NativeHarness.d.ts +41 -0
  2. package/dist/NativeHarness.d.ts.map +1 -0
  3. package/dist/NativeHarness.js +2 -0
  4. package/dist/client/factory.d.ts +2 -1
  5. package/dist/client/factory.d.ts.map +1 -1
  6. package/dist/client/factory.js +53 -59
  7. package/dist/client/store.d.ts +3 -3
  8. package/dist/client/store.d.ts.map +1 -1
  9. package/dist/client/store.js +7 -7
  10. package/dist/constants.d.ts +2 -0
  11. package/dist/constants.d.ts.map +1 -0
  12. package/dist/constants.js +1 -0
  13. package/dist/expect/context.d.ts +20 -0
  14. package/dist/expect/context.d.ts.map +1 -0
  15. package/dist/expect/context.js +6 -0
  16. package/dist/expect/errors.d.ts +3 -0
  17. package/dist/expect/errors.d.ts.map +1 -0
  18. package/dist/expect/errors.js +45 -0
  19. package/dist/expect/expect.d.ts.map +1 -1
  20. package/dist/expect/expect.js +6 -1
  21. package/dist/expect/matchers/toMatchImageSnapshot.d.ts +1 -1
  22. package/dist/expect/matchers/toMatchImageSnapshot.d.ts.map +1 -1
  23. package/dist/expect/matchers/toMatchImageSnapshot.js +4 -12
  24. package/dist/initialize.js +14 -5
  25. package/dist/jsx/jsx-dev-runtime.d.ts +2 -1
  26. package/dist/jsx/jsx-dev-runtime.d.ts.map +1 -1
  27. package/dist/jsx/jsx-dev-runtime.js +16 -7
  28. package/dist/render/queries.d.ts +7 -0
  29. package/dist/render/queries.d.ts.map +1 -0
  30. package/dist/render/queries.js +99 -0
  31. package/dist/runHarnessTestsInModule.d.ts +9 -0
  32. package/dist/runHarnessTestsInModule.d.ts.map +1 -0
  33. package/dist/runHarnessTestsInModule.js +57 -0
  34. package/dist/runner/runSuite.d.ts.map +1 -1
  35. package/dist/runner/runSuite.js +16 -6
  36. package/dist/screen/index.d.ts +50 -0
  37. package/dist/screen/index.d.ts.map +1 -0
  38. package/dist/screen/index.js +46 -0
  39. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  40. package/dist/userEvent/index.d.ts +16 -0
  41. package/dist/userEvent/index.d.ts.map +1 -0
  42. package/dist/userEvent/index.js +31 -0
  43. package/dist/utils/hmr.d.ts +2 -0
  44. package/dist/utils/hmr.d.ts.map +1 -0
  45. package/dist/utils/hmr.js +3 -0
  46. package/dist/utils/parse-error-stack.d.ts +9 -0
  47. package/dist/utils/parse-error-stack.d.ts.map +1 -0
  48. package/dist/utils/parse-error-stack.js +56 -0
  49. package/dist/waitFor.d.ts.map +1 -1
  50. package/dist/waitFor.js +5 -3
  51. package/out-tsc/vitest/src/__tests__/collector.test.d.ts +2 -0
  52. package/out-tsc/vitest/src/__tests__/collector.test.d.ts.map +1 -0
  53. package/out-tsc/vitest/src/__tests__/error-handling.test.d.ts +2 -0
  54. package/out-tsc/vitest/src/__tests__/error-handling.test.d.ts.map +1 -0
  55. package/out-tsc/vitest/src/__tests__/expect.test.d.ts +2 -0
  56. package/out-tsc/vitest/src/__tests__/expect.test.d.ts.map +1 -0
  57. package/out-tsc/vitest/src/__tests__/initialize.test.d.ts +2 -0
  58. package/out-tsc/vitest/src/__tests__/initialize.test.d.ts.map +1 -0
  59. package/out-tsc/vitest/src/__tests__/spy.test.d.ts +2 -0
  60. package/out-tsc/vitest/src/__tests__/spy.test.d.ts.map +1 -0
  61. package/out-tsc/vitest/src/bundler/bundle.d.ts +2 -0
  62. package/out-tsc/vitest/src/bundler/bundle.d.ts.map +1 -0
  63. package/out-tsc/vitest/src/bundler/errors.d.ts +15 -0
  64. package/out-tsc/vitest/src/bundler/errors.d.ts.map +1 -0
  65. package/out-tsc/vitest/src/bundler/evaluate.d.ts +2 -0
  66. package/out-tsc/vitest/src/bundler/evaluate.d.ts.map +1 -0
  67. package/out-tsc/vitest/src/bundler/factory.d.ts +3 -0
  68. package/out-tsc/vitest/src/bundler/factory.d.ts.map +1 -0
  69. package/out-tsc/vitest/src/bundler/index.d.ts +4 -0
  70. package/out-tsc/vitest/src/bundler/index.d.ts.map +1 -0
  71. package/out-tsc/vitest/src/bundler/types.d.ts +7 -0
  72. package/out-tsc/vitest/src/bundler/types.d.ts.map +1 -0
  73. package/out-tsc/vitest/src/client/factory.d.ts +3 -0
  74. package/out-tsc/vitest/src/client/factory.d.ts.map +1 -0
  75. package/out-tsc/vitest/src/client/getDeviceDescriptor.d.ts +8 -0
  76. package/out-tsc/vitest/src/client/getDeviceDescriptor.d.ts.map +1 -0
  77. package/out-tsc/vitest/src/client/getWSServer.d.ts +2 -0
  78. package/out-tsc/vitest/src/client/getWSServer.d.ts.map +1 -0
  79. package/out-tsc/vitest/src/client/getWSServer.test.d.ts +2 -0
  80. package/out-tsc/vitest/src/client/getWSServer.test.d.ts.map +1 -0
  81. package/out-tsc/vitest/src/client/index.d.ts +2 -0
  82. package/out-tsc/vitest/src/client/index.d.ts.map +1 -0
  83. package/out-tsc/vitest/src/client/setup-files.d.ts +12 -0
  84. package/out-tsc/vitest/src/client/setup-files.d.ts.map +1 -0
  85. package/out-tsc/vitest/src/client/store.d.ts +4 -0
  86. package/out-tsc/vitest/src/client/store.d.ts.map +1 -0
  87. package/out-tsc/vitest/src/collector/errors.d.ts +8 -0
  88. package/out-tsc/vitest/src/collector/errors.d.ts.map +1 -0
  89. package/out-tsc/vitest/src/collector/factory.d.ts +3 -0
  90. package/out-tsc/vitest/src/collector/factory.d.ts.map +1 -0
  91. package/out-tsc/vitest/src/collector/functions.d.ts +22 -0
  92. package/out-tsc/vitest/src/collector/functions.d.ts.map +1 -0
  93. package/out-tsc/vitest/src/collector/index.d.ts +5 -0
  94. package/out-tsc/vitest/src/collector/index.d.ts.map +1 -0
  95. package/out-tsc/vitest/src/collector/types.d.ts +10 -0
  96. package/out-tsc/vitest/src/collector/types.d.ts.map +1 -0
  97. package/out-tsc/vitest/src/collector/validation.d.ts +4 -0
  98. package/out-tsc/vitest/src/collector/validation.d.ts.map +1 -0
  99. package/out-tsc/vitest/src/constants.d.ts +2 -0
  100. package/out-tsc/vitest/src/constants.d.ts.map +1 -0
  101. package/out-tsc/vitest/src/disableHMRWhenReady.d.ts +2 -0
  102. package/out-tsc/vitest/src/disableHMRWhenReady.d.ts.map +1 -0
  103. package/out-tsc/vitest/src/disableHMRWhenReady.test.d.ts +2 -0
  104. package/out-tsc/vitest/src/disableHMRWhenReady.test.d.ts.map +1 -0
  105. package/out-tsc/vitest/src/entry-point.d.ts +2 -0
  106. package/out-tsc/vitest/src/entry-point.d.ts.map +1 -0
  107. package/out-tsc/vitest/src/errors.d.ts +6 -0
  108. package/out-tsc/vitest/src/errors.d.ts.map +1 -0
  109. package/out-tsc/vitest/src/expect/context.d.ts +20 -0
  110. package/out-tsc/vitest/src/expect/context.d.ts.map +1 -0
  111. package/out-tsc/vitest/src/expect/errors.d.ts +3 -0
  112. package/out-tsc/vitest/src/expect/errors.d.ts.map +1 -0
  113. package/out-tsc/vitest/src/expect/expect.d.ts +9 -0
  114. package/out-tsc/vitest/src/expect/expect.d.ts.map +1 -0
  115. package/out-tsc/vitest/src/expect/index.d.ts +2 -0
  116. package/out-tsc/vitest/src/expect/index.d.ts.map +1 -0
  117. package/out-tsc/vitest/src/expect/matchers/toMatchImageSnapshot.d.ts +13 -0
  118. package/out-tsc/vitest/src/expect/matchers/toMatchImageSnapshot.d.ts.map +1 -0
  119. package/out-tsc/vitest/src/expect/setup.d.ts +2 -0
  120. package/out-tsc/vitest/src/expect/setup.d.ts.map +1 -0
  121. package/out-tsc/vitest/src/filtering/index.d.ts +2 -0
  122. package/out-tsc/vitest/src/filtering/index.d.ts.map +1 -0
  123. package/out-tsc/vitest/src/filtering/testNameFilter.d.ts +12 -0
  124. package/out-tsc/vitest/src/filtering/testNameFilter.d.ts.map +1 -0
  125. package/out-tsc/vitest/src/globals.d.ts +19 -0
  126. package/out-tsc/vitest/src/globals.d.ts.map +1 -0
  127. package/out-tsc/vitest/src/index.d.ts +12 -0
  128. package/out-tsc/vitest/src/index.d.ts.map +1 -0
  129. package/out-tsc/vitest/src/initialize.d.ts +2 -0
  130. package/out-tsc/vitest/src/initialize.d.ts.map +1 -0
  131. package/out-tsc/vitest/src/jest-mock.d.ts +2 -0
  132. package/out-tsc/vitest/src/jest-mock.d.ts.map +1 -0
  133. package/out-tsc/vitest/src/jsx/jsx-dev-runtime.d.ts +4 -0
  134. package/out-tsc/vitest/src/jsx/jsx-dev-runtime.d.ts.map +1 -0
  135. package/out-tsc/vitest/src/jsx/jsx-runtime.d.ts +6 -0
  136. package/out-tsc/vitest/src/jsx/jsx-runtime.d.ts.map +1 -0
  137. package/out-tsc/vitest/src/mocker/index.d.ts +2 -0
  138. package/out-tsc/vitest/src/mocker/index.d.ts.map +1 -0
  139. package/out-tsc/vitest/src/mocker/registry.d.ts +6 -0
  140. package/out-tsc/vitest/src/mocker/registry.d.ts.map +1 -0
  141. package/out-tsc/vitest/src/mocker/types.d.ts +6 -0
  142. package/out-tsc/vitest/src/mocker/types.d.ts.map +1 -0
  143. package/out-tsc/vitest/src/namespace.d.ts +18 -0
  144. package/out-tsc/vitest/src/namespace.d.ts.map +1 -0
  145. package/out-tsc/vitest/src/polyfills.d.ts +11 -0
  146. package/out-tsc/vitest/src/polyfills.d.ts.map +1 -0
  147. package/out-tsc/vitest/src/render/ErrorBoundary.d.ts +17 -0
  148. package/out-tsc/vitest/src/render/ErrorBoundary.d.ts.map +1 -0
  149. package/out-tsc/vitest/src/render/TestComponentOverlay.d.ts +3 -0
  150. package/out-tsc/vitest/src/render/TestComponentOverlay.d.ts.map +1 -0
  151. package/out-tsc/vitest/src/render/cleanup.d.ts +2 -0
  152. package/out-tsc/vitest/src/render/cleanup.d.ts.map +1 -0
  153. package/out-tsc/vitest/src/render/index.d.ts +6 -0
  154. package/out-tsc/vitest/src/render/index.d.ts.map +1 -0
  155. package/out-tsc/vitest/src/render/setup.d.ts +2 -0
  156. package/out-tsc/vitest/src/render/setup.d.ts.map +1 -0
  157. package/out-tsc/vitest/src/render/types.d.ts +12 -0
  158. package/out-tsc/vitest/src/render/types.d.ts.map +1 -0
  159. package/out-tsc/vitest/src/runner/context.d.ts +10 -0
  160. package/out-tsc/vitest/src/runner/context.d.ts.map +1 -0
  161. package/out-tsc/vitest/src/runner/errors.d.ts +11 -0
  162. package/out-tsc/vitest/src/runner/errors.d.ts.map +1 -0
  163. package/out-tsc/vitest/src/runner/factory.d.ts +3 -0
  164. package/out-tsc/vitest/src/runner/factory.d.ts.map +1 -0
  165. package/out-tsc/vitest/src/runner/hooks.d.ts +4 -0
  166. package/out-tsc/vitest/src/runner/hooks.d.ts.map +1 -0
  167. package/out-tsc/vitest/src/runner/index.d.ts +5 -0
  168. package/out-tsc/vitest/src/runner/index.d.ts.map +1 -0
  169. package/out-tsc/vitest/src/runner/runSuite.d.ts +7 -0
  170. package/out-tsc/vitest/src/runner/runSuite.d.ts.map +1 -0
  171. package/out-tsc/vitest/src/runner/types.d.ts +18 -0
  172. package/out-tsc/vitest/src/runner/types.d.ts.map +1 -0
  173. package/out-tsc/vitest/src/screen/index.d.ts +8 -0
  174. package/out-tsc/vitest/src/screen/index.d.ts.map +1 -0
  175. package/out-tsc/vitest/src/spy/index.d.ts +2 -0
  176. package/out-tsc/vitest/src/spy/index.d.ts.map +1 -0
  177. package/out-tsc/vitest/src/symbolicate.d.ts +17 -0
  178. package/out-tsc/vitest/src/symbolicate.d.ts.map +1 -0
  179. package/out-tsc/vitest/src/ui/ReadyScreen.d.ts +2 -0
  180. package/out-tsc/vitest/src/ui/ReadyScreen.d.ts.map +1 -0
  181. package/out-tsc/vitest/src/ui/RunnerScreen.d.ts +8 -0
  182. package/out-tsc/vitest/src/ui/RunnerScreen.d.ts.map +1 -0
  183. package/out-tsc/vitest/src/ui/WrongEnvironmentScreen.d.ts +2 -0
  184. package/out-tsc/vitest/src/ui/WrongEnvironmentScreen.d.ts.map +1 -0
  185. package/out-tsc/vitest/src/ui/images.d.ts +3 -0
  186. package/out-tsc/vitest/src/ui/images.d.ts.map +1 -0
  187. package/out-tsc/vitest/src/ui/index.d.ts +2 -0
  188. package/out-tsc/vitest/src/ui/index.d.ts.map +1 -0
  189. package/out-tsc/vitest/src/ui/state.d.ts +20 -0
  190. package/out-tsc/vitest/src/ui/state.d.ts.map +1 -0
  191. package/out-tsc/vitest/src/userEvent/index.d.ts +6 -0
  192. package/out-tsc/vitest/src/userEvent/index.d.ts.map +1 -0
  193. package/out-tsc/vitest/src/utils/dev-server.d.ts +2 -0
  194. package/out-tsc/vitest/src/utils/dev-server.d.ts.map +1 -0
  195. package/out-tsc/vitest/src/utils/emitter.d.ts +16 -0
  196. package/out-tsc/vitest/src/utils/emitter.d.ts.map +1 -0
  197. package/out-tsc/vitest/src/waitFor.d.ts +21 -0
  198. package/out-tsc/vitest/src/waitFor.d.ts.map +1 -0
  199. package/out-tsc/vitest/tsconfig.spec.tsbuildinfo +1 -0
  200. package/out-tsc/vitest/vite.config.d.ts +3 -0
  201. package/out-tsc/vitest/vite.config.d.ts.map +1 -0
  202. package/package.json +2 -2
  203. package/src/client/factory.ts +63 -74
  204. package/src/client/store.ts +8 -8
  205. package/src/expect/context.ts +30 -0
  206. package/src/expect/errors.ts +76 -0
  207. package/src/expect/expect.ts +16 -5
  208. package/src/expect/matchers/toMatchImageSnapshot.ts +9 -23
  209. package/src/initialize.ts +14 -5
  210. package/src/jsx/jsx-dev-runtime.ts +34 -15
  211. package/src/runner/runSuite.ts +25 -11
  212. package/src/waitFor.ts +8 -6
@@ -0,0 +1,41 @@
1
+ import { type TurboModule } from 'react-native';
2
+ /**
3
+ * Represents the position and dimensions of a view in screen coordinates (points/dp).
4
+ */
5
+ export interface ViewInfo {
6
+ x: number;
7
+ y: number;
8
+ width: number;
9
+ height: number;
10
+ }
11
+ interface Spec extends TurboModule {
12
+ /**
13
+ * Simulates a native tap at the specified screen coordinates.
14
+ * Returns a promise that resolves when the tap action is complete.
15
+ */
16
+ simulateTap(x: number, y: number): Promise<void>;
17
+ /**
18
+ * Finds a view by its testID (accessibilityIdentifier on iOS, tag on Android).
19
+ * Returns null if no view is found.
20
+ */
21
+ queryByTestId(testId: string): ViewInfo | null;
22
+ /**
23
+ * Finds all views by testID (accessibilityIdentifier on iOS, tag on Android).
24
+ * Returns an empty array if no views are found.
25
+ */
26
+ queryAllByTestId(testId: string): ViewInfo[];
27
+ /**
28
+ * Finds a view by its accessibility label.
29
+ * Returns null if no view is found.
30
+ */
31
+ queryByAccessibilityLabel(label: string): ViewInfo | null;
32
+ /**
33
+ * Finds all views by accessibility label.
34
+ * Returns an empty array if no views are found.
35
+ */
36
+ queryAllByAccessibilityLabel(label: string): ViewInfo[];
37
+ }
38
+ export type HarnessModule = Spec;
39
+ declare const _default: Spec;
40
+ export default _default;
41
+ //# sourceMappingURL=NativeHarness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeHarness.d.ts","sourceRoot":"","sources":["../src/NativeHarness.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,IAAK,SAAQ,WAAW;IAChC;;;OAGG;IACH,WAAW,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEjD;;;OAGG;IACH,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IAE/C;;;OAGG;IACH,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAC;IAE7C;;;OAGG;IACH,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAAC;IAE1D;;;OAGG;IACH,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE,CAAC;CACzD;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC;;AAEjC,wBAAiE"}
@@ -0,0 +1,2 @@
1
+ import { TurboModuleRegistry } from 'react-native';
2
+ export default TurboModuleRegistry.getEnforcing('Harness');
@@ -1,2 +1,3 @@
1
- export declare const getClient: () => Promise<import("@react-native-harness/bridge/client").BridgeClient>;
1
+ import { type HarnessHandle } from '@react-native-harness/bridge/client';
2
+ export declare const getClient: () => Promise<HarnessHandle>;
2
3
  //# sourceMappingURL=factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/client/factory.ts"],"names":[],"mappings":"AAkBA,eAAO,MAAM,SAAS,2EAsFrB,CAAC"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../src/client/factory.ts"],"names":[],"mappings":"AAMA,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAY3F,eAAO,MAAM,SAAS,QAAa,OAAO,CAAC,aAAa,CA2EvD,CAAC"}
@@ -1,4 +1,4 @@
1
- import { getBridgeClient } from '@react-native-harness/bridge/client';
1
+ import { connectToHarness } from '@react-native-harness/bridge/client';
2
2
  import { store } from '../ui/state.js';
3
3
  import { getTestRunner } from '../runner/index.js';
4
4
  import { getTestCollector } from '../collector/index.js';
@@ -8,68 +8,62 @@ import { getBundler, evaluateModule } from '../bundler/index.js';
8
8
  import { markTestsAsSkippedByName } from '../filtering/index.js';
9
9
  import { setup } from '../render/setup.js';
10
10
  import { runSetupFiles } from './setup-files.js';
11
- import { setClient } from './store.js';
11
+ import { setHandle } from './store.js';
12
12
  export const getClient = async () => {
13
- const client = await getBridgeClient(getWSServer(), {
14
- runTests: async () => {
15
- throw new Error('Not implemented');
16
- },
17
- });
18
- setClient(client);
19
- client.rpc.$functions.runTests = async (path, options) => {
20
- if (store.getState().status === 'running') {
21
- throw new Error('Already running tests');
22
- }
23
- store.getState().setStatus('running');
24
- let collector = null;
25
- let runner = null;
26
- let events = null;
27
- let bundler = null;
28
- try {
29
- collector = getTestCollector();
30
- runner = getTestRunner();
31
- bundler = getBundler();
32
- events = combineEventEmitters(collector.events, runner.events, bundler.events);
33
- events.addListener((event) => {
34
- client.rpc.emitEvent(event.type, event);
35
- });
36
- await runSetupFiles({
37
- setupFiles: options.setupFiles ?? [],
38
- setupFilesAfterEnv: [],
39
- events: events,
40
- bundler: bundler,
41
- evaluateModule,
42
- });
43
- const moduleJs = await bundler.getModule(path);
44
- const collectionResult = await collector.collect(async () => {
13
+ const handle = await connectToHarness(getWSServer(), {
14
+ runTests: async (path, options) => {
15
+ if (store.getState().status === 'running') {
16
+ throw new Error('Already running tests');
17
+ }
18
+ store.getState().setStatus('running');
19
+ let collector = null;
20
+ let runner = null;
21
+ let events = null;
22
+ let bundler = null;
23
+ try {
24
+ collector = getTestCollector();
25
+ runner = getTestRunner();
26
+ bundler = getBundler();
27
+ events = combineEventEmitters(collector.events, runner.events, bundler.events);
28
+ events.addListener((event) => {
29
+ handle.emitEvent(event);
30
+ });
45
31
  await runSetupFiles({
46
- setupFiles: [],
47
- setupFilesAfterEnv: options.setupFilesAfterEnv ?? [],
32
+ setupFiles: options.setupFiles ?? [],
33
+ setupFilesAfterEnv: [],
48
34
  events: events,
49
35
  bundler: bundler,
50
36
  evaluateModule,
51
37
  });
52
- // Setup automatic cleanup for rendered components
53
- setup();
54
- evaluateModule(moduleJs, path);
55
- }, path);
56
- // Apply test name pattern by marking non-matching tests as skipped
57
- const processedTestSuite = options.testNamePattern
58
- ? markTestsAsSkippedByName(collectionResult.testSuite, options.testNamePattern)
59
- : collectionResult.testSuite;
60
- const result = await runner.run({
61
- testSuite: processedTestSuite,
62
- testFilePath: path,
63
- runner: options.runner,
64
- });
65
- return result;
66
- }
67
- finally {
68
- collector?.dispose();
69
- runner?.dispose();
70
- events?.clearAllListeners();
71
- store.getState().setStatus('idle');
72
- }
73
- };
74
- return client;
38
+ const moduleJs = await bundler.getModule(path);
39
+ const collectionResult = await collector.collect(async () => {
40
+ await runSetupFiles({
41
+ setupFiles: [],
42
+ setupFilesAfterEnv: options.setupFilesAfterEnv ?? [],
43
+ events: events,
44
+ bundler: bundler,
45
+ evaluateModule,
46
+ });
47
+ setup();
48
+ evaluateModule(moduleJs, path);
49
+ }, path);
50
+ const processedTestSuite = options.testNamePattern
51
+ ? markTestsAsSkippedByName(collectionResult.testSuite, options.testNamePattern)
52
+ : collectionResult.testSuite;
53
+ return await runner.run({
54
+ testSuite: processedTestSuite,
55
+ testFilePath: path,
56
+ runner: options.runner,
57
+ });
58
+ }
59
+ finally {
60
+ collector?.dispose();
61
+ runner?.dispose();
62
+ events?.clearAllListeners();
63
+ store.getState().setStatus('idle');
64
+ }
65
+ },
66
+ });
67
+ setHandle(handle);
68
+ return handle;
75
69
  };
@@ -1,4 +1,4 @@
1
- import type { BridgeClient } from '@react-native-harness/bridge/client';
2
- export declare const setClient: (client: BridgeClient) => void;
3
- export declare const getClientInstance: () => BridgeClient;
1
+ import type { HarnessHandle } from '@react-native-harness/bridge/client';
2
+ export declare const setHandle: (h: HarnessHandle) => void;
3
+ export declare const getHandle: () => HarnessHandle;
4
4
  //# sourceMappingURL=store.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/client/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAIxE,eAAO,MAAM,SAAS,GAAI,QAAQ,YAAY,KAAG,IAEhD,CAAC;AAEF,eAAO,MAAM,iBAAiB,QAAO,YAOpC,CAAC"}
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/client/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AAIzE,eAAO,MAAM,SAAS,GAAI,GAAG,aAAa,KAAG,IAE5C,CAAC;AAEF,eAAO,MAAM,SAAS,QAAO,aAO5B,CAAC"}
@@ -1,10 +1,10 @@
1
- let clientInstance = null;
2
- export const setClient = (client) => {
3
- clientInstance = client;
1
+ let handle = null;
2
+ export const setHandle = (h) => {
3
+ handle = h;
4
4
  };
5
- export const getClientInstance = () => {
6
- if (!clientInstance) {
7
- throw new Error('Bridge client not initialized. This should not happen in normal operation.');
5
+ export const getHandle = () => {
6
+ if (!handle) {
7
+ throw new Error('Harness not connected. This should not happen in normal operation.');
8
8
  }
9
- return clientInstance;
9
+ return handle;
10
10
  };
@@ -0,0 +1,2 @@
1
+ export declare const WS_SERVER_PORT = 3001;
2
+ //# 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,cAAc,OAAO,CAAC"}
@@ -0,0 +1 @@
1
+ export const WS_SERVER_PORT = 3001;
@@ -0,0 +1,20 @@
1
+ type HarnessExpectError = {
2
+ name?: string;
3
+ message?: string;
4
+ stack?: string;
5
+ };
6
+ export type HarnessExpectTestState = {
7
+ result?: {
8
+ state: 'pass' | 'fail';
9
+ errors?: HarnessExpectError[];
10
+ };
11
+ promises?: Promise<unknown>[];
12
+ onFinished?: Array<() => void | Promise<void>>;
13
+ };
14
+ declare global {
15
+ var HARNESS_EXPECT_TEST_STATE: HarnessExpectTestState | undefined;
16
+ }
17
+ export declare const getCurrentExpectTestState: () => HarnessExpectTestState | undefined;
18
+ export declare const setCurrentExpectTestState: (state: HarnessExpectTestState | undefined) => void;
19
+ export {};
20
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/expect/context.ts"],"names":[],"mappings":"AAAA,KAAK,kBAAkB,GAAG;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,CAAC,EAAE;QACP,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,CAAC,EAAE,kBAAkB,EAAE,CAAC;KAC/B,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAC9B,UAAU,CAAC,EAAE,KAAK,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CAChD,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,yBAAyB,EAAE,sBAAsB,GAAG,SAAS,CAAC;CACnE;AAED,eAAO,MAAM,yBAAyB,QAClC,sBAAsB,GACtB,SAEH,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,OAAO,sBAAsB,GAAG,SAAS,KACxC,IAEF,CAAC"}
@@ -0,0 +1,6 @@
1
+ export const getCurrentExpectTestState = () => {
2
+ return globalThis.HARNESS_EXPECT_TEST_STATE;
3
+ };
4
+ export const setCurrentExpectTestState = (state) => {
5
+ globalThis.HARNESS_EXPECT_TEST_STATE = state;
6
+ };
@@ -0,0 +1,3 @@
1
+ import type { HarnessExpectTestState } from './context.js';
2
+ export declare const flushExpectTestState: (state: HarnessExpectTestState) => Promise<void>;
3
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/expect/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAgD3D,eAAO,MAAM,oBAAoB,GAC/B,OAAO,sBAAsB,KAC5B,OAAO,CAAC,IAAI,CAyBd,CAAC"}
@@ -0,0 +1,45 @@
1
+ const formatErrorMessage = (error) => {
2
+ if (error instanceof Error) {
3
+ return `${error.name}: ${error.message}`;
4
+ }
5
+ if (error && typeof error === 'object') {
6
+ const maybeError = error;
7
+ if (maybeError.name || maybeError.message) {
8
+ return [maybeError.name, maybeError.message].filter(Boolean).join(': ');
9
+ }
10
+ }
11
+ return String(error);
12
+ };
13
+ const createExpectError = (errors, title) => {
14
+ const message = [title, ...errors.map(formatErrorMessage)]
15
+ .filter(Boolean)
16
+ .join('\n\n');
17
+ const error = new Error(message);
18
+ const firstError = errors.find((value) => !!value && typeof value === 'object');
19
+ if (firstError?.name) {
20
+ error.name = firstError.name;
21
+ }
22
+ if (firstError?.stack) {
23
+ error.stack = firstError.stack.replace(/^([^\n]+)(\n|$)/, `${error.name}: ${message}$2`);
24
+ }
25
+ return error;
26
+ };
27
+ export const flushExpectTestState = async (state) => {
28
+ if (state.promises?.length) {
29
+ const results = await Promise.allSettled(state.promises);
30
+ const rejected = results
31
+ .filter((result) => result.status === 'rejected')
32
+ .map((result) => result.reason);
33
+ if (rejected.length > 0) {
34
+ throw createExpectError(rejected);
35
+ }
36
+ }
37
+ for (const hook of state.onFinished ?? []) {
38
+ await hook();
39
+ }
40
+ const softErrors = state.result?.errors ?? [];
41
+ if (softErrors.length === 0) {
42
+ return;
43
+ }
44
+ throw createExpectError(softErrors, 'Soft assertion failures:');
45
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect/expect.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAa,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAS5E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B,OAAO,YAAY,CAAC;AAGpB,wBAAgB,YAAY,IAAI,YAAY,CAwF3C;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"}
1
+ {"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["../../src/expect/expect.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAa,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAS5E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B,OAAO,YAAY,CAAC;AAGpB,wBAAgB,YAAY,IAAI,YAAY,CAkG3C;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"}
@@ -3,13 +3,18 @@
3
3
  import { addCustomEqualityTesters, ASYMMETRIC_MATCHERS_OBJECT, customMatchers, getState, GLOBAL_EXPECT, setState, } from '@vitest/expect';
4
4
  import * as chai from 'chai';
5
5
  // Setup additional matchers
6
+ import { getCurrentExpectTestState } from './context.js';
6
7
  import './setup.js';
7
8
  import { toMatchImageSnapshot } from './matchers/toMatchImageSnapshot.js';
8
9
  export function createExpect() {
9
10
  const expect = ((value, message) => {
10
11
  const { assertionCalls } = getState(expect);
11
12
  setState({ assertionCalls: assertionCalls + 1 }, expect);
12
- return chai.expect(value, message);
13
+ const assertion = chai.expect(value, message);
14
+ const currentTest = getCurrentExpectTestState();
15
+ return currentTest && assertion.withTest
16
+ ? assertion.withTest(currentTest)
17
+ : assertion;
13
18
  });
14
19
  Object.assign(expect, chai.expect);
15
20
  Object.assign(expect, globalThis[ASYMMETRIC_MATCHERS_OBJECT]);
@@ -1,5 +1,5 @@
1
1
  import type { MatcherState } from '@vitest/expect';
2
- import { type ImageSnapshotOptions } from '@react-native-harness/bridge';
2
+ import type { ImageSnapshotOptions } from '@react-native-harness/bridge';
3
3
  type ScreenshotResult = {
4
4
  data: Uint8Array;
5
5
  width: number;
@@ -1 +1 @@
1
- {"version":3,"file":"toMatchImageSnapshot.d.ts","sourceRoot":"","sources":["../../../src/expect/matchers/toMatchImageSnapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,KAAK,oBAAoB,EAE1B,MAAM,8BAA8B,CAAC;AAGtC,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,MAAM,CAAA;CAAE,CAAC,CA+BnD"}
1
+ {"version":3,"file":"toMatchImageSnapshot.d.ts","sourceRoot":"","sources":["../../../src/expect/matchers/toMatchImageSnapshot.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAGzE,KAAK,gBAAgB,GAAG;IACtB,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,YAAY,EAClB,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,MAAM,CAAA;CAAE,CAAC,CAoBnD"}
@@ -1,21 +1,13 @@
1
- import { getClientInstance } from '../../client/store.js';
2
- import { generateTransferId, } from '@react-native-harness/bridge';
1
+ import { getHandle } from '../../client/store.js';
3
2
  import { getHarnessContext } from '../../runner/index.js';
4
3
  export async function toMatchImageSnapshot(received, options) {
5
- const client = getClientInstance();
4
+ const handle = getHandle();
6
5
  const context = getHarnessContext();
7
- const transferId = generateTransferId();
8
- client.sendBinary(transferId, received.data);
9
- const screenshotFile = await client.rpc['device.screenshot.receive']({
10
- type: 'binary',
11
- transferId,
12
- size: received.data.length,
13
- mimeType: 'image/png',
14
- }, {
6
+ const screenshotFile = await handle.transferScreenshot(received.data, {
15
7
  width: received.width,
16
8
  height: received.height,
17
9
  });
18
- const result = await client.rpc['test.matchImageSnapshot'](screenshotFile, context.testFilePath, options, context.runner);
10
+ const result = await handle.matchImageSnapshot(screenshotFile, context.testFilePath, options, context.runner);
19
11
  return {
20
12
  pass: result.pass,
21
13
  message: () => result.message,
@@ -2,10 +2,19 @@ import { getDeviceDescriptor } from './client/getDeviceDescriptor.js';
2
2
  import { getClient } from './client/index.js';
3
3
  import { disableHMRWhenReady } from './disableHMRWhenReady.js';
4
4
  import { setupJestMock } from './jest-mock.js';
5
- // Polyfill for EventTarget
5
+ // Polyfill for EventTarget on runtimes that don't ship one (RN's JSC).
6
+ // Do NOT overwrite when a native ctor already exists (RN Web / browsers):
7
+ // Safari's EventTarget.dispatchEvent() does an internal brand check and
8
+ // rejects polyfill instances with a TypeError, which breaks any
9
+ // DOM-event-driven flow in the page — most visibly DRM (FairPlay) via
10
+ // libraries that re-dispatch synthetic `encrypted` events.
6
11
  const Shim = require('event-target-shim');
7
- globalThis.Event = Shim.Event;
8
- globalThis.EventTarget = Shim.EventTarget;
12
+ if (typeof globalThis.Event !== 'function') {
13
+ globalThis.Event = Shim.Event;
14
+ }
15
+ if (typeof globalThis.EventTarget !== 'function') {
16
+ globalThis.EventTarget = Shim.EventTarget;
17
+ }
9
18
  // Setup jest mock to warn users about using Jest APIs
10
19
  setupJestMock();
11
20
  // Turn off LogBox
@@ -19,9 +28,9 @@ setTimeout(() => {
19
28
  void (async () => {
20
29
  try {
21
30
  await disableHMRWhenReady(() => HMRClient.disable(), 50);
22
- const client = await getClient();
31
+ const handle = await getClient();
23
32
  const deviceDescriptor = getDeviceDescriptor();
24
- await client.rpc.reportReady(deviceDescriptor);
33
+ handle.reportReady(deviceDescriptor);
25
34
  }
26
35
  catch (error) {
27
36
  console.error('Failed to initialize React Native Harness', error);
@@ -1,3 +1,4 @@
1
+ import * as ReactJSXRuntimeDev from 'react/jsx-dev-runtime';
1
2
  export declare const Fragment: import("react").ExoticComponent<import("react").FragmentProps>;
2
- export declare function jsxDEV(type: any, props: any, key: any, isStaticChildren: any, source: any, self: any): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
3
+ export declare function jsxDEV(...args: Parameters<typeof ReactJSXRuntimeDev.jsxDEV>): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
3
4
  //# sourceMappingURL=jsx-dev-runtime.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx/jsx-dev-runtime.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,gEAA8B,CAAC;AAEpD,wBAAgB,MAAM,CACpB,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,GAAG,EACV,GAAG,EAAE,GAAG,EACR,gBAAgB,EAAE,GAAG,EACrB,MAAM,EAAE,GAAG,EACX,IAAI,EAAE,GAAG,8FAkBV"}
1
+ {"version":3,"file":"jsx-dev-runtime.d.ts","sourceRoot":"","sources":["../../src/jsx/jsx-dev-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,MAAM,uBAAuB,CAAC;AAe5D,eAAO,MAAM,QAAQ,gEAA8B,CAAC;AAEpD,wBAAgB,MAAM,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,kBAAkB,CAAC,MAAM,CAAC,8FA8B3E"}
@@ -1,11 +1,20 @@
1
1
  import * as ReactJSXRuntimeDev from 'react/jsx-dev-runtime';
2
+ const isNamedElementType = (value) => (typeof value === 'function' ||
3
+ (typeof value === 'object' && value !== null)) &&
4
+ ('displayName' in value || 'name' in value);
5
+ const isPropsObject = (value) => typeof value === 'object' && value !== null;
2
6
  export const Fragment = ReactJSXRuntimeDev.Fragment;
3
- export function jsxDEV(type, props, key, isStaticChildren, source, self) {
4
- if (type &&
5
- (type.displayName === 'View' || type.name === 'View') &&
6
- props &&
7
- props.collapsable === undefined) {
8
- props = { ...props, collapsable: true };
7
+ export function jsxDEV(...args) {
8
+ const [type, props, key, isStaticChildren, source, self] = args;
9
+ const isViewType = isNamedElementType(type) &&
10
+ (type.displayName === 'View' || type.name === 'View');
11
+ const nextProps = isViewType &&
12
+ isPropsObject(props) &&
13
+ props.collapsable === undefined
14
+ ? { ...props, collapsable: true }
15
+ : props;
16
+ if (isViewType && isPropsObject(props) && props.collapsable === undefined) {
17
+ return ReactJSXRuntimeDev.jsxDEV(type, nextProps, key, isStaticChildren, source, self);
9
18
  }
10
- return ReactJSXRuntimeDev.jsxDEV(type, props, key, isStaticChildren, source, self);
19
+ return ReactJSXRuntimeDev.jsxDEV(type, nextProps, key, isStaticChildren, source, self);
11
20
  }
@@ -0,0 +1,7 @@
1
+ import { HostInstance } from 'react-native';
2
+ export declare const setRoot: (rootInstance: HostInstance) => void;
3
+ declare const queryByTestId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default | null, queryAllByTestId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[], getByTestId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default | null, getAllByTestId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[], findByTestId: (params: string) => Promise<import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default>, findAllByTestId: (params: string) => Promise<import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[]>;
4
+ declare const queryById: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default | null, queryAllById: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[], getId: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default | null, getAllById: (params: string) => import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[], findById: (params: string) => Promise<import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default>, findAllById: (params: string) => Promise<import("react-native/types_generated/src/private/webapis/dom/nodes/ReactNativeElement").default[]>;
5
+ export { queryByTestId, queryAllByTestId, getByTestId, getAllByTestId, findByTestId, findAllByTestId, };
6
+ export { queryById, queryAllById, getId, getAllById, findById, findAllById };
7
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/render/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAM5C,eAAO,MAAM,OAAO,GAAI,cAAc,YAAY,SAEjD,CAAC;AA6IF,QAAA,MACW,aAAa,8HACV,gBAAgB,yHACrB,WAAW,8HACR,cAAc,yHAChB,YAAY,gIACT,eAAe,gIAG3B,CAAC;AACF,QAAA,MACW,SAAS,8HACN,YAAY,yHACjB,KAAK,8HACF,UAAU,yHACZ,QAAQ,gIACL,WAAW,gIAC+B,CAAC;AAExD,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,99 @@
1
+ // import { store } from '../ui/state.js';
2
+ import { waitUntil } from '../waitFor.js';
3
+ let root = null;
4
+ export const setRoot = (rootInstance) => {
5
+ root = rootInstance;
6
+ };
7
+ const getRoot = () => {
8
+ const container = root;
9
+ if (!container) {
10
+ throw new Error('You need to render a component first!');
11
+ }
12
+ const ownerDocument = container.ownerDocument;
13
+ if (!ownerDocument) {
14
+ throw new Error('This feature is supported in React Native 0.82 and later!');
15
+ }
16
+ return ownerDocument.getRootNode();
17
+ };
18
+ const findNodeByPredicate = (predicate) => {
19
+ const queue = [getRoot()];
20
+ while (queue.length > 0) {
21
+ const node = queue.shift();
22
+ if (predicate(node)) {
23
+ return node;
24
+ }
25
+ for (const child of node.children) {
26
+ queue.push(child);
27
+ }
28
+ }
29
+ return null;
30
+ };
31
+ const findNodesByPredicate = (predicate) => {
32
+ const nodes = [];
33
+ const queue = [getRoot()];
34
+ while (queue.length > 0) {
35
+ const node = queue.shift();
36
+ if (predicate(node)) {
37
+ nodes.push(node);
38
+ }
39
+ for (const child of node.children) {
40
+ queue.push(child);
41
+ }
42
+ }
43
+ return nodes;
44
+ };
45
+ const getFiberOfHostInstance = (hostInstance) => {
46
+ // This should be considered as 'reaching into the implementation details' of React Native.
47
+ // Not perfect, but it's the only way to get the props of the host instance.
48
+ return (hostInstance
49
+ .__internalInstanceHandle || null);
50
+ };
51
+ const getPropsOfHostInstance = (hostInstance) => {
52
+ return getFiberOfHostInstance(hostInstance)?.memoizedProps || {};
53
+ };
54
+ const findBy = (predicate, options) => {
55
+ return waitUntil(() => findNodeByPredicate(predicate), options);
56
+ };
57
+ const findAllBy = (predicate, options) => {
58
+ return waitUntil(() => {
59
+ const nodes = findNodesByPredicate(predicate);
60
+ if (nodes.length === 0) {
61
+ return null;
62
+ }
63
+ return nodes;
64
+ }, options);
65
+ };
66
+ const queryBy = (predicate) => {
67
+ return findNodeByPredicate(predicate);
68
+ };
69
+ const queryAllBy = (predicate) => {
70
+ return findNodesByPredicate(predicate);
71
+ };
72
+ const getBy = (predicate) => {
73
+ const node = queryBy(predicate);
74
+ if (!node) {
75
+ throw new Error(`No node found with predicate ${predicate}`);
76
+ }
77
+ return node;
78
+ };
79
+ const getAllBy = (predicate) => {
80
+ const nodes = queryAllBy(predicate);
81
+ if (nodes.length === 0) {
82
+ throw new Error(`No nodes found with predicate ${predicate}`);
83
+ }
84
+ return nodes;
85
+ };
86
+ const createQueries = (predicate) => {
87
+ return {
88
+ findBy: (params) => findBy((node) => predicate(node, params)),
89
+ findAllBy: (params) => findAllBy((node) => predicate(node, params)),
90
+ queryBy: (params) => queryBy((node) => predicate(node, params)),
91
+ queryAllBy: (params) => queryAllBy((node) => predicate(node, params)),
92
+ getBy: (params) => getBy((node) => predicate(node, params)),
93
+ getAllBy: (params) => getAllBy((node) => predicate(node, params)),
94
+ };
95
+ };
96
+ const { queryBy: queryByTestId, queryAllBy: queryAllByTestId, getBy: getByTestId, getAllBy: getAllByTestId, findBy: findByTestId, findAllBy: findAllByTestId, } = createQueries((node, testId) => getPropsOfHostInstance(node).testID === testId);
97
+ const { queryBy: queryById, queryAllBy: queryAllById, getBy: getId, getAllBy: getAllById, findBy: findById, findAllBy: findAllById, } = createQueries((node, id) => node.id === id);
98
+ export { queryByTestId, queryAllByTestId, getByTestId, getAllByTestId, findByTestId, findAllByTestId, };
99
+ export { queryById, queryAllById, getId, getAllById, findById, findAllById };
@@ -0,0 +1,9 @@
1
+ import type { TestSuiteResult } from '@react-native-harness/bridge';
2
+ /**
3
+ * Runs tests from a specific module programmatically and returns the results.
4
+ *
5
+ * @param moduleId The require.resolveWeak call to the module, returning the module ID
6
+ * @returns The result of the test suite execution
7
+ */
8
+ export declare const runHarnessTestsInModule: (loader: () => unknown) => Promise<TestSuiteResult>;
9
+ //# sourceMappingURL=runHarnessTestsInModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runHarnessTestsInModule.d.ts","sourceRoot":"","sources":["../src/runHarnessTestsInModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,8BAA8B,CAAC;AAoCtC;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,OAAO,KACpB,OAAO,CAAC,eAAe,CAuBzB,CAAC"}