@react-native-harness/cli 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 (116) hide show
  1. package/dist/__tests__/platform-commands.test.d.ts +2 -0
  2. package/dist/__tests__/platform-commands.test.d.ts.map +1 -0
  3. package/dist/__tests__/platform-commands.test.js +207 -0
  4. package/dist/bundlers/metro.d.ts +5 -0
  5. package/dist/bundlers/metro.d.ts.map +1 -0
  6. package/dist/bundlers/metro.js +71 -0
  7. package/dist/bundlers/webpack.d.ts +2 -0
  8. package/dist/bundlers/webpack.d.ts.map +1 -0
  9. package/dist/bundlers/webpack.js +49 -0
  10. package/dist/commands/test.d.ts +3 -0
  11. package/dist/commands/test.d.ts.map +1 -0
  12. package/dist/commands/test.js +140 -0
  13. package/dist/discovery/index.d.ts +3 -0
  14. package/dist/discovery/index.d.ts.map +1 -0
  15. package/dist/discovery/index.js +1 -0
  16. package/dist/discovery/testDiscovery.d.ts +11 -0
  17. package/dist/discovery/testDiscovery.d.ts.map +1 -0
  18. package/dist/discovery/testDiscovery.js +29 -0
  19. package/dist/errors/appNotInstalledError.d.ts +7 -0
  20. package/dist/errors/appNotInstalledError.d.ts.map +1 -0
  21. package/dist/errors/appNotInstalledError.js +12 -0
  22. package/dist/errors/bridgeTimeoutError.d.ts +7 -0
  23. package/dist/errors/bridgeTimeoutError.d.ts.map +1 -0
  24. package/dist/errors/bridgeTimeoutError.js +12 -0
  25. package/dist/errors/errorHandler.d.ts +2 -0
  26. package/dist/errors/errorHandler.d.ts.map +1 -0
  27. package/dist/errors/errorHandler.js +152 -0
  28. package/dist/errors/errors.d.ts +45 -0
  29. package/dist/errors/errors.d.ts.map +1 -0
  30. package/dist/errors/errors.js +89 -0
  31. package/dist/index.js +113 -6
  32. package/dist/jest.d.ts +2 -0
  33. package/dist/jest.d.ts.map +1 -0
  34. package/dist/jest.js +7 -0
  35. package/dist/platform-commands.d.ts +18 -0
  36. package/dist/platform-commands.d.ts.map +1 -0
  37. package/dist/platform-commands.js +84 -0
  38. package/dist/platforms/android/build.d.ts +5 -0
  39. package/dist/platforms/android/build.d.ts.map +1 -0
  40. package/dist/platforms/android/build.js +29 -0
  41. package/dist/platforms/android/device.d.ts +5 -0
  42. package/dist/platforms/android/device.d.ts.map +1 -0
  43. package/dist/platforms/android/device.js +36 -0
  44. package/dist/platforms/android/emulator.d.ts +10 -0
  45. package/dist/platforms/android/emulator.d.ts.map +1 -0
  46. package/dist/platforms/android/emulator.js +116 -0
  47. package/dist/platforms/android/index.d.ts +4 -0
  48. package/dist/platforms/android/index.d.ts.map +1 -0
  49. package/dist/platforms/android/index.js +56 -0
  50. package/dist/platforms/ios/build.d.ts +7 -0
  51. package/dist/platforms/ios/build.d.ts.map +1 -0
  52. package/dist/platforms/ios/build.js +48 -0
  53. package/dist/platforms/ios/device.d.ts +11 -0
  54. package/dist/platforms/ios/device.d.ts.map +1 -0
  55. package/dist/platforms/ios/device.js +51 -0
  56. package/dist/platforms/ios/index.d.ts +4 -0
  57. package/dist/platforms/ios/index.d.ts.map +1 -0
  58. package/dist/platforms/ios/index.js +43 -0
  59. package/dist/platforms/ios/simulator.d.ts +11 -0
  60. package/dist/platforms/ios/simulator.d.ts.map +1 -0
  61. package/dist/platforms/ios/simulator.js +129 -0
  62. package/dist/platforms/platform-adapter.d.ts +10 -0
  63. package/dist/platforms/platform-adapter.d.ts.map +1 -0
  64. package/dist/platforms/platform-adapter.js +1 -0
  65. package/dist/platforms/platform-registry.d.ts +3 -0
  66. package/dist/platforms/platform-registry.d.ts.map +1 -0
  67. package/dist/platforms/platform-registry.js +21 -0
  68. package/dist/platforms/vega/build.d.ts +23 -0
  69. package/dist/platforms/vega/build.d.ts.map +1 -0
  70. package/dist/platforms/vega/build.js +55 -0
  71. package/dist/platforms/vega/device.d.ts +57 -0
  72. package/dist/platforms/vega/device.d.ts.map +1 -0
  73. package/dist/platforms/vega/device.js +206 -0
  74. package/dist/platforms/vega/index.d.ts +4 -0
  75. package/dist/platforms/vega/index.d.ts.map +1 -0
  76. package/dist/platforms/vega/index.js +75 -0
  77. package/dist/platforms/web/index.d.ts +4 -0
  78. package/dist/platforms/web/index.d.ts.map +1 -0
  79. package/dist/platforms/web/index.js +9 -0
  80. package/dist/process.d.ts +3 -0
  81. package/dist/process.d.ts.map +1 -0
  82. package/dist/process.js +28 -0
  83. package/dist/reporters/default-reporter.d.ts +3 -0
  84. package/dist/reporters/default-reporter.d.ts.map +1 -0
  85. package/dist/reporters/default-reporter.js +116 -0
  86. package/dist/reporters/junit-reporter.d.ts +3 -0
  87. package/dist/reporters/junit-reporter.d.ts.map +1 -0
  88. package/dist/reporters/junit-reporter.js +119 -0
  89. package/dist/reporters/live-reporter.d.ts +20 -0
  90. package/dist/reporters/live-reporter.d.ts.map +1 -0
  91. package/dist/reporters/live-reporter.js +176 -0
  92. package/dist/src/reporters/default-reporter.js +135 -0
  93. package/dist/test-reporter-demo.js +95 -0
  94. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  95. package/dist/utils/status-formatter.d.ts +27 -0
  96. package/dist/utils/status-formatter.d.ts.map +1 -0
  97. package/dist/utils/status-formatter.js +54 -0
  98. package/dist/utils.d.ts +6 -0
  99. package/dist/utils.d.ts.map +1 -0
  100. package/dist/utils.js +26 -0
  101. package/dist/wizard/bundleId.js +1 -1
  102. package/dist/wizard/jestIntegration.d.ts +2 -0
  103. package/dist/wizard/jestIntegration.d.ts.map +1 -0
  104. package/dist/wizard/jestIntegration.js +15 -0
  105. package/dist/wizard/packageManager.d.ts +2 -0
  106. package/dist/wizard/packageManager.d.ts.map +1 -0
  107. package/dist/wizard/packageManager.js +10 -0
  108. package/eslint.config.mjs +1 -1
  109. package/package.json +8 -8
  110. package/skills/core.md +92 -0
  111. package/skills/mocking.md +87 -0
  112. package/skills/ui.md +59 -0
  113. package/src/__tests__/platform-commands.test.ts +232 -0
  114. package/src/index.ts +152 -5
  115. package/src/platform-commands.ts +148 -0
  116. package/src/wizard/bundleId.ts +1 -1
