@react-native-harness/runtime 1.0.0-alpha.2 → 1.0.0-alpha.21

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 (169) hide show
  1. package/README.md +23 -4
  2. package/assets/harness-module-system.js +73 -0
  3. package/dist/bundler/bundle.d.ts.map +1 -1
  4. package/dist/bundler/bundle.js +7 -2
  5. package/dist/bundler/errors.d.ts +5 -0
  6. package/dist/bundler/errors.d.ts.map +1 -1
  7. package/dist/bundler/errors.js +11 -0
  8. package/dist/bundler/evaluate.d.ts.map +1 -1
  9. package/dist/bundler/evaluate.js +7 -7
  10. package/dist/bundler/factory.d.ts +3 -0
  11. package/dist/bundler/factory.d.ts.map +1 -0
  12. package/dist/bundler/factory.js +36 -0
  13. package/dist/bundler/index.d.ts +2 -1
  14. package/dist/bundler/index.d.ts.map +1 -1
  15. package/dist/bundler/index.js +1 -1
  16. package/dist/bundler/types.d.ts +7 -0
  17. package/dist/bundler/types.d.ts.map +1 -0
  18. package/dist/bundler/types.js +1 -0
  19. package/dist/client/factory.d.ts.map +1 -1
  20. package/dist/client/factory.js +34 -6
  21. package/dist/client/getDeviceDescriptor.d.ts +1 -1
  22. package/dist/client/getDeviceDescriptor.d.ts.map +1 -1
  23. package/dist/client/getDeviceDescriptor.js +18 -6
  24. package/dist/client/getWSServer.d.ts.map +1 -1
  25. package/dist/client/getWSServer.js +2 -1
  26. package/dist/client/setup-files.d.ts +12 -0
  27. package/dist/client/setup-files.d.ts.map +1 -0
  28. package/dist/client/setup-files.js +60 -0
  29. package/dist/collector/functions.d.ts +1 -1
  30. package/dist/collector/functions.d.ts.map +1 -1
  31. package/dist/collector/functions.js +10 -2
  32. package/dist/collector/types.d.ts +1 -1
  33. package/dist/collector/types.d.ts.map +1 -1
  34. package/dist/constants.d.ts +0 -1
  35. package/dist/constants.d.ts.map +1 -1
  36. package/dist/constants.js +0 -1
  37. package/dist/disableHMRWhenReady.d.ts +2 -0
  38. package/dist/disableHMRWhenReady.d.ts.map +1 -0
  39. package/dist/disableHMRWhenReady.js +20 -0
  40. package/dist/entry-point.d.ts +2 -0
  41. package/dist/entry-point.d.ts.map +1 -0
  42. package/dist/entry-point.js +4 -0
  43. package/dist/expect/index.d.ts.map +1 -1
  44. package/dist/expect/index.js +2 -0
  45. package/dist/expect/setup.js +2 -0
  46. package/dist/filtering/index.d.ts +2 -0
  47. package/dist/filtering/index.d.ts.map +1 -0
  48. package/dist/filtering/index.js +1 -0
  49. package/dist/filtering/testNameFilter.d.ts +12 -0
  50. package/dist/filtering/testNameFilter.d.ts.map +1 -0
  51. package/dist/filtering/testNameFilter.js +56 -0
  52. package/dist/globals.d.ts +6 -2
  53. package/dist/globals.d.ts.map +1 -1
  54. package/dist/globals.js +7 -1
  55. package/dist/index.d.ts +4 -0
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +4 -0
  58. package/dist/initialize.js +14 -6
  59. package/dist/jest-mock.d.ts +2 -0
  60. package/dist/jest-mock.d.ts.map +1 -0
  61. package/dist/jest-mock.js +25 -0
  62. package/dist/mocker/index.d.ts +1 -1
  63. package/dist/mocker/index.d.ts.map +1 -1
  64. package/dist/mocker/index.js +1 -1
  65. package/dist/mocker/registry.d.ts +2 -3
  66. package/dist/mocker/registry.d.ts.map +1 -1
  67. package/dist/mocker/registry.js +25 -16
  68. package/dist/namespace.d.ts +18 -0
  69. package/dist/namespace.d.ts.map +1 -0
  70. package/dist/namespace.js +19 -0
  71. package/dist/polyfills.d.ts +11 -0
  72. package/dist/polyfills.d.ts.map +1 -0
  73. package/dist/polyfills.js +13 -0
  74. package/dist/render/ErrorBoundary.d.ts +17 -0
  75. package/dist/render/ErrorBoundary.d.ts.map +1 -0
  76. package/dist/render/ErrorBoundary.js +73 -0
  77. package/dist/render/TestComponentOverlay.d.ts +3 -0
  78. package/dist/render/TestComponentOverlay.d.ts.map +1 -0
  79. package/dist/render/TestComponentOverlay.js +36 -0
  80. package/dist/render/cleanup.d.ts +2 -0
  81. package/dist/render/cleanup.d.ts.map +1 -0
  82. package/dist/render/cleanup.js +6 -0
  83. package/dist/render/index.d.ts +6 -0
  84. package/dist/render/index.d.ts.map +1 -0
  85. package/dist/render/index.js +66 -0
  86. package/dist/render/setup.d.ts +2 -0
  87. package/dist/render/setup.d.ts.map +1 -0
  88. package/dist/render/setup.js +7 -0
  89. package/dist/render/types.d.ts +12 -0
  90. package/dist/render/types.d.ts.map +1 -0
  91. package/dist/render/types.js +1 -0
  92. package/dist/runner/errors.d.ts +4 -2
  93. package/dist/runner/errors.d.ts.map +1 -1
  94. package/dist/runner/errors.js +21 -3
  95. package/dist/runner/factory.d.ts.map +1 -1
  96. package/dist/runner/factory.js +6 -1
  97. package/dist/runner/runSuite.d.ts.map +1 -1
  98. package/dist/runner/runSuite.js +59 -7
  99. package/dist/symbolicate.d.ts +3 -0
  100. package/dist/symbolicate.d.ts.map +1 -0
  101. package/dist/symbolicate.js +19 -0
  102. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  103. package/dist/ui/ReadyScreen.d.ts.map +1 -1
  104. package/dist/ui/ReadyScreen.js +3 -10
  105. package/dist/ui/WrongEnvironmentScreen.d.ts.map +1 -1
  106. package/dist/ui/WrongEnvironmentScreen.js +2 -10
  107. package/dist/ui/state.d.ts +14 -1
  108. package/dist/ui/state.d.ts.map +1 -1
  109. package/dist/ui/state.js +22 -0
  110. package/dist/utils/emitter.d.ts.map +1 -1
  111. package/dist/waitFor.d.ts +21 -0
  112. package/dist/waitFor.d.ts.map +1 -0
  113. package/dist/waitFor.js +137 -0
  114. package/eslint.config.mjs +1 -7
  115. package/package.json +22 -14
  116. package/src/__tests__/collector.test.ts +55 -55
  117. package/src/__tests__/error-handling.test.ts +34 -34
  118. package/src/__tests__/expect.test.ts +13 -5
  119. package/src/__tests__/initialize.test.ts +24 -0
  120. package/src/bundler/bundle.ts +9 -2
  121. package/src/bundler/errors.ts +11 -0
  122. package/src/bundler/evaluate.ts +9 -9
  123. package/src/bundler/factory.ts +43 -0
  124. package/src/bundler/index.ts +2 -1
  125. package/src/bundler/types.ts +7 -0
  126. package/src/client/factory.ts +53 -11
  127. package/src/client/getDeviceDescriptor.ts +29 -8
  128. package/src/client/getWSServer.ts +2 -1
  129. package/src/client/setup-files.ts +81 -0
  130. package/src/collector/functions.ts +18 -2
  131. package/src/collector/types.ts +4 -1
  132. package/src/constants.ts +0 -1
  133. package/src/disableHMRWhenReady.ts +27 -0
  134. package/src/entry-point.ts +8 -0
  135. package/src/expect/index.ts +8 -2
  136. package/src/expect/setup.ts +3 -0
  137. package/src/filtering/index.ts +4 -0
  138. package/src/filtering/testNameFilter.ts +82 -0
  139. package/src/globals.ts +15 -2
  140. package/src/index.ts +4 -0
  141. package/src/initialize.ts +21 -8
  142. package/src/jest-mock.ts +32 -0
  143. package/src/mocker/index.ts +6 -1
  144. package/src/mocker/metro-require.d.ts +2 -0
  145. package/src/mocker/registry.ts +29 -18
  146. package/src/namespace.ts +41 -0
  147. package/src/polyfills.ts +14 -0
  148. package/src/react-native.d.ts +35 -6
  149. package/src/render/ErrorBoundary.tsx +108 -0
  150. package/src/render/TestComponentOverlay.tsx +47 -0
  151. package/src/render/cleanup.ts +7 -0
  152. package/src/render/index.ts +96 -0
  153. package/src/render/setup.ts +8 -0
  154. package/src/render/types.ts +11 -0
  155. package/src/runner/errors.ts +35 -5
  156. package/src/runner/factory.ts +8 -1
  157. package/src/runner/runSuite.ts +70 -9
  158. package/src/symbolicate.ts +24 -0
  159. package/src/ui/ReadyScreen.tsx +2 -12
  160. package/src/ui/WrongEnvironmentScreen.tsx +1 -19
  161. package/src/ui/state.ts +39 -0
  162. package/src/utils/emitter.ts +1 -0
  163. package/src/waitFor.ts +199 -0
  164. package/tsconfig.spec.json +7 -3
  165. package/tsconfig.tsbuildinfo +1 -1
  166. package/assets/logo.png +0 -0
  167. package/assets/moduleSystem.flow.js +0 -1062
  168. package/types/global.d.ts +0 -2
  169. package/types/index.d.ts +0 -1
