@react-native-harness/runtime 1.2.0 → 1.3.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 (69) hide show
  1. package/dist/collector/functions.d.ts +3 -3
  2. package/dist/collector/functions.d.ts.map +1 -1
  3. package/dist/collector/types.d.ts +3 -2
  4. package/dist/collector/types.d.ts.map +1 -1
  5. package/dist/collector/validation.d.ts +2 -2
  6. package/dist/collector/validation.d.ts.map +1 -1
  7. package/dist/device/index.d.ts +12 -0
  8. package/dist/device/index.d.ts.map +1 -0
  9. package/dist/device/index.js +62 -0
  10. package/dist/hmr.d.ts +2 -0
  11. package/dist/hmr.d.ts.map +1 -0
  12. package/dist/hmr.js +5 -0
  13. package/dist/logbox.d.ts +4 -0
  14. package/dist/logbox.d.ts.map +1 -0
  15. package/dist/logbox.js +18 -0
  16. package/dist/runner/hooks.d.ts +2 -1
  17. package/dist/runner/hooks.d.ts.map +1 -1
  18. package/dist/runner/hooks.js +27 -17
  19. package/dist/runner/runSuite.d.ts.map +1 -1
  20. package/dist/runner/runSuite.js +56 -6
  21. package/dist/runner/test-context.d.ts +16 -0
  22. package/dist/runner/test-context.d.ts.map +1 -0
  23. package/dist/runner/test-context.js +57 -0
  24. package/dist/runner/types.d.ts +2 -1
  25. package/dist/runner/types.d.ts.map +1 -1
  26. package/dist/test-utils/react-native-url-polyfill.d.ts +9 -0
  27. package/dist/test-utils/react-native-url-polyfill.d.ts.map +1 -0
  28. package/dist/test-utils/react-native-url-polyfill.js +1 -0
  29. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  30. package/out-tsc/vitest/src/__tests__/device.test.d.ts +2 -0
  31. package/out-tsc/vitest/src/__tests__/device.test.d.ts.map +1 -0
  32. package/out-tsc/vitest/src/__tests__/logbox.test.d.ts +2 -0
  33. package/out-tsc/vitest/src/__tests__/logbox.test.d.ts.map +1 -0
  34. package/out-tsc/vitest/src/__tests__/runner-context.test.d.ts +2 -0
  35. package/out-tsc/vitest/src/__tests__/runner-context.test.d.ts.map +1 -0
  36. package/out-tsc/vitest/src/collector/functions.d.ts +3 -3
  37. package/out-tsc/vitest/src/collector/functions.d.ts.map +1 -1
  38. package/out-tsc/vitest/src/collector/types.d.ts +3 -2
  39. package/out-tsc/vitest/src/collector/types.d.ts.map +1 -1
  40. package/out-tsc/vitest/src/collector/validation.d.ts +2 -2
  41. package/out-tsc/vitest/src/collector/validation.d.ts.map +1 -1
  42. package/out-tsc/vitest/src/device/index.d.ts +12 -0
  43. package/out-tsc/vitest/src/device/index.d.ts.map +1 -0
  44. package/out-tsc/vitest/src/hmr.d.ts +2 -0
  45. package/out-tsc/vitest/src/hmr.d.ts.map +1 -0
  46. package/out-tsc/vitest/src/logbox.d.ts +4 -0
  47. package/out-tsc/vitest/src/logbox.d.ts.map +1 -0
  48. package/out-tsc/vitest/src/runner/hooks.d.ts +2 -1
  49. package/out-tsc/vitest/src/runner/hooks.d.ts.map +1 -1
  50. package/out-tsc/vitest/src/runner/runSuite.d.ts.map +1 -1
  51. package/out-tsc/vitest/src/runner/test-context.d.ts +16 -0
  52. package/out-tsc/vitest/src/runner/test-context.d.ts.map +1 -0
  53. package/out-tsc/vitest/src/runner/types.d.ts +2 -1
  54. package/out-tsc/vitest/src/runner/types.d.ts.map +1 -1
  55. package/out-tsc/vitest/src/test-utils/react-native-url-polyfill.d.ts +9 -0
  56. package/out-tsc/vitest/src/test-utils/react-native-url-polyfill.d.ts.map +1 -0
  57. package/out-tsc/vitest/tsconfig.spec.tsbuildinfo +1 -1
  58. package/out-tsc/vitest/vite.config.d.ts.map +1 -1
  59. package/package.json +2 -2
  60. package/src/__tests__/runner-context.test.ts +483 -0
  61. package/src/collector/functions.ts +5 -4
  62. package/src/collector/types.ts +4 -1
  63. package/src/collector/validation.ts +2 -2
  64. package/src/runner/hooks.ts +43 -19
  65. package/src/runner/runSuite.ts +75 -9
  66. package/src/runner/test-context.ts +84 -0
  67. package/src/runner/types.ts +3 -0
  68. package/src/test-utils/react-native-url-polyfill.ts +1 -0
  69. package/vite.config.ts +4 -0