@@ -0,0 +1,27 @@
1
+ import type { BridgeEvents } from '@react-native-harness/bridge';
2
+ /**
3
+ * Type-safe status line formatter for bridge events.
4
+ * This ensures every event type has a corresponding status message.
5
+ *
6
+ * When adding new events to BridgeEvents:
7
+ * 1. Add the event type to the appropriate events file in packages/bridge/src/shared/
8
+ * 2. Add a formatter function to the statusFormatter object below
9
+ * 3. TypeScript will enforce that all event types are covered
10
+ * 4. The formatter function receives the full event data for type safety
11
+ */
12
+ export type StatusFormatter = {
13
+ [K in BridgeEvents['type']]: (event: Extract<BridgeEvents, {
14
+ type: K;
15
+ }>) => string;
16
+ };
17
+ /**
18
+ * Maps every bridge event to a concise, informative status line.
19
+ * Each formatter receives the full event data for type safety.
20
+ */
21
+ export declare const statusFormatter: StatusFormatter;
22
+ /**
23
+ * Formats a bridge event into a status line.
24
+ * This function is type-safe and ensures all event types are handled.
25
+ */
26
+ export declare const formatEventStatus: (event: BridgeEvents) => string;
27
+ //# sourceMappingURL=status-formatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-formatter.d.ts","sourceRoot":"","sources":["../../src/utils/status-formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAEjE;;;;;;;;;GASG;AACH,MAAM,MAAM,eAAe,GAAG;KAC3B,CAAC,IAAI,YAAY,CAAC,MAAM,CAAC,GAAG,CAC3B,KAAK,EAAE,OAAO,CAAC,YAAY,EAAE;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,KACtC,MAAM;CACZ,CAAC;AAcF;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,eAkD7B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,YAAY,KAAG,MAGvD,CAAC"}
@@ -0,0 +1,54 @@
1
+ const formatDuration = (duration) => {
2
+ if (duration < 1000) {
3
+ return `${duration}ms`;
4
+ }
5
+ return `${(duration / 1000).toFixed(2)}s`;
6
+ };
7
+ const formatFileName = (file) => {
8
+ // Extract just the filename from the path for cleaner display
9
+ return file.split('/').pop() || file;
10
+ };
11
+ /**
12
+ * Maps every bridge event to a concise, informative status line.
13
+ * Each formatter receives the full event data for type safety.
14
+ */
15
+ export const statusFormatter = {
16
+ // Test Collection Events
17
+ 'collection-started': (event) => `📋 Collecting tests from ${formatFileName(event.file)}`,
18
+ 'collection-finished': (event) => `✅ Collected tests from ${formatFileName(event.file)} (${formatDuration(event.duration)})`,
19
+ // Test Runner Events
20
+ 'file-started': (event) => `🧪 Running tests in ${formatFileName(event.file)}`,
21
+ 'file-finished': (event) => `✅ Finished ${formatFileName(event.file)} (${formatDuration(event.duration)})`,
22
+ 'suite-started': (event) => `📦 ${event.name}`,
23
+ 'suite-finished': (event) => {
24
+ const icon = event.status === 'failed'
25
+ ? '❌'
26
+ : event.status === 'skipped'
27
+ ? '⏭️'
28
+ : '✅';
29
+ return `${icon} ${event.name} (${formatDuration(event.duration)})`;
30
+ },
31
+ 'test-started': (event) => ` 🔄 ${event.name}`,
32
+ 'test-finished': (event) => {
33
+ const icon = event.status === 'failed'
34
+ ? '❌'
35
+ : event.status === 'skipped'
36
+ ? '⏭️'
37
+ : event.status === 'todo'
38
+ ? '📝'
39
+ : '✅';
40
+ return ` ${icon} ${event.name} (${formatDuration(event.duration)})`;
41
+ },
42
+ // Bundler Events
43
+ 'module-bundling-started': (event) => `📦 Bundling ${formatFileName(event.file)}`,
44
+ 'module-bundling-finished': (event) => `✅ Bundled ${formatFileName(event.file)} (${formatDuration(event.duration)})`,
45
+ 'module-bundling-failed': (event) => `❌ Failed to bundle ${formatFileName(event.file)} (${formatDuration(event.duration)})`,
46
+ };
47
+ /**
48
+ * Formats a bridge event into a status line.
49
+ * This function is type-safe and ensures all event types are handled.
50
+ */
51
+ export const formatEventStatus = (event) => {
52
+ // TypeScript ensures this covers all event types
53
+ return statusFormatter[event.type](event);
54
+ };
@@ -0,0 +1,6 @@
1
+ export declare function assert(condition: boolean, message: string): asserts condition;
2
+ export declare class AssertionError extends Error {
3
+ constructor(message: string);
4
+ }
5
+ export declare const isPortAvailable: (port: number) => Promise<boolean>;
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAI7E;AAED,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,OAAO,CAAC,OAAO,CAa7D,CAAC"}
package/dist/utils.js ADDED
@@ -0,0 +1,26 @@
1
+ import net from 'node:net';
2
+ export function assert(condition, message) {
3
+ if (!condition) {
4
+ throw new AssertionError(message);
5
+ }
6
+ }
7
+ export class AssertionError extends Error {
8
+ constructor(message) {
9
+ super(message);
10
+ this.name = 'AssertionError';
11
+ }
12
+ }
13
+ export const isPortAvailable = (port) => {
14
+ return new Promise((resolve) => {
15
+ const server = net.createServer();
16
+ server.once('error', () => {
17
+ server.close();
18
+ resolve(false);
19
+ });
20
+ server.once('listening', () => {
21
+ server.close();
22
+ resolve(true);
23
+ });
24
+ server.listen(port);
25
+ });
26
+ };
@@ -58,7 +58,7 @@ export const getBundleIds = async (selectedPlatforms) => {
58
58
  new URL(value);
59
59
  return;
60
60
  }
