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

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 (68) hide show
  1. package/dist/__tests__/harness-cache.test.d.ts +2 -0
  2. package/dist/__tests__/harness-cache.test.d.ts.map +1 -0
  3. package/dist/__tests__/harness-cache.test.js +51 -0
  4. package/dist/__tests__/harness.test.js +340 -47
  5. package/dist/__tests__/index.test.d.ts +2 -0
  6. package/dist/__tests__/index.test.d.ts.map +1 -0
  7. package/dist/__tests__/index.test.js +42 -0
  8. package/dist/cli-args.d.ts +1 -0
  9. package/dist/cli-args.d.ts.map +1 -1
  10. package/dist/cli-args.js +5 -0
  11. package/dist/crash-supervisor.d.ts.map +1 -1
  12. package/dist/crash-supervisor.js +7 -6
  13. package/dist/errors.d.ts +1 -0
  14. package/dist/errors.d.ts.map +1 -1
  15. package/dist/errors.js +1 -0
  16. package/dist/harness.d.ts +23 -1
  17. package/dist/harness.d.ts.map +1 -1
  18. package/dist/harness.js +396 -50
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +205 -58
  21. package/dist/logs.d.ts +1 -0
  22. package/dist/logs.d.ts.map +1 -1
  23. package/dist/logs.js +3 -0
  24. package/dist/run.d.ts +7 -1
  25. package/dist/run.d.ts.map +1 -1
  26. package/dist/run.js +13 -8
  27. package/dist/setup.d.ts.map +1 -1
  28. package/dist/setup.js +18 -2
  29. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  30. package/package.json +7 -6
  31. package/src/__tests__/harness-cache.test.ts +74 -0
  32. package/src/__tests__/harness.test.ts +469 -51
  33. package/src/__tests__/index.test.ts +61 -0
  34. package/src/cli-args.ts +6 -0
  35. package/src/crash-supervisor.ts +13 -6
  36. package/src/env.d.ts +1 -1
  37. package/src/errors.ts +5 -0
  38. package/src/harness.ts +504 -58
  39. package/src/index.ts +276 -64
  40. package/src/logs.ts +4 -0
  41. package/src/run.ts +20 -10
  42. package/src/setup.ts +22 -1
  43. package/tsconfig.json +3 -3
  44. package/tsconfig.lib.json +6 -6
  45. package/dist/cli-args.test.d.ts +0 -2
  46. package/dist/cli-args.test.d.ts.map +0 -1
  47. package/dist/cli-args.test.js +0 -1
  48. package/dist/crash-monitor.d.ts +0 -16
  49. package/dist/crash-monitor.d.ts.map +0 -1
  50. package/dist/crash-monitor.js +0 -75
  51. package/dist/event-mapper.d.ts +0 -16
  52. package/dist/event-mapper.d.ts.map +0 -1
  53. package/dist/event-mapper.js +0 -120
  54. package/dist/global-setup.d.ts +0 -3
  55. package/dist/global-setup.d.ts.map +0 -1
  56. package/dist/global-setup.js +0 -60
  57. package/dist/global-teardown.d.ts +0 -3
  58. package/dist/global-teardown.d.ts.map +0 -1
  59. package/dist/global-teardown.js +0 -11
  60. package/dist/harness-reporter.d.ts +0 -8
  61. package/dist/harness-reporter.d.ts.map +0 -1
  62. package/dist/harness-reporter.js +0 -12
  63. package/dist/jest-options.d.ts +0 -2
  64. package/dist/jest-options.d.ts.map +0 -1
  65. package/dist/jest-options.js +0 -1
  66. package/dist/types.d.ts +0 -17
  67. package/dist/types.d.ts.map +0 -1
  68. package/dist/types.js +0 -1
@@ -0,0 +1,61 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import type { Harness } from '../harness.js';
3
+ import type { Config as HarnessConfig } from '@react-native-harness/config';
4
+ import type { Config, Test, TestWatcher } from 'jest-runner';
5
+ import JestHarness from '../index.js';
6
+ import { StartupStallError } from '../errors.js';
7
+
8
+ describe('JestHarness', () => {
9
+ it('reports StartupStallError without a stack trace', async () => {
10
+ const runner = new JestHarness({} as Config.GlobalConfig);
11
+ const onFailure = vi.fn();
12
+
13
+ const harness = {
14
+ ensureAppReady: vi
15
+ .fn()
16
+ .mockRejectedValue(new StartupStallError(1500, 3)),
17
+ callHook: vi.fn(async () => undefined),
18
+ setRunState: vi.fn(),
19
+ getRunState: vi.fn(() => null),
20
+ crashSupervisor: {
21
+ beginTestRun: vi.fn(),
22
+ waitForCrash: vi.fn(),
23
+ cancelCrashWaiters: vi.fn(),
24
+ reset: vi.fn(),
25
+ },
26
+ } as unknown as Harness;
27
+
28
+ await runner._createInBandTestRun(
29
+ [
30
+ {
31
+ path: '/tmp/example.harness.ts',
32
+ context: {
33
+ config: {},
34
+ },
35
+ } as Test,
36
+ ],
37
+ {
38
+ isInterrupted: () => false,
39
+ } as TestWatcher,
40
+ harness,
41
+ {
42
+ detectNativeCrashes: true,
43
+ resetEnvironmentBetweenTestFiles: false,
44
+ } as HarnessConfig,
45
+ () => Promise.resolve(),
46
+ () => Promise.resolve(),
47
+ onFailure
48
+ );
49
+
50
+ expect(onFailure).toHaveBeenCalledWith(
51
+ expect.objectContaining({
52
+ path: '/tmp/example.harness.ts',
53
+ }),
54
+ {
55
+ message:
56
+ 'The app did not request its Metro bundle after 3 launch attempts within 1500ms. Last Metro status: unknown.',
57
+ stack: '',
58
+ }
59
+ );
60
+ });
61
+ });
package/src/cli-args.ts CHANGED
@@ -3,6 +3,7 @@ import { hideBin } from 'yargs/helpers';
3
3
 