@@ -0,0 +1,2 @@
1
+ export { filterTestsByName, markTestsAsSkippedByName, } from './testNameFilter.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filtering/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,wBAAwB,GACzB,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ export { filterTestsByName, markTestsAsSkippedByName, } from './testNameFilter.js';
@@ -0,0 +1,12 @@
1
+ import { TestSuite } from '@react-native-harness/bridge';
2
+ /**
3
+ * Filters tests by name pattern, matching against test names and suite+test combinations
4
+ * @deprecated Use markTestsAsSkippedByName instead - this function will be removed in a future version
5
+ */
6
+ export declare const filterTestsByName: (suite: TestSuite, testNamePattern: string) => TestSuite;
7
+ /**
8
+ * Marks tests as skipped based on name pattern, keeping all tests in the structure
9
+ * but setting non-matching tests to 'skipped' status
10
+ */
11
+ export declare const markTestsAsSkippedByName: (suite: TestSuite, testNamePattern: string) => TestSuite;
12
+ //# sourceMappingURL=testNameFilter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testNameFilter.d.ts","sourceRoot":"","sources":["../../src/filtering/testNameFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,OAAO,SAAS,EAChB,iBAAiB,MAAM,KACtB,SAGF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,wBAAwB,GACnC,OAAO,SAAS,EAChB,iBAAiB,MAAM,KACtB,SAGF,CAAC"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Filters tests by name pattern, matching against test names and suite+test combinations
3
+ * @deprecated Use markTestsAsSkippedByName instead - this function will be removed in a future version
4
+ */
5
+ export const filterTestsByName = (suite, testNamePattern) => {
6
+ const regex = new RegExp(testNamePattern);
7
+ return filterSuiteRecursively(suite, regex);
8
+ };
9
+ /**
10
+ * Marks tests as skipped based on name pattern, keeping all tests in the structure
11
+ * but setting non-matching tests to 'skipped' status
12
+ */
13
+ export const markTestsAsSkippedByName = (suite, testNamePattern) => {
14
+ const regex = new RegExp(testNamePattern);
15
+ return markTestsRecursively(suite, regex);
16
+ };
17
+ const markTestsRecursively = (suite, regex) => {
18
+ // Mark tests in current suite - skip tests that don't match the pattern
19
+ const updatedTests = suite.tests.map((test) => {
20
+ const matches = regex.test(test.name) || regex.test(`${suite.name} ${test.name}`);
21
+ // If test doesn't match pattern and is currently active, mark it as skipped
22
+ if (!matches && test.status === 'active') {
23
+ return {
24
+ ...test,
25
+ status: 'skipped',
26
+ };
27
+ }
28
+ // Keep original status for matching tests or already skipped/todo tests
29
+ return test;
30
+ });
31
+ // Recursively process child suites
32
+ const updatedChildSuites = suite.suites.map((childSuite) => markTestsRecursively(childSuite, regex));
33
+ return {
34
+ ...suite,
35
+ tests: updatedTests,
36
+ suites: updatedChildSuites,
37
+ };
38
+ };
39
+ const filterSuiteRecursively = (suite, regex) => {
40
+ // Filter tests in current suite - match against test name or "suite test" combination
41
+ const filteredTests = suite.tests.filter((test) => regex.test(test.name) || regex.test(`${suite.name} ${test.name}`));
42
+ // Recursively filter child suites
43
+ const filteredChildSuites = suite.suites
44
+ .map((childSuite) => filterSuiteRecursively(childSuite, regex))
45
+ .filter((childSuite) => hasAnyActiveTests(childSuite));
46
+ return {
47
+ ...suite,
48
+ tests: filteredTests,
49
+ suites: filteredChildSuites,
50
+ };
51
+ };
52
+ const hasAnyActiveTests = (suite) => {
53
+ const hasDirectTests = suite.tests.some((test) => test.status === 'active');
54
+ const hasChildTests = suite.suites.some((childSuite) => hasAnyActiveTests(childSuite));
55
+ return hasDirectTests || hasChildTests;
56
+ };
package/dist/globals.d.ts CHANGED
@@ -1,5 +1,9 @@
1
+ export type HarnessGlobal = {
2
+ appRegistryComponentName: string;
3
+ webSocketPort?: number;
4
+ };
1
5
  declare global {
2
- var RN_HARNESS: boolean | undefined;
6
+ var RN_HARNESS: HarnessGlobal | undefined;
3
7
  }