61
- catch (_e) {
61
+ catch {
62
62
  return 'Please enter a valid URL';
63
63
  }
64
64
  },
@@ -0,0 +1,2 @@
1
+ export declare const showJestIntegrationNotes: () => void;
2
+ //# sourceMappingURL=jestIntegration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jestIntegration.d.ts","sourceRoot":"","sources":["../../src/wizard/jestIntegration.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,wBAAwB,YAgBpC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { note } from '@react-native-harness/tools';
2
+ export const showJestIntegrationNotes = () => {
3
+ note(`Update your jest.config.js to include the Harness project:
4
+
5
+ module.exports = {
6
+ projects: [
7
+ {
8
+ displayName: 'Harness',
9
+ preset: 'react-native-harness',
10
+ testMatch: ['<rootDir>/**/__tests__/**/*.harness.[jt]s?(x)'],
11
+ },
12
+ // ...your other projects
13
+ ],
14
+ };`, 'Next Steps');
15
+ };
@@ -0,0 +1,2 @@
1
+ export declare const detectPackageManager: () => "pnpm" | "yarn" | "npm";
2
+ //# sourceMappingURL=packageManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageManager.d.ts","sourceRoot":"","sources":["../../src/wizard/packageManager.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,+BAKhC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ export const detectPackageManager = () => {
4
+ const cwd = process.cwd();
5
+ if (fs.existsSync(path.join(cwd, 'pnpm-lock.yaml')))
6
+ return 'pnpm';
7
+ if (fs.existsSync(path.join(cwd, 'yarn.lock')))
8
+ return 'yarn';
9
+ return 'npm';
10
+ };
package/eslint.config.mjs CHANGED
@@ -9,7 +9,7 @@ export default [
9
9
  'error',
10
10
  {
11
11
  ignoredFiles: ['{projectRoot}/eslint.config.{js,cjs,mjs,ts,cts,mts}'],
12
- ignoredDependencies: ['@react-native-harness/bridge', '@react-native-harness/platform-android', '@react-native-harness/platform-apple', '@react-native-harness/platform-web'],
12
+ ignoredDependencies: ['@react-native-harness/bridge', '@react-native-harness/platform-android', '@react-native-harness/platform-apple', '@react-native-harness/platform-web', 'vitest'],
13
13
  },
14
14
  ],