4
4
  export type HarnessCliArgs = {
5
5
  harnessRunner?: string;
6
+ metroPort?: number;
6
7
  };
7
8
 
8
9
  export const getAdditionalCliArgs = (): HarnessCliArgs => {
@@ -11,6 +12,10 @@ export const getAdditionalCliArgs = (): HarnessCliArgs => {
11
12
  type: 'string',
12
13
  description: 'Specify which Harness runner to use',
13
14
  })
15
+ .option('metroPort', {
16
+ type: 'number',
17
+ description: 'Override the Metro bundler port',
18
+ })
14
19
  .strict(false)
15
20
  .help(false)
16
21
  .version(false)
@@ -19,5 +24,6 @@ export const getAdditionalCliArgs = (): HarnessCliArgs => {
19
24
 
20
25
  return {
21
26
  harnessRunner: argv.harnessRunner,
27
+ metroPort: argv.metroPort,
22
28
  };
23
29
  };
@@ -12,6 +12,8 @@ import {
12
12
  } from './errors.js';
13
13
  import { logger } from '@react-native-harness/tools';
14
14
 
15
+ const crashLogger = logger.child('crash');
16
+
15
17
  export type CrashSupervisorState =
16
18
  | 'idle'
17
19
  | 'launching'
@@ -113,15 +115,20 @@ export const createCrashSupervisor = ({
113
115
  }
114
116
 
115
117
  if (!activeTestFilePath) {
116
- logger.debug(`Ignoring crash signal without active test: ${reason}`);
118
+ crashLogger.debug('ignoring crash signal without active test: %s', reason);
117
119
  return;
118
120
  }
119
121
 
120
122
  isResolvingCrash = true;
121
- logger.debug(`Native crash detected during ${activeTestFilePath} (state: ${state}, reason: ${reason || '(none)'})`);
123
+ crashLogger.debug(
124
+ 'native crash detected during %s (state=%s reason=%s)',
125
+ activeTestFilePath,
126
+ state,
127
+ reason || '(none)'
128
+ );
122
129
 
123
130
  for (const line of details?.rawLines ?? []) {
124
- logger.debug(line);
131
+ crashLogger.debug('%s', line);
125
132
  }
126
133
 
127
134
  const phase = getCrashPhase(state);
@@ -136,7 +143,7 @@ export const createCrashSupervisor = ({
136
143
  });
137
144
 
138
145
  const mergedDetails = mergeCrashDetails(phase, details, enrichedDetails, reason);
139
- logger.debug('Crash details:', {
146
+ crashLogger.debug('crash details: %o', {
140
147
  phase: mergedDetails.phase,
141
148
  source: mergedDetails.source,
142
149
  summary: mergedDetails.summary,
@@ -160,10 +167,10 @@ export const createCrashSupervisor = ({
160
167
  const isRunning = await platformRunner.isAppRunning();
161
168
 
162
169
  if (!isRunning) {
163
- handleCrash(reason, details);
170
+ void handleCrash(reason, details);
164
171
  }
165
172
  } catch (error) {
166
- logger.debug('Crash confirmation failed', error);
173
+ crashLogger.debug('crash confirmation failed', error);
167
174
  }
168
175
  };
169
176
 
package/src/env.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Harness } from '@react-native-harness/cli/external';
1
+ import type { Harness } from './harness.js';
2
2
  import type { Config as HarnessConfig } from '@react-native-harness/config';
3
3
 
4
4
  declare global {
package/src/errors.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { HarnessError } from '@react-native-harness/tools';
2
2
  import type { AppCrashDetails } from '@react-native-harness/platforms';
3
+ export {
4
+ StartupStallError,
5
+ type StartupStallCode,
6
+ type StartupStallDetails,
7
+ } from '@react-native-harness/bundler-metro';
3
8
 
4
9
  export class NoRunnerSpecifiedError extends HarnessError {
5
10
  constructor() {