4
- export {};
8
+ export declare const getHarnessGlobal: () => HarnessGlobal;
5
9
  //# sourceMappingURL=globals.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG;IAC1B,wBAAwB,EAAE,MAAM,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,UAAU,EAAE,aAAa,GAAG,SAAS,CAAC;CAC3C;AAED,eAAO,MAAM,gBAAgB,QAAO,aAQnC,CAAC"}
package/dist/globals.js CHANGED
@@ -1 +1,7 @@
1
- export {};
1
+ export const getHarnessGlobal = () => {
2
+ const harnessGlobal = global.RN_HARNESS;
3
+ if (!harnessGlobal) {
4
+ throw new Error('RN_HARNESS global is not set');
5
+ }
6
+ return harnessGlobal;
7
+ };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,11 @@
1
+ import './polyfills.js';
1
2
  import './globals.d.ts';
2
3
  export { UI as ReactNativeHarness } from './ui/index.js';
3
4
  export * from './spy/index.js';
4
5
  export * from './expect/index.js';
5
6
  export * from './collector/index.js';
6
7
  export * from './mocker/index.js';
8
+ export * from './namespace.js';
9
+ export * from './waitFor.js';
10
+ export * from './render/index.js';
7
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,CAAC;AACxB,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;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,10 @@
1
+ import './polyfills.js';
1
2
  import './globals.d.ts';
