@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
@@ -13,6 +13,7 @@ import {
13
13
  import * as chai from 'chai';
14
14
 
15
15
  // Setup additional matchers
16
+ import { getCurrentExpectTestState } from './context.js';
16
17
  import './setup.js';
17
18
  import { toMatchImageSnapshot } from './matchers/toMatchImageSnapshot.js';
18
19
 
@@ -20,12 +21,22 @@ export function createExpect(): ExpectStatic {
20
21
  const expect = ((value: unknown, message?: string): Assertion => {
21
22
  const { assertionCalls } = getState(expect);
22
23
  setState({ assertionCalls: assertionCalls + 1 }, expect);
23
- return chai.expect(value, message) as unknown as Assertion;
24
+
25
+ const assertion = chai.expect(value, message) as unknown as Assertion & {
26
+ withTest?: (test: unknown) => Assertion;
27
+ };
28
+ const currentTest = getCurrentExpectTestState();
29
+
30
+ return currentTest && assertion.withTest
31
+ ? assertion.withTest(currentTest)
32
+ : assertion;
24
33
  }) as ExpectStatic;
25
34
  Object.assign(expect, chai.expect);
26
35
  Object.assign(
27
36
  expect,
28
- globalThis[ASYMMETRIC_MATCHERS_OBJECT as unknown as keyof typeof globalThis]
37
+ globalThis[
38
+ ASYMMETRIC_MATCHERS_OBJECT as unknown as keyof typeof globalThis
39
+ ],
29
40
  );
30
41
 
31
42
  expect.getState = () => getState<MatcherState>(expect);
@@ -44,7 +55,7 @@ export function createExpect(): ExpectStatic {
44
55
  expectedAssertionsNumber: null,
45
56
  expectedAssertionsNumberErrorGen: null,
46
57
  },
47
- expect
58
+ expect,
48
59
  );
49
60
 
50
61
  // @ts-expect-error untyped
@@ -62,7 +73,7 @@ export function createExpect(): ExpectStatic {
62
73
  // @ts-expect-error untyped
63
74
  expect.unreachable = (message?: string) => {
64
75
  chai.assert.fail(
65
- `expected${message ? ` "${message}" ` : ' '}not to be reached`
76
+ `expected${message ? ` "${message}" ` : ' '}not to be reached`,
66
77
  );
67
78
  };
68
79
 
@@ -71,7 +82,7 @@ export function createExpect(): ExpectStatic {
71
82
  new Error(
72
83
  `expected number of assertions to be ${expected}, but got ${
73
84
  expect.getState().assertionCalls
74
- }`
85
+ }`,
75
86
  );
76
87
  if (Error.captureStackTrace) {
77
88
  Error.captureStackTrace(errorGen(), assertions);
@@ -1,9 +1,6 @@
1
- import { getClientInstance } from '../../client/store.js';
1
+ import { getHandle } from '../../client/store.js';
2
2
  import type { MatcherState } from '@vitest/expect';
3
- import {
4
- type ImageSnapshotOptions,
5
- generateTransferId,
6
- } from '@react-native-harness/bridge';
3
+ import type { ImageSnapshotOptions } from '@react-native-harness/bridge';
7
4
  import { getHarnessContext } from '../../runner/index.js';
8
5
 
9
6
  type ScreenshotResult = {
@@ -17,30 +14,19 @@ export async function toMatchImageSnapshot(
17
14
  received: ScreenshotResult,
18
15
  options: ImageSnapshotOptions
19
16
  ): Promise<{ pass: boolean; message: () => string }> {
20
- const client = getClientInstance();
17
+ const handle = getHandle();
21
18
  const context = getHarnessContext();
22
19
 
23
- const transferId = generateTransferId();
24
- client.sendBinary(transferId, received.data);
20
+ const screenshotFile = await handle.transferScreenshot(received.data, {
21
+ width: received.width,
22
+ height: received.height,
23
+ });
25
24
 
26
- const screenshotFile = await client.rpc['device.screenshot.receive'](
27
- {
28
- type: 'binary',
29
- transferId,
30
- size: received.data.length,
31
- mimeType: 'image/png',
32
- },
33
- {
34
- width: received.width,
35
- height: received.height,
36
- }
37
- );
38
-
39
- const result = await client.rpc['test.matchImageSnapshot'](
25
+ const result = await handle.matchImageSnapshot(
40
26
  screenshotFile,
41
27
  context.testFilePath,
42
28
  options,
43
- context.runner
29
+ context.runner,
44
30
  );
45
31
 
46
32
  return {
package/src/initialize.ts CHANGED
@@ -3,10 +3,19 @@ import { getClient } from './client/index.js';
3
3
  import { disableHMRWhenReady } from './disableHMRWhenReady.js';
4
4
  import { setupJestMock } from './jest-mock.js';
5
5
 
6
- // Polyfill for EventTarget
6
+ // Polyfill for EventTarget on runtimes that don't ship one (RN's JSC).
7
+ // Do NOT overwrite when a native ctor already exists (RN Web / browsers):
8
+ // Safari's EventTarget.dispatchEvent() does an internal brand check and
9
+ // rejects polyfill instances with a TypeError, which breaks any
10
+ // DOM-event-driven flow in the page — most visibly DRM (FairPlay) via
11
+ // libraries that re-dispatch synthetic `encrypted` events.
7
12
  const Shim = require('event-target-shim');
8
- globalThis.Event = Shim.Event;
9
- globalThis.EventTarget = Shim.EventTarget;
13
+ if (typeof globalThis.Event !== 'function') {
14
+ globalThis.Event = Shim.Event;
15
+ }
16
+ if (typeof globalThis.EventTarget !== 'function') {
17
+ globalThis.EventTarget = Shim.EventTarget;
18
+ }
10
19
 
11
20
  // Setup jest mock to warn users about using Jest APIs
12
21
  setupJestMock();
@@ -25,10 +34,10 @@ setTimeout(() => {
25
34
  void (async () => {
26
35
  try {
27
36
  await disableHMRWhenReady(() => HMRClient.disable(), 50);
28
- const client = await getClient();
37
+ const handle = await getClient();
29
38
 
30
39
  const deviceDescriptor = getDeviceDescriptor();
31
- await client.rpc.reportReady(deviceDescriptor);
40
+ handle.reportReady(deviceDescriptor);
32
41
  } catch (error) {
33
42
  console.error('Failed to initialize React Native Harness', error);
34
43
  }
@@ -1,26 +1,45 @@
1
1
  import * as ReactJSXRuntimeDev from 'react/jsx-dev-runtime';
2
2
 
3
+ type NamedElementType = {
4
+ displayName?: string;
5
+ name?: string;
6
+ };
7
+
8
+ const isNamedElementType = (value: unknown): value is NamedElementType =>
9
+ (typeof value === 'function' ||
10
+ (typeof value === 'object' && value !== null)) &&
11
+ ('displayName' in value || 'name' in value);
12
+
13
+ const isPropsObject = (value: unknown): value is Record<string, unknown> =>
14
+ typeof value === 'object' && value !== null;
15
+
3
16
  export const Fragment = ReactJSXRuntimeDev.Fragment;
4
17
 
5
- export function jsxDEV(
6
- type: any,
7
- props: any,
8
- key: any,
9
- isStaticChildren: any,
10
- source: any,
11
- self: any
12
- ) {
13
- if (
14
- type &&
15
- (type.displayName === 'View' || type.name === 'View') &&
16
- props &&
18
+ export function jsxDEV(...args: Parameters<typeof ReactJSXRuntimeDev.jsxDEV>) {
19
+ const [type, props, key, isStaticChildren, source, self] = args;
20
+ const isViewType =
21
+ isNamedElementType(type) &&
22
+ (type.displayName === 'View' || type.name === 'View');
23
+ const nextProps =
24
+ isViewType &&
25
+ isPropsObject(props) &&
17
26
  props.collapsable === undefined
18
- ) {
19
- props = { ...props, collapsable: true };
27
+ ? { ...props, collapsable: true }
28
+ : props;
29
+
30
+ if (isViewType && isPropsObject(props) && props.collapsable === undefined) {
31
+ return ReactJSXRuntimeDev.jsxDEV(
32
+ type,
33
+ nextProps,
34
+ key,
35
+ isStaticChildren,
36
+ source,
37
+ self
38
+ );
20
39
  }
21
40
  return ReactJSXRuntimeDev.jsxDEV(
22
41
  type,
23
- props,
42
+ nextProps,
24
43
  key,
25
44
  isStaticChildren,
26
45
  source,
@@ -4,6 +4,11 @@ import type {
4
4
  TestSuite,
5
5
  TestSuiteResult,
6
6
  } from '@react-native-harness/bridge';
7
+ import {
8
+ setCurrentExpectTestState,
9
+ type HarnessExpectTestState,
10
+ } from '../expect/context.js';
11
+ import { flushExpectTestState } from '../expect/errors.js';
7
12
  import { runHooks } from './hooks.js';
8
13
  import { getTestExecutionError } from './errors.js';
9
14
  import { TestRunnerContext } from './types.js';
@@ -15,7 +20,7 @@ declare global {
15
20
  const runTest = async (
16
21
  test: TestCase,
17
22
  suite: TestSuite,
18
- context: TestRunnerContext
23
+ context: TestRunnerContext,
19
24
  ): Promise<TestResult> => {
20
25
  const startTime = Date.now();
21
26
 
@@ -69,14 +74,23 @@ const runTest = async (
69
74
  return result;
70
75
  }
71
76
 
72
- // Run all beforeEach hooks from the current suite and its parents
73
- await runHooks(suite, 'beforeEach');
77
+ const expectTestState: HarnessExpectTestState = {};
78
+ setCurrentExpectTestState(expectTestState);
74
79
 
75
- // Run the actual test
76
- await test.fn();
80
+ try {
81
+ // Run all beforeEach hooks from the current suite and its parents
82
+ await runHooks(suite, 'beforeEach');
77
83
 
78
- // Run all afterEach hooks from the current suite and its parents
79
- await runHooks(suite, 'afterEach');
84
+ // Run the actual test
85
+ await test.fn();
86
+
87
+ // Run all afterEach hooks from the current suite and its parents
88
+ await runHooks(suite, 'afterEach');
89
+
90
+ await flushExpectTestState(expectTestState);
91
+ } finally {
92
+ setCurrentExpectTestState(undefined);
93
+ }
80
94
 
81
95
  const duration = Date.now() - startTime;
82
96
 
@@ -102,7 +116,7 @@ const runTest = async (
102
116
  error,
103
117
  context.testFilePath,
104
118
  suite.name,
105
- test.name
119
+ test.name,
106
120
  );
107
121
  const duration = Date.now() - startTime;
108
122
 
@@ -130,7 +144,7 @@ const runTest = async (
130
144
 
131
145
  export const runSuite = async (
132
146
  suite: TestSuite,
133
- context: TestRunnerContext
147
+ context: TestRunnerContext,
134
148
  ): Promise<TestSuiteResult> => {
135
149
  const startTime = Date.now();
136
150
 
@@ -212,10 +226,10 @@ export const runSuite = async (
212
226
 
213
227
  // Check if any tests or child suites failed
214
228
  const hasFailedTests = testResults.some(
215
- (result) => result.status === 'failed'
229
+ (result) => result.status === 'failed',
216
230
  );
217
231
  const hasFailedSuites = suiteResults.some(
218
- (result) => result.status === 'failed'
232
+ (result) => result.status === 'failed',
219
233
  );
220
234
 
221
235
  if (hasFailedTests || hasFailedSuites) {
package/src/waitFor.ts CHANGED
@@ -114,6 +114,12 @@ export interface WaitUntilOptions
114
114
 
115
115
  type Truthy<T> = T extends false | '' | 0 | null | undefined ? never : T;
116
116
 
117
+ const isPromiseLike = <T>(value: T | PromiseLike<T>): value is PromiseLike<T> =>
118
+ value !== null &&
119
+ typeof value === 'object' &&
120
+ 'then' in value &&
121
+ typeof value.then === 'function';
122
+
117
123
  export function waitUntil<T>(
118
124
  callback: WaitUntilCallback<T>,
119
125
  options: number | WaitUntilOptions = {}
@@ -164,12 +170,8 @@ export function waitUntil<T>(
164
170
  }
165
171
  try {
166
172
  const result = callback();
167
- if (
168
- result !== null &&
169
- typeof result === 'object' &&
170
- typeof (result as any).then === 'function'
171
- ) {
172
- const thenable = result as PromiseLike<T>;
173
+ if (isPromiseLike(result)) {
174
+ const thenable = result;
173
175
  promiseStatus = 'pending';
174
176
  thenable.then(
175
177
  (resolvedValue) => {