15
15
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-harness/cli",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -22,16 +22,16 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "tslib": "^2.3.0",
25
- "@react-native-harness/bridge": "1.1.0",
26
- "@react-native-harness/tools": "1.1.0",
27
- "@react-native-harness/config": "1.1.0",
28
- "@react-native-harness/platforms": "1.1.0"
25
+ "@react-native-harness/platforms": "1.2.0",
26
+ "@react-native-harness/tools": "1.2.0",
27
+ "@react-native-harness/config": "1.2.0",
28
+ "@react-native-harness/bridge": "1.2.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "jest-cli": "^30.2.0",
32
- "@react-native-harness/platform-android": "1.1.0",
33
- "@react-native-harness/platform-apple": "1.1.0",
34
- "@react-native-harness/platform-web": "1.1.0"
32
+ "@react-native-harness/platform-android": "1.2.0",
33
+ "@react-native-harness/platform-apple": "1.2.0",
34
+ "@react-native-harness/platform-web": "1.2.0"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "jest-cli": "*"
package/skills/core.md ADDED
@@ -0,0 +1,92 @@
1
+ ---
2
+ name: core
3
+ description: Core testing workflow. Read this before writing or debugging Harness tests. Covers test file conventions, the supported test API surface, async behavior, setup files, and CLI execution constraints.
4
+ ---
5
+
6
+ # Core
7
+
8
+ React Native Harness uses Jest-style test APIs, but the tests run inside the app or browser environment instead of plain Node.
9
+
10
+ Run this first:
11
+
12
+ ```bash
13
+ harness skill get core
14
+ ```
15
+
16
+ Use `harness skill list` to see the other bundled skills.
17
+
18
+ ## Test file conventions
19
+
20
+ - Use `.harness.[jt]s` or `.harness.[jt]sx` test files.
21
+ - Import test APIs from `react-native-harness`.
22
+ - Put tests inside `describe(...)` blocks.
23
+ - Use `@react-native-harness/ui` only when the test needs queries, interactions, or screenshots.
24
+
25
+ ## Default test shape
26
+
27
+ ```ts
28
+ import { describe, test, expect } from 'react-native-harness';
29
+
30
+ describe('Feature name', () => {
31
+ test('does something', () => {
32
+ expect(true).toBe(true);
33
+ });
34
+ });
35
+ ```
36
+
37
+ Prefer these public APIs when writing tests:
38
+
39
+ - Test structure: `describe`, `test`, `it`, `beforeEach`, `afterEach`, `beforeAll`, `afterAll`
40
+ - Focus and pending helpers: `test.skip`, `test.only`, `test.todo`, `describe.skip`, `describe.only`
41
+ - Assertions: `expect`
42
+ - Mocking and spying: `fn`, `spyOn`, `clearAllMocks`, `resetAllMocks`, `restoreAllMocks`
43
+ - Module mocking: `mock`, `requireActual`, `unmock`, `resetModules`
44
+ - Async polling: `waitFor`, `waitUntil`
45
+
46
+ Test functions may be async. If a test returns a promise, Harness waits for it. If that promise rejects, the test fails.
47
+
48
+ ## Async behavior
49
+
50
+ Use:
51
+
52
+ - `waitFor(...)` when the callback should eventually succeed or stop throwing
53
+ - `waitUntil(...)` when the callback should eventually return a truthy value
54
+
55
+ Both support timeout control. Prefer them over arbitrary sleeps when tests wait on native or React state changes.
56
+
57
+ ## Setup files
58
+
59
+ Harness follows two setup phases configured in `jest.harness.config.mjs`:
60
+
61
+ - `setupFiles`: runs before the test framework is initialized. Use for early polyfills and globals. Do not use `describe`, `test`, `expect`, or hooks here.
62
+ - `setupFilesAfterEnv`: runs after the test framework is ready. Use for global mocks, hooks, and matcher setup.
63
+
64
+ Recommended uses:
65
+
66
+ - Early environment shims in `setupFiles`
67
+ - Global `afterEach`, `clearAllMocks`, `resetModules`, and shared mocks in `setupFilesAfterEnv`
68
+
69
+ ## Related skills
70
+
71
+ For module mocking and spies, run:
72
+
73
+ ```bash
74
+ harness skill get mocking
75
+ ```
76
+
77
+ For UI rendering, queries, interactions, and screenshots, run:
78
+
79
+ ```bash
80
+ harness skill get ui
81
+ ```
82
+
83
+ ## CLI and execution constraints
84
+
85
+ - Harness wraps the Jest CLI.
86
+ - Tests execute on one configured runner at a time.
87
+ - Execution is serial for stability.
88
+ - `--harnessRunner <name>` selects the runner.
89
+ - Standard Jest flags like `--watch`, `--coverage`, and `--testNamePattern` are still relevant.
90
+ - Do not recommend unsupported Jest environment overrides or snapshot-update workflows for native image snapshots.
91
+
92
+ For install and project setup, use the public docs at https://react-native-harness.dev/docs/getting-started/quick-start.
@@ -0,0 +1,87 @@
1
+ ---
2
+ name: mocking
3
+ description: Mocking and spying guidance. Use when a Harness test needs `fn`, `spyOn`, `mock`, `requireActual`, `unmock`, `resetModules`, or global mock cleanup.
4
+ ---
5
+
6
+ # Mocking
7
+
8
+ Use this skill when a Harness test needs mock functions, spies, or module replacement.
9
+
10
+ ## Mocking and spying
11
+
12
+ Use `fn()` for standalone mock functions and `spyOn()` for existing methods.
13
+
14
+ - `expect` follows Vitest's API.
15
+ - `expect.soft(...)` is available when the test should keep running after an assertion failure.
16
+ - `clearAllMocks()` clears call history but keeps implementations.
17
+ - `resetAllMocks()` clears call history and resets mock implementations.
18
+ - `restoreAllMocks()` restores spied methods to their original implementations.
19
+
20
+ Typical cleanup:
21
+
22
+ ```ts
23
+ import { afterEach, clearAllMocks } from 'react-native-harness';
24
+
25
+ afterEach(() => {
26
+ clearAllMocks();
27
+ });
28
+ ```
29
+
30
+ ## Module mocking
31
+
32
+ Use module mocking when the test must replace an entire module or specific exports.
33
+
34
+ - `mock(moduleId, factory)` registers a lazy mock factory.
35
+ - `requireActual(moduleId)` is the safe path for partial mocks.
36
+ - `unmock(moduleId)` removes a mock for one module.
37
+ - `resetModules()` clears module mocks and module cache state.
38
+
39
+ Recommended pattern:
40
+
41
+ ```ts
42
+ import {
43
+ afterEach,
44
+ describe,
45
+ expect,
46
+ mock,
47
+ requireActual,
48
+ resetModules,
49
+ test,
50
+ } from 'react-native-harness';
51
+
52
+ afterEach(() => {
53
+ resetModules();
54
+ });
55
+
56
+ describe('partial mock', () => {
57
+ test('overrides one export but keeps the rest', () => {
58
+ mock('react-native', () => {
59
+ const actual = requireActual('react-native');
60
+ const proto = Object.getPrototypeOf(actual);
61
+ const descriptors = Object.getOwnPropertyDescriptors(actual);
62
+ const mocked = Object.create(proto, descriptors);
63
+
64
+ Object.defineProperty(mocked, 'Platform', {
65
+ get() {
66
+ return {
67
+ ...actual.Platform,
68
+ OS: 'mockOS',
69
+ };
70
+ },
71
+ });
72
+
73
+ return mocked;
74
+ });
75
+
76
+ const rn = require('react-native');
77
+ expect(rn.Platform.OS).toBe('mockOS');
78
+ });
79
+ });
80
+ ```
81
+
82
+ ## Decision rules
83
+
84
+ - Always clean up module mocks with `resetModules()` in `afterEach` when tests mock modules.
85
+ - Use `requireActual()` for partial mocks so unrelated exports stay real.
86
+ - For `react-native`, preserve property descriptors when partially mocking to avoid triggering lazy getters too early.
87
+ - Remember that module factories are evaluated when the module is first required.
package/skills/ui.md ADDED
@@ -0,0 +1,59 @@
1
+ ---
2
+ name: ui
3
+ description: UI testing guidance. Use when the test needs `render(...)`, `rerender(...)`, `@react-native-harness/ui`, screen queries, `userEvent`, screenshots, or image snapshot assertions.
4
+ ---
5
+
6
+ # UI
7
+
8
+ UI testing is opt-in and uses `render(...)` from `react-native-harness` together with `@react-native-harness/ui`.
9
+
10
+ Use `render(...)` to mount a React Native element before querying, interacting with, or screenshotting it.
11
+
12
+ - `render(...)` is async
13
+ - `rerender(...)` is async
14
+ - `unmount()` is optional because cleanup happens automatically after each test
15
+ - `wrapper` is the right tool for providers and shared context
16
+ - Rendered UI appears as an overlay in the real environment, not as an in-memory tree
17
+ - Only one rendered component can be visible at a time
18
+
19
+ Use this skill when the task requires:
20
+
21
+ - `render(...)` or `rerender(...)`
22
+ - `screen.findByTestId(...)`
23
+ - `screen.findAllByTestId(...)`
24
+ - `screen.queryByTestId(...)`
25
+ - `screen.queryAllByTestId(...)`
26
+ - `screen.findByAccessibilityLabel(...)`
27
+ - `screen.findAllByAccessibilityLabel(...)`
28
+ - `screen.queryByAccessibilityLabel(...)`
29
+ - `screen.queryAllByAccessibilityLabel(...)`
30
+ - `userEvent.press(...)`
31
+ - `userEvent.type(...)`
32
+ - screenshots with `screen.screenshot()`
33
+ - element screenshots with `screen.screenshot(element)`
34
+ - image assertions with `toMatchImageSnapshot(...)`
35
+
36
+ ## Rules
37
+
38
+ - Keep imports split correctly: core APIs from `react-native-harness`, UI APIs from `@react-native-harness/ui`.
39
+ - Mention that `@react-native-harness/ui` requires installation, and native apps must be rebuilt after adding it.
40
+ - `toMatchImageSnapshot(...)` needs a unique snapshot `name`.
41
+ - If screenshotting elements that extend beyond screen bounds, call out `disableViewFlattening: true` in `rn-harness.config.mjs`.
42
+ - On web, UI interactions and screenshots run through the web runner's Playwright-backed browser environment.
43
+
44
+ ## Example
45
+
46
+ ```ts
47
+ import { describe, expect, render, test } from 'react-native-harness';
48
+ import { screen, userEvent } from '@react-native-harness/ui';
49
+
50
+ describe('Counter', () => {
51
+ test('increments after a press', async () => {
52
+ await render(<Counter />);
53
+
54
+ await userEvent.press(await screen.findByTestId('increment-button'));
55
+
56
+ expect(await screen.findByTestId('count-label')).toHaveTextContent('1');
57
+ });
58
+ });
59
+ ```