2
3
  export { UI as ReactNativeHarness } from './ui/index.js';
3
4
  export * from './spy/index.js';
4
5
  export * from './expect/index.js';
5
6
  export * from './collector/index.js';
6
7
  export * from './mocker/index.js';
8
+ export * from './namespace.js';
9
+ export * from './waitFor.js';
10
+ export * from './render/index.js';
@@ -1,16 +1,24 @@
1
1
  import { getDeviceDescriptor } from './client/getDeviceDescriptor.js';
2
2
  import { getClient } from './client/index.js';
3
+ import { disableHMRWhenReady } from './disableHMRWhenReady.js';
4
+ import { setupJestMock } from './jest-mock.js';
3
5
  // Polyfill for EventTarget
4
6
  const Shim = require('event-target-shim');
5
7
  globalThis.Event = Shim.Event;
6
8
  globalThis.EventTarget = Shim.EventTarget;
9
+ // Setup jest mock to warn users about using Jest APIs
10
+ setupJestMock();
7
11
  // Turn off LogBox
8
12
  const { LogBox } = require('react-native');
9
13
  LogBox.ignoreAllLogs(true);
10
14
  // 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()));
15
+ const HMRClientModule = require('react-native/Libraries/Utilities/HMRClient');
16
+ const HMRClient = 'default' in HMRClientModule ? HMRClientModule.default : HMRClientModule;
17
+ // Wait for HMRClient to be initialized
18
+ setTimeout(() => {
19
+ void disableHMRWhenReady(() => HMRClient.disable(), 50).then(() => getClient().then((client) => client.rpc.reportReady(getDeviceDescriptor())));
20
+ });
21
+ // Re-throw fatal errors
22
+ ErrorUtils.setGlobalHandler((error) => {
23
+ throw error;
24
+ });
@@ -0,0 +1,2 @@
1
+ export declare const setupJestMock: () => void;
2
+ //# sourceMappingURL=jest-mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jest-mock.d.ts","sourceRoot":"","sources":["../src/jest-mock.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa,QAAO,IA8BhC,CAAC"}
@@ -0,0 +1,25 @@
1
+ // Mock jest global to warn users about using Jest APIs in Harness tests
2
+ export const setupJestMock = () => {
3
+ function throwError() {
4
+ throw new Error(`Jest globals are not available in Harness tests. Import from 'react-native-harness' instead (e.g., import { harness } from 'react-native-harness'; harness.fn())`);
5
+ }
6
+ const jestMock = new Proxy({}, {
7
+ get() {
8
+ throwError();
9
+ },
10
+ set() {
11
+ throwError();
12
+ },
13
+ has() {
14
+ throwError();
15
+ },
16
+ ownKeys() {
17
+ throwError();
18
+ },
19
+ });
20
+ Object.defineProperty(globalThis, 'jest', {
21
+ value: jestMock,
22
+ writable: false,
23
+ configurable: false,
24
+ });
25
+ };
@@ -1,2 +1,2 @@
1
- export { mock, requireActual, clearMocks } from './registry.js';
1
+ export { mock, requireActual, unmock, resetModules, } from './registry.js';
2
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mocker/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,aAAa,EACb,MAAM,EACN,YAAY,GACb,MAAM,eAAe,CAAC"}
@@ -1 +1 @@
1
- export { mock, requireActual, clearMocks } from './registry.js';
1
+ export { mock, requireActual, unmock, resetModules, } from './registry.js';
@@ -1,7 +1,6 @@
1
1
  import { ModuleFactory } from './types.js';