@@ -1,4 +1,4 @@
1
- import type { CollectionResult } from '@react-native-harness/bridge';
1
+ import type { CollectionResult, SuiteHookFn } from '@react-native-harness/bridge';
2
2
  import type { TestFn } from './types.js';
3
3
  export declare const describe: ((name: string, fn: () => void) => void) & {
4
4
  skip: (name: string, fn: () => void) => void;
@@ -14,8 +14,8 @@ export declare const it: ((name: string, fn: TestFn) => void) & {
14
14
  only: (name: string, fn: TestFn) => void;
15
15
  todo: (name: string) => void;
16
16
  };
17
- export declare function beforeAll(fn: TestFn): void;
18
- export declare function afterAll(fn: TestFn): void;
17
+ export declare function beforeAll(fn: SuiteHookFn): void;
18
+ export declare function afterAll(fn: SuiteHookFn): void;
19
19
  export declare function beforeEach(fn: TestFn): void;
20
20
  export declare function afterEach(fn: TestFn): void;
21
21
  export declare const collectTests: (fn: () => void | Promise<void>) => Promise<CollectionResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/collector/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA4LzC,eAAO,MAAM,QAAQ,UACZ,MAAM,MAAM,MAAM,IAAI;iBAsBd,MAAM,MAAM,MAAM,IAAI;iBAqBtB,MAAM,MAAM,MAAM,IAAI;CAsBtC,CAAC;AAEF,eAAO,MAAM,IAAI,UACR,MAAM,MAAM,MAAM;iBAaV,MAAM,MAAM,MAAM;iBAWlB,MAAM,MAAM,MAAM;iBAWlB,MAAM;CAiBtB,CAAC;AAEF,eAAO,MAAM,EAAE,UAtDN,MAAM,MAAM,MAAM;iBAaV,MAAM,MAAM,MAAM;iBAWlB,MAAM,MAAM,MAAM;iBAWlB,MAAM;CAmBD,CAAC;AAEvB,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,QAQnC;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,QAQlC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,QAQpC;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,QAQnC;AAgBD,eAAO,MAAM,YAAY,GACvB,IAAI,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAC7B,OAAO,CAAC,gBAAgB,CAiB1B,CAAC"}
1
+ {"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../src/collector/functions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,gBAAgB,EAChB,WAAW,EACZ,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA4LzC,eAAO,MAAM,QAAQ,UACZ,MAAM,MAAM,MAAM,IAAI;iBAsBd,MAAM,MAAM,MAAM,IAAI;iBAqBtB,MAAM,MAAM,MAAM,IAAI;CAsBtC,CAAC;AAEF,eAAO,MAAM,IAAI,UACR,MAAM,MAAM,MAAM;iBAaV,MAAM,MAAM,MAAM;iBAWlB,MAAM,MAAM,MAAM;iBAWlB,MAAM;CAiBtB,CAAC;AAEF,eAAO,MAAM,EAAE,UAtDN,MAAM,MAAM,MAAM;iBAaV,MAAM,MAAM,MAAM;iBAWlB,MAAM,MAAM,MAAM;iBAWlB,MAAM;CAmBD,CAAC;AAEvB,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,QAQxC;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,WAAW,QAQvC;AAED,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,QAQpC;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,QAQnC;AAgBD,eAAO,MAAM,YAAY,GACvB,IAAI,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAC7B,OAAO,CAAC,gBAAgB,CAiB1B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { EventEmitter } from '../utils/emitter.js';
2
- import { TestCollectorEvents, CollectionResult } from '@react-native-harness/bridge';
3
- export type TestFn = () => void | Promise<void>;
2
+ import { TestCollectorEvents, CollectionResult, type HarnessTestContext } from '@react-native-harness/bridge';
3
+ export type TestFn = (context: HarnessTestContext) => void | Promise<void>;
4
+ export type SuiteHookFn = () => void | Promise<void>;
4
5
  export type TestCollectorEventsEmitter = EventEmitter<TestCollectorEvents>;
5
6
  export type TestCollector = {
6
7
  events: TestCollectorEventsEmitter;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/collector/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,MAAM,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhD,MAAM,MAAM,0BAA0B,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC;AAE3E,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,0BAA0B,CAAC;IACnC,OAAO,EAAE,CACP,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC9B,YAAY,EAAE,MAAM,KACjB,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/collector/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,kBAAkB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3E,MAAM,MAAM,WAAW,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAErD,MAAM,MAAM,0BAA0B,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC;AAE3E,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,0BAA0B,CAAC;IACnC,OAAO,EAAE,CACP,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC9B,YAAY,EAAE,MAAM,KACjB,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { TestFn } from './types.js';
1
+ import { TestFn, SuiteHookFn } from './types.js';
2
2
  export declare const validateTestName: (name: string, functionName: string) => void;
3
- export declare const validateTestFunction: (fn: TestFn, functionName: string) => void;
3
+ export declare const validateTestFunction: (fn: TestFn | SuiteHookFn, functionName: string) => void;
4
4
  //# sourceMappingURL=validation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/collector/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,cAAc,MAAM,KAAG,IAMrE,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,IAAI,MAAM,EACV,cAAc,MAAM,KACnB,IAMF,CAAC"}
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/collector/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,cAAc,MAAM,KAAG,IAMrE,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,IAAI,MAAM,GAAG,WAAW,EACxB,cAAc,MAAM,KACnB,IAMF,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { DeviceStateMutation, PermissionName } from '@react-native-harness/platforms';
2
+ export declare const device: {
3
+ permissions: {
4
+ grant: (permission: PermissionName) => Promise<DeviceStateMutation | null>;
5
+ revoke: (permission: PermissionName) => Promise<DeviceStateMutation | null>;
6
+ reset: (permission: PermissionName) => Promise<DeviceStateMutation | null>;
7
+ grantAll: () => Promise<DeviceStateMutation | null>;
8
+ denyAll: () => Promise<DeviceStateMutation | null>;
9
+ resetAll: () => Promise<DeviceStateMutation | null>;
10
+ };
11
+ };
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/device/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,mBAAmB,EACnB,cAAc,EACf,MAAM,iCAAiC,CAAC;AA2BzC,eAAO,MAAM,MAAM;;4BAEW,cAAc,KAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;6BAOnD,cAAc,KAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;4BAOrD,cAAc,KAAG,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;wBAO1D,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;uBAMpC,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;wBAMlC,OAAO,CAAC,mBAAmB,GAAG,IAAI,CAAC;;CAO1D,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { getHandle } from '../client/store.js';
2
+ const warnIfNeeded = (warning) => {
3
+ if (warning) {
4
+ console.warn(warning);
5
+ }
6
+ };
7
+ const applyPermissionCommand = async (command) => {
8
+ const result = await getHandle().applyDevicePermission(command);
9
+ warnIfNeeded(result.warning);
10
+ if (!result.mutationId) {
11
+ return null;
12
+ }
13
+ return {
14
+ id: result.mutationId,
15
+ revert: async () => {
16
+ await getHandle().revertDevicePermission(result.mutationId);
17
+ },
18
+ };
19
+ };
20
+ export const device = {
21
+ permissions: {
22
+ grant: async (permission) => {
23
+ return await applyPermissionCommand({
24
+ kind: 'permission',
25
+ permission,
26
+ decision: 'grant',
27
+ });
28
+ },
29
+ revoke: async (permission) => {
30
+ return await applyPermissionCommand({
31
+ kind: 'permission',
32
+ permission,
33
+ decision: 'deny',
34
+ });
35
+ },
36
+ reset: async (permission) => {
37
+ return await applyPermissionCommand({
38
+ kind: 'permission',
39
+ permission,
40
+ decision: 'reset',
41
+ });
42
+ },
43
+ grantAll: async () => {
44
+ return await applyPermissionCommand({
45
+ kind: 'permission-all',
46
+ decision: 'grant',
47
+ });
48
+ },
49
+ denyAll: async () => {
50
+ return await applyPermissionCommand({
51
+ kind: 'permission-all',
52
+ decision: 'deny',
53
+ });
54
+ },
55
+ resetAll: async () => {
56
+ return await applyPermissionCommand({
57
+ kind: 'permission-all',
58
+ decision: 'reset',
59
+ });
60
+ },
61
+ },
62
+ };
package/dist/hmr.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare const disableHMR: () => void;
2
+ //# sourceMappingURL=hmr.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,UAAU,QAAO,IAM7B,CAAC"}
package/dist/hmr.js ADDED
@@ -0,0 +1,5 @@
1
+ export const disableHMR = () => {
2
+ const module = require('react-native/Libraries/Utilities/HMRClient');
3
+ const client = 'default' in module ? module.default : module;
4
+ client.disable();
5
+ };
@@ -0,0 +1,4 @@
1
+ export declare const isLogBoxSuppressed: () => boolean;
2
+ /** Hide LogBox UI while keeping console.error → Metro forwarding. */
3
+ export declare const disableLogBoxUI: () => void;
4
+ //# sourceMappingURL=logbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logbox.d.ts","sourceRoot":"","sources":["../src/logbox.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,kBAAkB,QAAO,OAA2B,CAAC;AAElE,qEAAqE;AACrE,eAAO,MAAM,eAAe,QAAO,IAelC,CAAC"}
package/dist/logbox.js ADDED
@@ -0,0 +1,18 @@
1
+ import { LogBox, TurboModuleRegistry, } from 'react-native';
2
+ let logBoxSuppressed = false;
3
+ const noop = () => undefined;
4
+ export const isLogBoxSuppressed = () => logBoxSuppressed;
5
+ /** Hide LogBox UI while keeping console.error → Metro forwarding. */
6
+ export const disableLogBoxUI = () => {
7
+ const harnessLogBox = LogBox;
8
+ harnessLogBox.ignoreAllLogs(true);
9
+ harnessLogBox.addException = noop;
10
+ harnessLogBox.addLog = noop;
11
+ harnessLogBox.addConsoleLog = noop;
12
+ const nativeLogBox = TurboModuleRegistry?.get('LogBox');
13
+ if (nativeLogBox != null) {
14
+ nativeLogBox.show = noop;
15
+ nativeLogBox.hide = noop;
16
+ }
17
+ logBoxSuppressed = true;
18
+ };
@@ -1,4 +1,5 @@
1
1
  import type { TestSuite } from '@react-native-harness/bridge';
2
+ import type { ActiveTestContext } from './types.js';
2
3
  export type HookType = 'beforeEach' | 'afterEach' | 'beforeAll' | 'afterAll';
3
- export declare const runHooks: (suite: TestSuite, hookType: HookType) => Promise<void>;
4
+ export declare const runHooks: (suite: TestSuite, hookType: HookType, context?: ActiveTestContext) => Promise<void>;
4
5
  //# sourceMappingURL=hooks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/runner/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC;AAuC7E,eAAO,MAAM,QAAQ,GACnB,OAAO,SAAS,EAChB,UAAU,QAAQ,KACjB,OAAO,CAAC,IAAI,CAMd,CAAC"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/runner/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAuB,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,UAAU,CAAC;AAmD7E,eAAO,MAAM,QAAQ,GACnB,OAAO,SAAS,EAChB,UAAU,QAAQ,EAClB,UAAU,iBAAiB,KAC1B,OAAO,CAAC,IAAI,CAgBd,CAAC"}
@@ -1,4 +1,17 @@
1
1
  const collectInheritedHooks = (suite, hookType) => {
2
+ const hooks = [];
3
+ const suiteChain = [];
4
+ let current = suite;
5
+ while (current) {
6
+ suiteChain.unshift(current);
7
+ current = current.parent;
8
+ }
9
+ for (const currentSuite of suiteChain) {
10
+ hooks.push(...currentSuite[hookType]);
11
+ }
12
+ return hooks;
13
+ };
14
+ const collectSuiteHooks = (suite, hookType) => {
2
15
  const hooks = [];
3
16
  const suiteChain = [];
4
17
  // Collect all suites from current to root
@@ -7,33 +20,30 @@ const collectInheritedHooks = (suite, hookType) => {
7
20
  suiteChain.push(currentSuite);
8
21
  currentSuite = currentSuite.parent;
9
22
  }
10
- if (hookType === 'beforeEach' || hookType === 'beforeAll') {
11
- // For beforeEach/beforeAll: run parent hooks first (reverse the chain)
23
+ if (hookType === 'beforeAll') {
24
+ // Run parent suite hooks before child suite hooks.
12
25
  for (let i = suiteChain.length - 1; i >= 0; i--) {
13
- if (hookType === 'beforeEach') {
14
- hooks.push(...suiteChain[i].beforeEach);
15
- }
16
- else {
17
- hooks.push(...suiteChain[i].beforeAll);
18
- }
26
+ hooks.push(...suiteChain[i].beforeAll);
19
27
  }
20
28
  }
21
29
  else {
22
- // For afterEach/afterAll: run child hooks first (use chain as-is)
30
+ // Run child suite hooks before parent suite hooks.
23
31
  for (const suiteInChain of suiteChain) {
24
- if (hookType === 'afterEach') {
25
- hooks.push(...suiteInChain.afterEach);
26
- }
27
- else {
28
- hooks.push(...suiteInChain.afterAll);
29
- }
32
+ hooks.push(...suiteInChain.afterAll);
30
33
  }
31
34
  }
32
35
  return hooks;
33
36
  };
34
- export const runHooks = async (suite, hookType) => {
37
+ export const runHooks = async (suite, hookType, context) => {
38
+ if (hookType === 'beforeAll' || hookType === 'afterAll') {
39
+ const hooks = collectSuiteHooks(suite, hookType);
40
+ for (const hook of hooks) {
41
+ await hook();
42
+ }
43
+ return;
44
+ }
35
45
  const hooks = collectInheritedHooks(suite, hookType);
36
46
  for (const hook of hooks) {
37
- await hook();
47
+ await hook(context);
38
48
  }
39
49
  };
@@ -1 +1 @@
1
- {"version":3,"file":"runSuite.d.ts","sourceRoot":"","sources":["../../src/runner/runSuite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,SAAS,EACT,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAQtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,iBAAiB,EAAE,MAAM,CAAC;CAC/B;AA+HD,eAAO,MAAM,QAAQ,GACnB,OAAO,SAAS,EAChB,SAAS,iBAAiB,KACzB,OAAO,CAAC,eAAe,CAoIzB,CAAC"}
1
+ {"version":3,"file":"runSuite.d.ts","sourceRoot":"","sources":["../../src/runner/runSuite.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,SAAS,EACT,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAQtC,OAAO,EAAqB,iBAAiB,EAAE,MAAM,YAAY,CAAC;AASlE,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,iBAAiB,EAAE,MAAM,CAAC;CAC/B;AAyLD,eAAO,MAAM,QAAQ,GACnB,OAAO,SAAS,EAChB,SAAS,iBAAiB,KACzB,OAAO,CAAC,eAAe,CAoIzB,CAAC"}
@@ -2,8 +2,26 @@ import { setCurrentExpectTestState, } from '../expect/context.js';
2
2
  import { flushExpectTestState } from '../expect/errors.js';
3
3
  import { runHooks } from './hooks.js';
4
4
  import { getTestExecutionError } from './errors.js';
5
+ import { createTestContext, createTestLifecycleState, isSkipTestError, runOnTestFailed, runOnTestFinished, } from './test-context.js';
5
6
  const runTest = async (test, suite, context) => {
6
7
  const startTime = Date.now();
8
+ const task = {
9
+ name: test.name,
10
+ type: 'test',
11
+ mode: test.status === 'active'
12
+ ? 'run'
13
+ : test.status === 'skipped'
14
+ ? 'skip'
15
+ : 'todo',
16
+ file: {
17
+ name: context.testFilePath,
18
+ },
19
+ suite: {
20
+ name: suite.name,
21
+ },
22
+ };
23
+ const lifecycleState = createTestLifecycleState();
24
+ const activeTestContext = createTestContext(task, lifecycleState);
7
25
  // Emit test-started event
8
26
  context.events.emit({
9
27
  type: 'test-started',
@@ -50,13 +68,43 @@ const runTest = async (test, suite, context) => {
50
68
  const expectTestState = {};
51
69
  setCurrentExpectTestState(expectTestState);
52
70
  try {
53
- // Run all beforeEach hooks from the current suite and its parents
54
- await runHooks(suite, 'beforeEach');
55
- // Run the actual test
56
- await test.fn();
57
- // Run all afterEach hooks from the current suite and its parents
58
- await runHooks(suite, 'afterEach');
71
+ let didSkip = false;
72
+ try {
73
+ // Run all beforeEach hooks from the current suite and its parents
74
+ await runHooks(suite, 'beforeEach', activeTestContext);
75
+ // Run the actual test
76
+ await test.fn(activeTestContext);
77
+ }
78
+ catch (error) {
79
+ if (!isSkipTestError(error)) {
80
+ throw error;
81
+ }
82
+ didSkip = true;
83
+ }
84
+ finally {
85
+ // Run all afterEach hooks from the current suite and its parents
86
+ await runHooks(suite, 'afterEach', activeTestContext);
87
+ }
88
+ if (didSkip) {
89
+ const duration = Date.now() - startTime;
90
+ await runOnTestFinished(lifecycleState);
91
+ const result = {
92
+ name: test.name,
93
+ status: 'skipped',
94
+ duration,
95
+ };
96
+ context.events.emit({
97
+ type: 'test-finished',
98
+ file: context.testFilePath,
99
+ suite: suite.name,
100
+ name: test.name,
101
+ duration,
102
+ status: 'skipped',
103
+ });
104
+ return result;
105
+ }
59
106
  await flushExpectTestState(expectTestState);
107
+ await runOnTestFinished(lifecycleState);
60
108
  }
61
109
  finally {
62
110
  setCurrentExpectTestState(undefined);
@@ -79,6 +127,8 @@ const runTest = async (test, suite, context) => {
79
127
  return result;
80
128
  }
81
129
  catch (error) {
130
+ await runOnTestFailed(lifecycleState);
131
+ await runOnTestFinished(lifecycleState);
82
132
  const testError = await getTestExecutionError(error, context.testFilePath, suite.name, test.name);
83
133
  const duration = Date.now() - startTime;
84
134
  const result = {
@@ -0,0 +1,16 @@
1
+ import type { HarnessTaskContext } from '@react-native-harness/bridge';
2
+ import type { ActiveTestContext } from './types.js';
3
+ export type TestLifecycleState = {
4
+ onTestFailed: Array<() => void | Promise<void>>;
5
+ onTestFinished: Array<() => void | Promise<void>>;
6
+ };
7
+ export declare class SkipTestError extends Error {
8
+ note?: string;
9
+ constructor(note?: string);
10
+ }
11
+ export declare const isSkipTestError: (error: unknown) => error is SkipTestError;
12
+ export declare const createTestLifecycleState: () => TestLifecycleState;
13
+ export declare const runOnTestFailed: (state: TestLifecycleState) => Promise<void>;
14
+ export declare const runOnTestFinished: (state: TestLifecycleState) => Promise<void>;
15
+ export declare const createTestContext: (task: HarnessTaskContext, state: TestLifecycleState) => ActiveTestContext;
16
+ //# sourceMappingURL=test-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-context.d.ts","sourceRoot":"","sources":["../../src/runner/test-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,KAAK,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAChD,cAAc,EAAE,KAAK,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CACnD,CAAC;AAEF,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;gBAEF,IAAI,CAAC,EAAE,MAAM;CAK1B;AAED,eAAO,MAAM,eAAe,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,aAEzD,CAAC;AA8BF,eAAO,MAAM,wBAAwB,QAAO,kBAK3C,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,OAAO,kBAAkB,KACxB,OAAO,CAAC,IAAI,CAId,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,OAAO,kBAAkB,KACxB,OAAO,CAAC,IAAI,CAId,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,MAAM,kBAAkB,EACxB,OAAO,kBAAkB,KACxB,iBAOF,CAAC"}
@@ -0,0 +1,57 @@
1
+ export class SkipTestError extends Error {
2
+ note;
3
+ constructor(note) {
4
+ super(note ?? 'Test skipped');
5
+ this.name = 'SkipTestError';
6
+ this.note = note;
7
+ }
8
+ }
9
+ export const isSkipTestError = (error) => {
10
+ return error instanceof SkipTestError;
11
+ };
12
+ const createSkip = () => {
13
+ function skip(noteOrCondition, note) {
14
+ if (typeof noteOrCondition === 'boolean') {
15
+ if (!noteOrCondition) {
16
+ return;
17
+ }
18
+ throw new SkipTestError(note);
19
+ }
20
+ throw new SkipTestError(noteOrCondition);
21
+ }
22
+ return skip;
23
+ };
24
+ const createOnTestFinished = (state) => {
25
+ return (fn) => {
26
+ state.onTestFinished.push(fn);
27
+ };
28
+ };
29
+ const createOnTestFailed = (state) => {
30
+ return (fn) => {
31
+ state.onTestFailed.push(fn);
32
+ };
33
+ };
34
+ export const createTestLifecycleState = () => {
35
+ return {
36
+ onTestFailed: [],
37
+ onTestFinished: [],
38
+ };
39
+ };
40
+ export const runOnTestFailed = async (state) => {
41
+ for (let i = state.onTestFailed.length - 1; i >= 0; i--) {
42
+ await state.onTestFailed[i]();
43
+ }
44
+ };
45
+ export const runOnTestFinished = async (state) => {
46
+ for (let i = state.onTestFinished.length - 1; i >= 0; i--) {
47
+ await state.onTestFinished[i]();
48
+ }
49
+ };
50
+ export const createTestContext = (task, state) => {
51
+ return {
52
+ task,
53
+ onTestFailed: createOnTestFailed(state),
54
+ onTestFinished: createOnTestFinished(state),
55
+ skip: createSkip(),
56
+ };
57
+ };
@@ -1,10 +1,11 @@
1
1
  import { EventEmitter } from '../utils/emitter.js';
2
- import type { TestRunnerEvents, TestSuite, TestSuiteResult } from '@react-native-harness/bridge';
2
+ import type { HarnessTestContext, TestRunnerEvents, TestSuite, TestSuiteResult } from '@react-native-harness/bridge';
3
3
  export type TestRunnerEventsEmitter = EventEmitter<TestRunnerEvents>;
4
4
  export type TestRunnerContext = {
5
5
  events: TestRunnerEventsEmitter;
6
6
  testFilePath: string;
7
7
  };
8
+ export type ActiveTestContext = HarnessTestContext;
8
9
  export type RunTestsOptions = {
9
10
  testSuite: TestSuite;
10
11
  testFilePath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runner/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,gBAAgB,EAChB,SAAS,EACT,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,uBAAuB,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAErE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,uBAAuB,CAAC;IAChC,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,uBAAuB,CAAC;IAChC,GAAG,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runner/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,EACT,eAAe,EAChB,MAAM,8BAA8B,CAAC;AAEtC,MAAM,MAAM,uBAAuB,GAAG,YAAY,CAAC,gBAAgB,CAAC,CAAC;AAErE,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,uBAAuB,CAAC;IAChC,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAEnD,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,MAAM,EAAE,uBAAuB,CAAC;IAChC,GAAG,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,eAAe,CAAC,CAAC;IAC5D,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC"}
@@ -0,0 +1,9 @@
1
+ export declare const URL: {
2
+ new (url: string | URL, base?: string | URL): URL;
3
+ prototype: URL;
4
+ canParse(url: string | URL, base?: string | URL): boolean;
5
+ createObjectURL(obj: Blob | MediaSource): string;
6
+ parse(url: string | URL, base?: string | URL): URL | null;
7
+ revokeObjectURL(url: string): void;
8
+ };
9
+ //# sourceMappingURL=react-native-url-polyfill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-native-url-polyfill.d.ts","sourceRoot":"","sources":["../../src/test-utils/react-native-url-polyfill.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,GAAG;;;;;;;CAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ export const URL = globalThis.URL;