@react-native-harness/jest 1.1.0-rc.2 → 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.js +1 -1
  3. package/dist/__tests__/harness.test.js +147 -3
  4. package/dist/__tests__/resource-lock.test.d.ts +2 -0
  5. package/dist/__tests__/resource-lock.test.d.ts.map +1 -0
  6. package/dist/__tests__/resource-lock.test.js +103 -0
  7. package/dist/action-hooks.d.ts +9 -0
  8. package/dist/action-hooks.d.ts.map +1 -0
  9. package/dist/action-hooks.js +36 -0
  10. package/dist/cli-args.test.d.ts +2 -0
  11. package/dist/cli-args.test.d.ts.map +1 -0
  12. package/dist/cli-args.test.js +1 -0
  13. package/dist/crash-monitor.d.ts +16 -0
  14. package/dist/crash-monitor.d.ts.map +1 -0
  15. package/dist/crash-monitor.js +75 -0
  16. package/dist/errors.d.ts +4 -0
  17. package/dist/errors.d.ts.map +1 -1
  18. package/dist/errors.js +9 -2
  19. package/dist/event-mapper.d.ts +16 -0
  20. package/dist/event-mapper.d.ts.map +1 -0
  21. package/dist/event-mapper.js +120 -0
  22. package/dist/global-setup.d.ts +3 -0
  23. package/dist/global-setup.d.ts.map +1 -0
  24. package/dist/global-setup.js +60 -0
  25. package/dist/global-teardown.d.ts +3 -0
  26. package/dist/global-teardown.d.ts.map +1 -0
  27. package/dist/global-teardown.js +11 -0
  28. package/dist/harness-reporter.d.ts +8 -0
  29. package/dist/harness-reporter.d.ts.map +1 -0
  30. package/dist/harness-reporter.js +12 -0
  31. package/dist/harness.d.ts.map +1 -1
  32. package/dist/harness.js +478 -386
  33. package/dist/jest-options.d.ts +2 -0
  34. package/dist/jest-options.d.ts.map +1 -0
  35. package/dist/jest-options.js +1 -0
  36. package/dist/logs.d.ts +3 -0
  37. package/dist/logs.d.ts.map +1 -1
  38. package/dist/logs.js +9 -0
  39. package/dist/resource-lock.d.ts +25 -0
  40. package/dist/resource-lock.d.ts.map +1 -0
  41. package/dist/resource-lock.js +278 -0
  42. package/dist/setup.d.ts.map +1 -1
  43. package/dist/setup.js +11 -0
  44. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  45. package/dist/types.d.ts +17 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/dist/types.js +1 -0
  48. package/package.json +7 -7
  49. package/src/__tests__/errors.test.ts +18 -6
  50. package/src/__tests__/harness-cache.test.ts +2 -2
  51. package/src/__tests__/harness.test.ts +254 -19
  52. package/src/__tests__/resource-lock.test.ts +138 -0
  53. package/src/action-hooks.ts +66 -0
  54. package/src/errors.ts +10 -4
  55. package/src/harness.ts +585 -445
  56. package/src/logs.ts +13 -3
  57. package/src/resource-lock.ts +450 -0
  58. package/src/setup.ts +21 -1
@@ -0,0 +1,66 @@
1
+ import {
2
+ definePlugin,
3
+ type HarnessPlugin,
4
+ } from '@react-native-harness/plugins';
5
+ import type { Config as HarnessConfig } from '@react-native-harness/config';
6
+ import type { HarnessPlatform } from '@react-native-harness/platforms';
7
+ import { spawn } from '@react-native-harness/tools';
8
+
9
+ type ActionHookState = {
10
+ _unused?: never;
11
+ };
12
+
13
+ const getInlineHookScript = (
14
+ name: 'PRE_RUN_HOOK' | 'AFTER_RUN_HOOK'
15
+ ): string | null => {
16
+ const value = process.env[name]?.trim();
17
+
18
+ return value ? value : null;
19
+ };
20
+
21
+ const runInlineHook = async (script: string): Promise<void> => {
22
+ const env = Object.fromEntries(
23
+ Object.entries(process.env).filter(
24
+ (entry): entry is [string, string] => entry[1] != null
25
+ )
26
+ );
27
+
28
+ await spawn('bash', ['-lc', script], {
29
+ env,
30
+ cwd: process.env.HARNESS_PROJECT_ROOT,
31
+ });
32
+ };
33
+
34
+ export const createActionHooksPlugin = (): HarnessPlugin<
35
+ ActionHookState,
36
+ HarnessConfig,
37
+ HarnessPlatform
38
+ > =>
39
+ definePlugin({
40
+ name: 'github-action-hooks',
41
+ createState: () => ({}),
42
+ hooks: {
43
+ harness: {
44
+ beforeRun: async () => {
45
+ const script = getInlineHookScript('PRE_RUN_HOOK');
46
+
47
+ if (!script) {
48
+ return;
49
+ }
50
+
51
+ await runInlineHook(script);
52
+ },
53
+ afterRun: async (ctx) => {
54
+ const script = getInlineHookScript('AFTER_RUN_HOOK');
55
+
56
+ if (!script) {
57
+ return;
58
+ }
59
+
60
+ process.env.HARNESS_EXIT_CODE = ctx.status === 'passed' ? '0' : '1';
61
+
62
+ await runInlineHook(script);
63
+ },
64
+ },
65
+ },
66
+ });
package/src/errors.ts CHANGED
@@ -27,6 +27,15 @@ export class InitializationTimeoutError extends HarnessError {
27
27
  }
28
28
  }
29
29
 
30
+ export class PlatformReadyTimeoutError extends HarnessError {
31
+ constructor(public readonly timeout: number) {
32
+ super(
33
+ `The platform did not become ready within ${timeout}ms. Increase "platformReadyTimeout" if your device, simulator, or emulator needs more time to start.`
34
+ );
35
+ this.name = 'PlatformReadyTimeoutError';
36
+ }
37
+ }
38
+
30
39
  export type NativeCrashPhase = 'startup' | 'execution';
31
40
 
32
41
  export type NativeCrashDetails = AppCrashDetails & {
@@ -51,10 +60,7 @@ const buildNativeCrashMessage = ({
51
60
  const hasCrashBlock = summary?.includes('\n') ?? false;
52
61
  const shouldRenderSummary =
53
62
  Boolean(summary) &&
54
- !(
55
- !hasCrashBlock &&
56
- artifactType === 'ios-crash-report'
57
- );
63
+ !(!hasCrashBlock && artifactType === 'ios-crash-report');
58
64
 
59
65
  if (shouldRenderSummary && summary) {
60
66
  lines.push('');