2
2
  export declare const mock: (moduleId: string, 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
3
  export declare const requireActual: <T = any>(moduleId: string) => T;
4
+ export declare const unmock: (moduleId: string) => void;
5
+ export declare const resetModules: () => void;
7
6
  //# sourceMappingURL=registry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/mocker/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAqB,MAAM,YAAY,CAAC;AAO9D,eAAO,MAAM,IAAI,GAAI,UAAU,MAAM,EAAE,SAAS,aAAa,KAAG,IAG/D,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"}
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/mocker/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAqB,MAAM,YAAY,CAAC;AAO9D,eAAO,MAAM,IAAI,GAAI,UAAU,MAAM,EAAE,SAAS,aAAa,KAAG,IAG/D,CAAC;AAmBF,eAAO,MAAM,aAAa,GAAI,CAAC,GAAG,GAAG,EAAE,UAAU,MAAM,KAAG,CAEH,CAAC;AAExD,eAAO,MAAM,MAAM,GAAI,UAAU,MAAM,SAGtC,CAAC;AAEF,eAAO,MAAM,YAAY,QAAO,IAG/B,CAAC"}
@@ -1,40 +1,49 @@
1
+ const modulesCache = new Map();
1
2
  const mockRegistry = new Map();
2
- const mockCache = new Map();
3
3
  const originalRequire = global.__r;
4
4
  export const mock = (moduleId, factory) => {
5
- mockCache.delete(moduleId);
5
+ modulesCache.delete(moduleId);
6
6
  mockRegistry.set(moduleId, factory);
7
7
  };
8
- export const clearMocks = () => {
9
- mockRegistry.clear();
10
- mockCache.clear();
11
- };
12
- export const getMockRegistry = () => {
13
- return mockRegistry;
8
+ const isModuleMocked = (moduleId) => {
9
+ return mockRegistry.has(moduleId);
14
10
  };
15
- export const getMockImplementation = (moduleId) => {
16
- if (mockCache.has(moduleId)) {
17
- return mockCache.get(moduleId);
18
- }
11
+ const getMockImplementation = (moduleId) => {
19
12
  const factory = mockRegistry.get(moduleId);
20
13
  if (!factory) {
21
14
  return null;
22
15
  }
23
16
  const implementation = factory();
24
- mockCache.set(moduleId, implementation);
17
+ modulesCache.set(moduleId, implementation);
25
18
  return implementation;
26
19
  };
27
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
21
  export const requireActual = (moduleId) =>
29
22
  // babel plugin will transform 'moduleId' to a number
30
23
  originalRequire(moduleId);
24
+ export const unmock = (moduleId) => {
25
+ mockRegistry.delete(moduleId);
26
+ modulesCache.delete(moduleId);
27
+ };
28
+ export const resetModules = () => {
29
+ modulesCache.clear();
30
+ mockRegistry.clear();
31
+ };
31
32
  const mockRequire = (moduleId) => {
32
33
  // babel plugin will transform 'moduleId' to a number
33
- const mockedModule = getMockImplementation(moduleId);
34
- if (mockedModule) {
34
+ const moduleIdNumber = moduleId;
35
+ const cachedModule = modulesCache.get(moduleIdNumber);
36
+ if (cachedModule) {
37
+ return cachedModule;
38
+ }
39
+ if (isModuleMocked(moduleIdNumber)) {
40
+ const mockedModule = getMockImplementation(moduleIdNumber);
41
+ modulesCache.set(moduleIdNumber, mockedModule);
35
42
  return mockedModule;
36
43
  }
37
- return originalRequire(moduleId);
44
+ const originalModule = originalRequire(moduleIdNumber);
45
+ modulesCache.set(moduleIdNumber, originalModule);
46
+ return originalModule;
38
47
  };
39
48
  Object.setPrototypeOf(mockRequire, Object.getPrototypeOf(originalRequire));
40
49
  Object.defineProperties(mockRequire, Object.getOwnPropertyDescriptors(originalRequire));
@@ -0,0 +1,18 @@
1
+ import { spyOn, fn, clearAllMocks, resetAllMocks, restoreAllMocks } from './spy/index.js';
2
+ import { mock, unmock, requireActual, resetModules } from './mocker/index.js';
3
+ import { waitFor, waitUntil } from './waitFor.js';
4
+ export type HarnessNamespace = {
5
+ spyOn: typeof spyOn;
6
+ fn: typeof fn;
7
+ mock: typeof mock;
8
+ unmock: typeof unmock;
9
+ requireActual: typeof requireActual;
10
+ clearAllMocks: typeof clearAllMocks;
11
+ resetAllMocks: typeof resetAllMocks;
12
+ restoreAllMocks: typeof restoreAllMocks;
13
+ resetModules: typeof resetModules;
14
+ waitFor: typeof waitFor;
15
+ waitUntil: typeof waitUntil;
16
+ };
17
+ export declare const harness: HarnessNamespace;
18
+ //# sourceMappingURL=namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../src/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,EAAE,EACF,aAAa,EACb,aAAa,EACb,eAAe,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,OAAO,KAAK,CAAC;IACpB,EAAE,EAAE,OAAO,EAAE,CAAC;IACd,IAAI,EAAE,OAAO,IAAI,CAAC;IAClB,MAAM,EAAE,OAAO,MAAM,CAAC;IACtB,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,aAAa,EAAE,OAAO,aAAa,CAAC;IACpC,eAAe,EAAE,OAAO,eAAe,CAAC;IACxC,YAAY,EAAE,OAAO,YAAY,CAAC;IAClC,OAAO,EAAE,OAAO,OAAO,CAAC;IACxB,SAAS,EAAE,OAAO,SAAS,CAAC;CAC7B,CAAC;AAkBF,eAAO,MAAM,OAAO,kBAA2B,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { spyOn, fn, clearAllMocks, resetAllMocks, restoreAllMocks, } from './spy/index.js';
2
+ import { mock, unmock, requireActual, resetModules } from './mocker/index.js';
3
+ import { waitFor, waitUntil } from './waitFor.js';
4
+ const createHarnessNamespace = () => {
5
+ return {
6
+ spyOn,
7
+ fn,
8
+ mock,
9
+ unmock,
10
+ requireActual,
11
+ clearAllMocks,
12
+ resetAllMocks,
13
+ restoreAllMocks,
14
+ resetModules,
15
+ waitFor,
16
+ waitUntil,
17
+ };
18
+ };
19
+ export const harness = createHarnessNamespace();
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Polyfills for ES2022+ features not supported by JSC (JavaScriptCore).
3
+ *
4
+ * JSC, used in React Native when Hermes is disabled, doesn't support
5
+ * Object.hasOwn (ES2022). This causes runtime errors when @vitest/expect
6
+ * v4.x initializes.
7
+ *
8
+ * This polyfill must be loaded before any code that uses Object.hasOwn.
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=polyfills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polyfills.d.ts","sourceRoot":"","sources":["../src/polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Polyfills for ES2022+ features not supported by JSC (JavaScriptCore).
3
+ *
4
+ * JSC, used in React Native when Hermes is disabled, doesn't support
5
+ * Object.hasOwn (ES2022). This causes runtime errors when @vitest/expect
6
+ * v4.x initializes.
7
+ *
8
+ * This polyfill must be loaded before any code that uses Object.hasOwn.
9
+ */
10
+ if (typeof Object.hasOwn !== 'function') {
11
+ Object.hasOwn = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
12
+ }
13
+ export {};
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ type ErrorBoundaryProps = {
3
+ children: React.ReactNode;
4
+ };
5
+ type ErrorBoundaryState = {
6
+ hasError: boolean;
7
+ error: Error | null;
8
+ };
9
+ export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
10
+ constructor(props: ErrorBoundaryProps);
11
+ static getDerivedStateFromError(error: Error): ErrorBoundaryState;
12
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
13
+ componentDidUpdate(prevProps: ErrorBoundaryProps): void;
14
+ render(): React.ReactNode;
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=ErrorBoundary.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBoundary.d.ts","sourceRoot":"","sources":["../../src/render/ErrorBoundary.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,CAAC;AAEF,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB,CAAC;AAEF,qBAAa,aAAc,SAAQ,KAAK,CAAC,SAAS,CAChD,kBAAkB,EAClB,kBAAkB,CACnB;gBACa,KAAK,EAAE,kBAAkB;IAKrC,MAAM,CAAC,wBAAwB,CAAC,KAAK,EAAE,KAAK,GAAG,kBAAkB;IAIxD,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,GAAG,IAAI;IAIjE,kBAAkB,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI;IAOvD,MAAM,IAAI,KAAK,CAAC,SAAS;CAwBnC"}
@@ -0,0 +1,73 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
3
+ import { View, Text, StyleSheet, ScrollView } from 'react-native';
4
+ export class ErrorBoundary extends React.Component {
5
+ constructor(props) {
6
+ super(props);
7
+ this.state = { hasError: false, error: null };
8
+ }
9
+ static getDerivedStateFromError(error) {
10
+ return { hasError: true, error };
11
+ }
12
+ componentDidCatch(error, errorInfo) {
13
+ console.error('Error caught by ErrorBoundary:', error, errorInfo);
14
+ }
15
+ componentDidUpdate(prevProps) {
16
+ // Reset error state when children change (new component rendered)
17
+ if (prevProps.children !== this.props.children && this.state.hasError) {
18
+ this.setState({ hasError: false, error: null });
19
+ }
20
+ }
21
+ render() {
22
+ if (this.state.hasError && this.state.error) {
23
+ return (_jsx(View, { style: styles.errorContainer, children: _jsxs(View, { style: styles.errorContent, children: [_jsx(Text, { style: styles.errorTitle, children: "Component Error" }), _jsx(Text, { style: styles.errorSubtitle, children: "The rendered component threw an error:" }), _jsxs(ScrollView, { style: styles.errorScrollView, children: [_jsx(Text, { style: styles.errorMessage, children: this.state.error.message }), this.state.error.stack && (_jsx(Text, { style: styles.errorStack, children: this.state.error.stack }))] })] }) }));
24
+ }
25
+ return this.props.children;
26
+ }
27
+ }
28
+ const styles = StyleSheet.create({
29
+ errorContainer: {
30
+ flex: 1,
31
+ backgroundColor: 'rgba(220, 38, 38, 0.1)',
32
+ justifyContent: 'center',
33
+ alignItems: 'center',
34
+ padding: 20,
35
+ },
36
+ errorContent: {
37
+ backgroundColor: '#1f2937',
38
+ borderRadius: 12,
39
+ padding: 20,
40
+ maxWidth: 500,
41
+ width: '100%',
42
+ maxHeight: '80%',
43
+ borderWidth: 2,
44
+ borderColor: '#dc2626',
45
+ },
46
+ errorTitle: {
47
+ fontSize: 24,
48
+ fontWeight: '700',
49
+ color: '#dc2626',
50
+ marginBottom: 8,
51
+ },
52
+ errorSubtitle: {
53
+ fontSize: 14,
54
+ color: '#9ca3af',
55
+ marginBottom: 16,
56
+ },
57
+ errorScrollView: {
58
+ maxHeight: 400,
59
+ },
60
+ errorMessage: {
61
+ fontSize: 16,
62
+ fontWeight: '600',
63
+ color: '#fca5a5',
64
+ marginBottom: 12,
65
+ fontFamily: 'Courier',
66
+ },
67
+ errorStack: {
68
+ fontSize: 12,
69
+ color: '#d1d5db',
70
+ fontFamily: 'Courier',
71
+ lineHeight: 18,
72
+ },
73
+ });
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare const TestComponentOverlay: () => React.ReactElement | null;
3
+ //# sourceMappingURL=TestComponentOverlay.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TestComponentOverlay.d.ts","sourceRoot":"","sources":["../../src/render/TestComponentOverlay.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAMzC,eAAO,MAAM,oBAAoB,QAAO,KAAK,CAAC,YAAY,GAAG,IAgC5D,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect } from 'react';
3
+ import { View, StyleSheet } from 'react-native';
4
+ import { useRenderedElement } from '../ui/state.js';
5
+ import { store } from '../ui/state.js';
6
+ import { ErrorBoundary } from './ErrorBoundary.js';
7
+ export const TestComponentOverlay = () => {
8
+ const { element, key } = useRenderedElement();
9
+ useEffect(() => {
10
+ // Call onRenderCallback when element changes
11
+ const callback = store.getState().onRenderCallback;
12
+ if (callback) {
13
+ callback();
14
+ store.getState().setOnRenderCallback(null);
15
+ }
16
+ }, [element]);
17
+ if (!element) {
18
+ return null;
19
+ }
20
+ const handleLayout = () => {
21
+ const callback = store.getState().onLayoutCallback;
22
+ if (callback) {
23
+ callback();
24
+ // Clear the callback after calling it
25
+ store.getState().setOnLayoutCallback(null);
26
+ }
27
+ };
28
+ return (_jsx(View, { style: styles.overlay, onLayout: handleLayout, children: _jsx(ErrorBoundary, { children: element }) }, key));
29
+ };
30
+ const styles = StyleSheet.create({
31
+ overlay: {
32
+ ...StyleSheet.absoluteFillObject,
33
+ backgroundColor: '#0a1628',
34
+ zIndex: 1000,
35
+ },
36
+ });
@@ -0,0 +1,2 @@
1
+ export declare const cleanup: () => void;
2
+ //# sourceMappingURL=cleanup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cleanup.d.ts","sourceRoot":"","sources":["../../src/render/cleanup.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,QAAO,IAI1B,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { store } from '../ui/state.js';
2
+ export const cleanup = () => {
3
+ store.getState().setRenderedElement(null);
4
+ store.getState().setOnLayoutCallback(null);
5
+ store.getState().setOnRenderCallback(null);
6
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import type { RenderResult, RenderOptions } from './types.js';
3
+ export declare const render: (element: React.ReactElement, options?: RenderOptions) => Promise<RenderResult>;
4
+ export { cleanup } from './cleanup.js';
5
+ export type { RenderResult, RenderOptions } from './types.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAY9D,eAAO,MAAM,MAAM,GACjB,SAAS,KAAK,CAAC,YAAY,EAC3B,UAAS,aAAkB,KAC1B,OAAO,CAAC,YAAY,CA2EtB,CAAC;AAEF,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,66 @@
1
+ import React from 'react';
2
+ import { store } from '../ui/state.js';
3
+ const wrapElement = (element, wrapper) => {
4
+ if (!wrapper) {
5
+ return element;
6
+ }
7
+ return React.createElement(wrapper, { children: element });
8
+ };
9
+ export const render = async (element, options = {}) => {
10
+ const { timeout = 1000, wrapper } = options;
11
+ // If an element is already rendered, unmount it first
12
+ if (store.getState().renderedElement !== null) {
13
+ store.getState().setRenderedElement(null);
14
+ store.getState().setOnLayoutCallback(null);
15
+ store.getState().setOnRenderCallback(null);
16
+ }
17
+ // Create a promise that resolves when the element is laid out
18
+ const layoutPromise = new Promise((resolve, reject) => {
19
+ const timeoutId = setTimeout(() => {
20
+ store.getState().setOnLayoutCallback(null);
21
+ reject(new Error(`Render timeout: Element did not mount within ${timeout}ms`));
22
+ }, timeout);
23
+ store.getState().setOnLayoutCallback(() => {
24
+ clearTimeout(timeoutId);
25
+ resolve();
26
+ });
27
+ });
28
+ // Wrap and set the element in state (key is generated automatically)
29
+ const wrappedElement = wrapElement(element, wrapper);
30
+ store.getState().setRenderedElement(wrappedElement);
31
+ // Wait for layout
32
+ await layoutPromise;
33
+ const rerender = async (newElement) => {
34
+ if (store.getState().renderedElement === null) {
35
+ throw new Error('No element is currently rendered. Call render() first.');
36
+ }
37
+ // Create a promise that resolves when the element is re-rendered
38
+ const renderPromise = new Promise((resolve, reject) => {
39
+ const timeoutId = setTimeout(() => {
40
+ store.getState().setOnRenderCallback(null);
41
+ reject(new Error(`Rerender timeout: Element did not update within ${timeout}ms`));
42
+ }, timeout);
43
+ store.getState().setOnRenderCallback(() => {
44
+ clearTimeout(timeoutId);
45
+ resolve();
46
+ });
47
+ });
48
+ const wrappedNewElement = wrapElement(newElement, wrapper);
49
+ store.getState().updateRenderedElement(wrappedNewElement);
50
+ // Wait for render
51
+ await renderPromise;
52
+ };
53
+ const unmount = () => {
54
+ if (store.getState().renderedElement === null) {
55
+ return;
56
+ }
57
+ store.getState().setRenderedElement(null);
58
+ store.getState().setOnLayoutCallback(null);
59
+ store.getState().setOnRenderCallback(null);
60
+ };
61
+ return {
62
+ rerender,
63
+ unmount,
64
+ };
65
+ };
66
+ export { cleanup } from './cleanup.js';
@@ -0,0 +1,2 @@
1
+ export declare const setup: () => void;
2
+ //# sourceMappingURL=setup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/render/setup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,YAIjB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { afterEach } from '../collector/functions.js';
2
+ import { cleanup } from './cleanup.js';
3
+ export const setup = () => {
4
+ afterEach(() => {
5
+ cleanup();
6
+ });
7
+ };