@react-native-harness/jest 1.1.0-rc.1 → 1.1.0-rc.3

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 (58) hide show
  1. package/dist/__tests__/errors.test.js +6 -1
  2. package/dist/__tests__/harness-cache.test.d.ts +2 -0
  3. package/dist/__tests__/harness-cache.test.d.ts.map +1 -0
  4. package/dist/__tests__/harness-cache.test.js +51 -0
  5. package/dist/__tests__/harness.test.js +484 -47
  6. package/dist/__tests__/index.test.d.ts +2 -0
  7. package/dist/__tests__/index.test.d.ts.map +1 -0
  8. package/dist/__tests__/index.test.js +42 -0
  9. package/dist/__tests__/resource-lock.test.d.ts +2 -0
  10. package/dist/__tests__/resource-lock.test.d.ts.map +1 -0
  11. package/dist/__tests__/resource-lock.test.js +103 -0
  12. package/dist/action-hooks.d.ts +9 -0
  13. package/dist/action-hooks.d.ts.map +1 -0
  14. package/dist/action-hooks.js +36 -0
  15. package/dist/cli-args.d.ts +1 -0
  16. package/dist/cli-args.d.ts.map +1 -1
  17. package/dist/cli-args.js +5 -0
  18. package/dist/crash-supervisor.d.ts.map +1 -1
  19. package/dist/crash-supervisor.js +7 -6
  20. package/dist/errors.d.ts +5 -0
  21. package/dist/errors.d.ts.map +1 -1
  22. package/dist/errors.js +10 -2
  23. package/dist/harness.d.ts +23 -1
  24. package/dist/harness.d.ts.map +1 -1
  25. package/dist/harness.js +574 -136
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +205 -58
  28. package/dist/logs.d.ts +4 -0
  29. package/dist/logs.d.ts.map +1 -1
  30. package/dist/logs.js +12 -0
  31. package/dist/resource-lock.d.ts +25 -0
  32. package/dist/resource-lock.d.ts.map +1 -0
  33. package/dist/resource-lock.js +278 -0
  34. package/dist/run.d.ts +7 -1
  35. package/dist/run.d.ts.map +1 -1
  36. package/dist/run.js +13 -8
  37. package/dist/setup.d.ts.map +1 -1
  38. package/dist/setup.js +29 -2
  39. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  40. package/package.json +7 -6
  41. package/src/__tests__/errors.test.ts +18 -6
  42. package/src/__tests__/harness-cache.test.ts +74 -0
  43. package/src/__tests__/harness.test.ts +702 -49
  44. package/src/__tests__/index.test.ts +61 -0
  45. package/src/__tests__/resource-lock.test.ts +138 -0
  46. package/src/action-hooks.ts +66 -0
  47. package/src/cli-args.ts +6 -0
  48. package/src/crash-supervisor.ts +13 -6
  49. package/src/env.d.ts +1 -1
  50. package/src/errors.ts +15 -4
  51. package/src/harness.ts +743 -157
  52. package/src/index.ts +276 -64
  53. package/src/logs.ts +17 -3
  54. package/src/resource-lock.ts +450 -0
  55. package/src/run.ts +20 -10
  56. package/src/setup.ts +42 -1
  57. package/tsconfig.json +3 -3
  58. package/tsconfig.lib.json +6 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-native-harness/jest",
3
- "version": "1.1.0-rc.1",
3
+ "version": "1.1.0-rc.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -40,11 +40,12 @@
40
40
  "p-limit": "^7.1.1",
41
41
  "tslib": "^2.3.0",
42
42
  "yargs": "^17.7.2",
43
- "@react-native-harness/bridge": "1.1.0-rc.1",
44
- "@react-native-harness/bundler-metro": "1.1.0-rc.1",
45
- "@react-native-harness/config": "1.1.0-rc.1",
46
- "@react-native-harness/platforms": "1.1.0-rc.1",
47
- "@react-native-harness/tools": "1.1.0-rc.1"
43
+ "@react-native-harness/bridge": "1.1.0-rc.3",
44
+ "@react-native-harness/config": "1.1.0-rc.3",
45
+ "@react-native-harness/bundler-metro": "1.1.0-rc.3",
46
+ "@react-native-harness/platforms": "1.1.0-rc.3",
47
+ "@react-native-harness/tools": "1.1.0-rc.3",
48
+ "@react-native-harness/plugins": "1.1.0-rc.3"
48
49
  },
49
50
  "devDependencies": {
50
51
  "@types/yargs": "^17.0.32",
@@ -1,5 +1,13 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { NativeCrashError } from '../errors.js';
2
+ import { NativeCrashError, PlatformReadyTimeoutError } from '../errors.js';
3
+
4
+ describe('PlatformReadyTimeoutError', () => {
5
+ it('includes the configured timeout and config hint', () => {
6
+ expect(new PlatformReadyTimeoutError(300000).message).toBe(
7
+ 'The platform did not become ready within 300000ms. Increase "platformReadyTimeout" if your device, simulator, or emulator needs more time to start.'
8
+ );
9
+ });
10
+ });
3
11
 
4
12
  describe('NativeCrashError', () => {
5
13
  it('formats the extracted stack trace in the error message', () => {
@@ -35,7 +43,9 @@ describe('NativeCrashError', () => {
35
43
  exceptionType: 'EXC_CRASH',
36
44
  });
37
45
 
38
- expect(error.message).not.toContain('notify_get_state check indicated test daemon not ready');
46
+ expect(error.message).not.toContain(
47
+ 'notify_get_state check indicated test daemon not ready'
48
+ );
39
49
  expect(error.message).toContain('Signal: SIGABRT');
40
50
  expect(error.message).toContain('Exception: EXC_CRASH');
41
51
  expect(error.message).toContain('Process: HarnessPlayground (pid 18007)');
@@ -54,9 +64,9 @@ describe('NativeCrashError', () => {
54
64
  stackTrace: [frame],
55
65
  });
56
66
 
57
- expect(error.message.match(/MainActivity\.onCreate\(MainActivity\.kt:38\)/g)).toHaveLength(
58
- 1
59
- );
67
+ expect(
68
+ error.message.match(/MainActivity\.onCreate\(MainActivity\.kt:38\)/g)
69
+ ).toHaveLength(1);
60
70
  });
61
71
 
62
72
  it('collapses the native crash stack header so jest does not reprint multiline messages', () => {
@@ -65,6 +75,8 @@ describe('NativeCrashError', () => {
65
75
  summary: ['line one', 'line two'].join('\n'),
66
76
  });
67
77
 
68
- expect(error.stack).toBe('NativeCrashError: The native app crashed while preparing to run this test file.');
78
+ expect(error.stack).toBe(
79
+ 'NativeCrashError: The native app crashed while preparing to run this test file.'
80
+ );
69
81
  });
70
82
  });
@@ -0,0 +1,74 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import type { Config as HarnessConfig } from '@react-native-harness/config';
3
+ import type { HarnessPlatform } from '@react-native-harness/platforms';
4
+
5
+ const mocks = vi.hoisted(() => ({
6
+ isMetroCacheReusable: vi.fn(),
7
+ logMetroCacheReused: vi.fn(),
8
+ logMetroPrewarmCompleted: vi.fn(),
9
+ }));
10
+
11
+ vi.mock('@react-native-harness/bundler-metro', () => ({
12
+ isMetroCacheReusable: mocks.isMetroCacheReusable,
13
+ }));
14
+
15
+ vi.mock('../logs.js', () => ({
16
+ logMetroCacheReused: mocks.logMetroCacheReused,
17
+ logMetroPrewarmCompleted: mocks.logMetroPrewarmCompleted,
18
+ }));
19
+
20
+ import { maybeLogMetroCacheReuse } from '../harness.js';
21
+
22
+ const platform: HarnessPlatform = {
23
+ name: 'ios',
24
+ platformId: 'ios',
25
+ runner: '/virtual/platform-runner.js',
26
+ config: {},
27
+ getResourceLockKey: () => 'ios:simulator:iPhone 17 Pro:26.2',
28
+ };
29
+
30
+ const createHarnessConfig = (
31
+ overrides: Partial<HarnessConfig> = {}
32
+ ): HarnessConfig =>
33
+ ({
34
+ appRegistryComponentName: 'App',
35
+ disableViewFlattening: false,
36
+ bridgeTimeout: 5000,
37
+ entryPoint: 'index.js',
38
+ unstable__enableMetroCache: true,
39
+ forwardClientLogs: false,
40
+ ...overrides,
41
+ } as HarnessConfig);
42
+
43
+ describe('maybeLogMetroCacheReuse', () => {
44
+ beforeEach(() => {
45
+ vi.clearAllMocks();
46
+ mocks.isMetroCacheReusable.mockReturnValue(false);
47
+ });
48
+
49
+ it('logs when an existing metro cache will be reused', () => {
50
+ mocks.isMetroCacheReusable.mockReturnValue(true);
51
+
52
+ maybeLogMetroCacheReuse(createHarnessConfig(), platform, '/tmp/project');
53
+
54
+ expect(mocks.isMetroCacheReusable).toHaveBeenCalledWith('/tmp/project');
55
+ expect(mocks.logMetroCacheReused).toHaveBeenCalledWith(platform);
56
+ });
57
+
58
+ it('does not log when metro cache reuse is disabled', () => {
59
+ maybeLogMetroCacheReuse(
60
+ createHarnessConfig({ unstable__enableMetroCache: false }),
61
+ platform,
62
+ '/tmp/project'
63
+ );
64
+
65
+ expect(mocks.isMetroCacheReusable).not.toHaveBeenCalled();
66
+ expect(mocks.logMetroCacheReused).not.toHaveBeenCalled();
67
+ });
68
+
69
+ it('does not log when the metro cache is absent', () => {
70
+ maybeLogMetroCacheReuse(createHarnessConfig(), platform, '/tmp/project');
71
+
72
+ expect(mocks.logMetroCacheReused).not.toHaveBeenCalled();
73
+ });
74
+ });